diff options
author | alekhgupta1441 <alekhgupta1441@gmail.com> | 2020-03-14 07:04:54 +0530 |
---|---|---|
committer | Michael Dickens <michael.dickens@ettus.com> | 2020-04-19 15:33:41 -0400 |
commit | cb4f4648815c005788a1879bdb10c58228736808 (patch) | |
tree | 1b2a7b3acfc4dab769897934da3f86d72a3af079 /gr-utils/modtool/core/disable.py | |
parent | b28220713221c811fc31662472976e0d8a3dc959 (diff) |
modtool: Replaced str.format() by Python f'strings in all codes
Diffstat (limited to 'gr-utils/modtool/core/disable.py')
-rw-r--r-- | gr-utils/modtool/core/disable.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/gr-utils/modtool/core/disable.py b/gr-utils/modtool/core/disable.py index 1fb4628312..0f925dde0e 100644 --- a/gr-utils/modtool/core/disable.py +++ b/gr-utils/modtool/core/disable.py @@ -65,12 +65,13 @@ class ModToolDisable(ModTool): cmake.comment_out_lines(r'\$\{CMAKE_CURRENT_SOURCE_DIR\}/'+fname) fname_base = os.path.splitext(fname)[0] ed = CMakeFileEditor(self._file['qalib']) # Abusing the CMakeFileEditor... - ed.comment_out_lines(r'#include\s+"{}.h"'.format(fname_base), comment_str='//') - ed.comment_out_lines(r'{}::suite\(\)'.format(fname_base), comment_str='//') + ed.comment_out_lines(fr'#include\s+"{fname_base}.h"', comment_str='//') + ed.comment_out_lines(fr'{fname_base}::suite\(\)', comment_str='//') ed.write() self.scm.mark_file_updated(self._file['qalib']) elif self.info['version'] == '38': - fname_qa_cc = 'qa_{}.cc'.format(self.info['blockname']) + blockname_=self._info['blockname'] + fname_qa_cc = f'qa_{blockname_}.cc' cmake.comment_out_lines(fname_qa_cc) elif self.info['version'] == '36': cmake.comment_out_lines('add_executable.*'+fname) @@ -83,18 +84,18 @@ class ModToolDisable(ModTool): as well as the block magic """ with open(self._file['swig']) as f: swigfile = f.read() - (swigfile, nsubs) = re.subn(r'(.include\s+"({}/)?{}")'.format( - self.info['modname'], fname), + modn_=self.info['modname'] + (swigfile, nsubs) = re.subn(f'(.include\s+"({modn_}/)?{fname}")', r'//\1', swigfile) if nsubs > 0: - logger.info("Changing {}...".format(self._file['swig'])) + logger.info(f"Changing {self._file['swig']}...") if nsubs > 1: # Need to find a single BLOCK_MAGIC blockname = os.path.splitext(fname[len(self.info['modname'])+1:])[0] if self.info['version'] in ('37', '38'): blockname = os.path.splitext(fname)[0] - (swigfile, nsubs) = re.subn('(GR_SWIG_BLOCK_MAGIC2?.+{}.+;)'.format(blockname), r'//\1', swigfile) + (swigfile, nsubs) = re.subn(f'(GR_SWIG_BLOCK_MAGIC2?.+{blockname}.+;)', r'//\1', swigfile) if nsubs > 1: - logger.warning("Hm, changed more then expected while editing {}.".format(self._file['swig'])) + logger.warning(f"Hm, changed more then expected while editing {self._file['swig']}.") with open(self._file['swig'], 'w') as f: f.write(swigfile) self.scm.mark_file_updated(self._file['swig']) @@ -108,7 +109,7 @@ class ModToolDisable(ModTool): if self.info['version'] in ('37', '38'): blockname = os.path.splitext(fname)[0] swigfile = re.sub(r'(%include\s+"'+fname+'")', r'//\1', swigfile) - logger.info("Changing {}...".format(self._file['swig'])) + logger.info(f"Changing {self._file['swig']}...") swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC2?.+'+blockname+'.+;)', r'//\1', swigfile) with open(self._file['swig'], 'w') as f: f.write(swigfile) @@ -121,11 +122,12 @@ class ModToolDisable(ModTool): else: from ..cli import cli_input # List of special rules: 0: subdir, 1: filename re match, 2: callback + modname_=self.info['modname'] special_treatments = ( ('python', r'qa.+py$', _handle_py_qa), ('python', r'^(?!qa).+py$', _handle_py_mod), ('lib', r'qa.+\.cc$', _handle_cc_qa), - ('include/{}'.format(self.info['modname']), r'.+\.h$', _handle_h_swig), + (f'include/{modname_}', r'.+\.h$', _handle_h_swig), ('include', r'.+\.h$', _handle_h_swig), ('swig', r'.+\.i$', _handle_i_swig) ) @@ -133,18 +135,18 @@ class ModToolDisable(ModTool): if self.skip_subdirs[subdir]: continue if self.info['version'] in ('37', '38') and subdir == 'include': - subdir = 'include/{}'.format(self.info['modname']) + subdir = f'include/{modname_}' try: cmake = CMakeFileEditor(os.path.join(subdir, 'CMakeLists.txt')) except IOError: continue - logger.info("Traversing {}...".format(subdir)) + logger.info(f"Traversing {subdir}...") filenames = cmake.find_filenames_match(self.info['pattern']) yes = self.info['yes'] for fname in filenames: file_disabled = False if not yes: - ans = cli_input("Really disable {}? [Y/n/a/q]: ".format(fname)).lower().strip() + ans = cli_input(f"Really disable {fname}? [Y/n/a/q]: ").lower().strip() if ans == 'a': yes = True if ans == 'q': |