diff options
-rw-r--r-- | gr-utils/python/modtool/modtool_add.py | 75 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_base.py | 42 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_disable.py | 31 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_help.py | 1 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_info.py | 21 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_makexml.py | 15 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_newmod.py | 4 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_rename.py | 14 | ||||
-rw-r--r-- | gr-utils/python/modtool/modtool_rm.py | 14 |
9 files changed, 105 insertions, 112 deletions
diff --git a/gr-utils/python/modtool/modtool_add.py b/gr-utils/python/modtool/modtool_add.py index c21ae3dc2a..c7486c0a7c 100644 --- a/gr-utils/python/modtool/modtool_add.py +++ b/gr-utils/python/modtool/modtool_add.py @@ -23,15 +23,15 @@ import os import re from optparse import OptionGroup -import readline import getpass +import readline +import Cheetah.Template from util_functions import append_re_line_sequence, ask_yes_no, SequenceCompleter from cmakefile_editor import CMakeFileEditor from modtool_base import ModTool, ModToolException from templates import Templates from code_generator import get_template -import Cheetah.Template class ModToolAdd(ModTool): @@ -52,21 +52,22 @@ class ModToolAdd(ModTool): parser = ModTool.setup_parser(self) ogroup = OptionGroup(parser, "Add module options") ogroup.add_option("-t", "--block-type", type="choice", - choices=self._block_types, default=None, help="One of %s." % ', '.join(self._block_types)) + choices=self._block_types, default=None, + help="One of %s." % ', '.join(self._block_types)) ogroup.add_option("--license-file", type="string", default=None, - help="File containing the license header for every source code file.") + help="File containing the license header for every source code file.") ogroup.add_option("--copyright", type="string", default=None, - help="Name of the copyright holder (you or your company) MUST be a quoted string.") + help="Name of the copyright holder (you or your company) MUST be a quoted string.") ogroup.add_option("--argument-list", type="string", default=None, - help="The argument list for the constructor and make functions.") + help="The argument list for the constructor and make functions.") ogroup.add_option("--add-python-qa", action="store_true", default=None, - help="If given, Python QA code is automatically added if possible.") + help="If given, Python QA code is automatically added if possible.") ogroup.add_option("--add-cpp-qa", action="store_true", default=None, - help="If given, C++ QA code is automatically added if possible.") + help="If given, C++ QA code is automatically added if possible.") ogroup.add_option("--skip-cmakefiles", action="store_true", default=False, - help="If given, only source files are written, but CMakeLists.txt files are left unchanged.") + help="If given, only source files are written, but CMakeLists.txt files are left unchanged.") ogroup.add_option("-l", "--lang", type="choice", choices=('cpp', 'c++', 'python'), - default=None, help="Language (cpp or python)") + default=None, help="Language (cpp or python)") parser.add_option_group(ogroup) return parser @@ -108,9 +109,9 @@ class ModToolAdd(ModTool): print "Language: %s" % {'cpp': 'C++', 'python': 'Python'}[self._info['lang']] if ((self._skip_subdirs['lib'] and self._info['lang'] == 'cpp') - or (self._skip_subdirs['python'] and self._info['lang'] == 'python')): + or (self._skip_subdirs['python'] and self._info['lang'] == 'python')): raise ModToolException('Missing or skipping relevant subdir.') - + if not options.license_file: self._info['copyrightholder'] = options.copyright if self._info['copyrightholder'] is None: @@ -162,8 +163,7 @@ class ModToolAdd(ModTool): return open('LICENCE').read() elif self._info['is_component']: return Templates['grlicense'] - else: - return get_template('defaultlicense', **self._info) + return get_template('defaultlicense', **self._info) def _write_tpl(self, tpl, path, fname): """ Shorthand for writing a substituted template to a file""" @@ -175,8 +175,8 @@ class ModToolAdd(ModTool): def run(self): """ Go, go, go. """ has_swig = ( - self._info['lang'] == 'cpp' - and not self._skip_subdirs['swig'] + self._info['lang'] == 'cpp' + and not self._skip_subdirs['swig'] ) has_grc = False if self._info['lang'] == 'cpp': @@ -202,14 +202,14 @@ class ModToolAdd(ModTool): """ def _add_qa(): " Add C++ QA files for 3.7 API " - fname_qa_h = 'qa_%s.h' % self._info['blockname'] + fname_qa_h = 'qa_%s.h' % self._info['blockname'] fname_qa_cc = 'qa_%s.cc' % self._info['blockname'] self._write_tpl('qa_cpp', 'lib', fname_qa_cc) - self._write_tpl('qa_h', 'lib', fname_qa_h) + self._write_tpl('qa_h', 'lib', fname_qa_h) if not self._skip_cmakefiles: try: append_re_line_sequence(self._file['cmlib'], - '\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'], + r'\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'], ' ${CMAKE_CURRENT_SOURCE_DIR}/qa_%s.cc' % self._info['blockname']) append_re_line_sequence(self._file['qalib'], '#include.*\n', @@ -218,7 +218,7 @@ class ModToolAdd(ModTool): '(addTest.*suite.*\n|new CppUnit.*TestSuite.*\n)', ' s->addTest(gr::%s::qa_%s::suite());' % (self._info['modname'], self._info['blockname']) - ) + ) self.scm.mark_files_updated((self._file['qalib'],)) except IOError: print "Can't add C++ QA files." @@ -236,28 +236,28 @@ class ModToolAdd(ModTool): 'filename': fname_qa_cc, 'modname': self._info['modname'] } + ) ) - ) ) ed = CMakeFileEditor(self._file['cmlib']) ed.remove_double_newlines() ed.write() fname_cc = None - fname_h = None - if self._info['version'] == '37': - fname_h = self._info['blockname'] + '.h' + fname_h = None + if self._info['version'] == '37': + fname_h = self._info['blockname'] + '.h' fname_cc = self._info['blockname'] + '.cc' if self._info['blocktype'] in ('source', 'sink', 'sync', 'decimator', 'interpolator', 'general', 'hier', 'tagged_stream'): fname_cc = self._info['blockname'] + '_impl.cc' - self._write_tpl('block_impl_h', 'lib', self._info['blockname'] + '_impl.h') + self._write_tpl('block_impl_h', 'lib', self._info['blockname'] + '_impl.h') self._write_tpl('block_impl_cpp', 'lib', fname_cc) - self._write_tpl('block_def_h', self._info['includedir'], fname_h) + self._write_tpl('block_def_h', self._info['includedir'], fname_h) else: # Pre-3.7 or autotools - fname_h = self._info['fullblockname'] + '.h' + fname_h = self._info['fullblockname'] + '.h' fname_cc = self._info['fullblockname'] + '.cc' - self._write_tpl('block_h36', self._info['includedir'], fname_h) - self._write_tpl('block_cpp36', 'lib', fname_cc) + self._write_tpl('block_h36', self._info['includedir'], fname_h) + self._write_tpl('block_cpp36', 'lib', fname_cc) if self._add_cc_qa: if self._info['version'] == '37': _add_qa() @@ -290,14 +290,15 @@ class ModToolAdd(ModTool): swig_block_magic_str = get_template('swig_block_magic', **self._info) open(self._file['swig'], 'a').write(swig_block_magic_str) include_str = '#include "%s%s%s.h"' % ( - {True: 'gnuradio/' + self._info['modname'], False: self._info['modname']}[self._info['is_component']], - mod_block_sep, - self._info['blockname']) + {True: 'gnuradio/' + self._info['modname'], + False: self._info['modname']}[self._info['is_component']], + mod_block_sep, + self._info['blockname']) if re.search('#include', open(self._file['swig'], 'r').read()): append_re_line_sequence(self._file['swig'], '^#include.*\n', include_str) else: # I.e., if the swig file is empty oldfile = open(self._file['swig'], 'r').read() - regexp = re.compile('^%\{\n', re.MULTILINE) + regexp = re.compile(r'^%\{\n', re.MULTILINE) oldfile = regexp.sub('%%{\n%s\n' % include_str, oldfile, count=1) open(self._file['swig'], 'w').write(oldfile) self.scm.mark_files_updated((self._file['swig'],)) @@ -316,8 +317,8 @@ class ModToolAdd(ModTool): return print "Editing %s/CMakeLists.txt..." % self._info['pydir'] open(self._file['cmpython'], 'a').write( - 'GR_ADD_TEST(qa_%s ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/%s)\n' % \ - (self._info['blockname'], fname_py_qa)) + 'GR_ADD_TEST(qa_%s ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/%s)\n' % \ + (self._info['blockname'], fname_py_qa)) self.scm.mark_files_updated((self._file['cmpython'],)) def _run_python(self): @@ -331,7 +332,8 @@ class ModToolAdd(ModTool): self._write_tpl('block_python', self._info['pydir'], fname_py) append_re_line_sequence(self._file['pyinit'], '(^from.*import.*\n|# import any pure.*\n)', - 'from %s import %s' % (self._info['blockname'], self._info['blockname'])) + 'from %s import %s' % (self._info['blockname'], + self._info['blockname'])) self.scm.mark_files_updated((self._file['pyinit'],)) if self._skip_cmakefiles: return @@ -355,4 +357,3 @@ class ModToolAdd(ModTool): ed.append_value('install', fname_grc, to_ignore_end='DESTINATION[^()]+') ed.write() self.scm.mark_files_updated((self._file['cmgrc'],)) - diff --git a/gr-utils/python/modtool/modtool_base.py b/gr-utils/python/modtool/modtool_base.py index a58b7abcb1..0bbd95946d 100644 --- a/gr-utils/python/modtool/modtool_base.py +++ b/gr-utils/python/modtool/modtool_base.py @@ -46,6 +46,7 @@ class ModTool(object): self._skip_subdirs[subdir] = False self.parser = self.setup_parser() self._dir = None + self.scm = None def setup_parser(self): """ Init the option parser. If derived classes need to add options, @@ -56,24 +57,24 @@ class ModTool(object): ogroup = OptionGroup(parser, "General options") ogroup.add_option("-h", "--help", action="help", help="Displays this help message.") ogroup.add_option("-d", "--directory", type="string", default=".", - help="Base directory of the module. Defaults to the cwd.") + help="Base directory of the module. Defaults to the cwd.") ogroup.add_option("-n", "--module-name", type="string", default=None, - help="Use this to override the current module's name (is normally autodetected).") + help="Use this to override the current module's name (is normally autodetected).") ogroup.add_option("-N", "--block-name", type="string", default=None, - help="Name of the block, where applicable.") + help="Name of the block, where applicable.") ogroup.add_option("--skip-lib", action="store_true", default=False, - help="Don't do anything in the lib/ subdirectory.") + help="Don't do anything in the lib/ subdirectory.") ogroup.add_option("--skip-swig", action="store_true", default=False, - help="Don't do anything in the swig/ subdirectory.") + help="Don't do anything in the swig/ subdirectory.") ogroup.add_option("--skip-python", action="store_true", default=False, - help="Don't do anything in the python/ subdirectory.") + help="Don't do anything in the python/ subdirectory.") ogroup.add_option("--skip-grc", action="store_true", default=False, - help="Don't do anything in the grc/ subdirectory.") + help="Don't do anything in the grc/ subdirectory.") ogroup.add_option("--scm-mode", type="choice", choices=('yes', 'no', 'auto'), - default=gr.prefs().get_string('modtool', 'scm_mode', 'no'), - help="Use source control management (yes, no or auto).") + default=gr.prefs().get_string('modtool', 'scm_mode', 'no'), + help="Use source control management (yes, no or auto).") ogroup.add_option("-y", "--yes", action="store_true", default=False, - help="Answer all questions with 'yes'. This can overwrite and delete your files, so be careful.") + help="Answer all questions with 'yes'. This can overwrite and delete your files, so be careful.") parser.add_option_group(ogroup) return parser @@ -92,7 +93,7 @@ class ModTool(object): if self._info['version'] == '36' and ( os.path.isdir(os.path.join('include', self._info['modname'])) or os.path.isdir(os.path.join('include', 'gnuradio', self._info['modname'])) - ): + ): self._info['version'] = '37' if options.skip_lib or not self._has_subdirs['lib']: self._skip_subdirs['lib'] = True @@ -111,14 +112,14 @@ class ModTool(object): def _setup_files(self): """ Initialise the self._file[] dictionary """ if not self._skip_subdirs['swig']: - self._file['swig'] = os.path.join('swig', self._get_mainswigfile()) + self._file['swig'] = os.path.join('swig', self._get_mainswigfile()) self._info['pydir'] = 'python' if os.path.isdir(os.path.join('python', self._info['modname'])): self._info['pydir'] = os.path.join('python', self._info['modname']) - self._file['qalib'] = os.path.join('lib', 'qa_%s.cc' % self._info['modname']) - self._file['pyinit'] = os.path.join(self._info['pydir'], '__init__.py') - self._file['cmlib'] = os.path.join('lib', 'CMakeLists.txt') - self._file['cmgrc'] = os.path.join('grc', 'CMakeLists.txt') + self._file['qalib'] = os.path.join('lib', 'qa_%s.cc' % self._info['modname']) + self._file['pyinit'] = os.path.join(self._info['pydir'], '__init__.py') + self._file['cmlib'] = os.path.join('lib', 'CMakeLists.txt') + self._file['cmgrc'] = os.path.join('grc', 'CMakeLists.txt') self._file['cmpython'] = os.path.join(self._info['pydir'], 'CMakeLists.txt') if self._info['is_component']: self._info['includedir'] = os.path.join('include', 'gnuradio', self._info['modname']) @@ -155,7 +156,7 @@ class ModTool(object): self._info['is_component'] = False for f in files: if os.path.isfile(f) and f == 'CMakeLists.txt': - if re.search('find_package\(Gnuradio', open(f).read()) is not None: + if re.search(r'find_package\(Gnuradio', open(f).read()) is not None: self._info['version'] = '36' # Might be 37, check that later has_makefile = True elif re.search('GR_REGISTER_COMPONENT', open(f).read()) is not None: @@ -164,7 +165,7 @@ class ModTool(object): has_makefile = True # TODO search for autofoo elif os.path.isdir(f): - if (f in self._has_subdirs.keys()): + if f in self._has_subdirs.keys(): self._has_subdirs[f] = True else: self._skip_subdirs[f] = True @@ -193,9 +194,8 @@ def get_class_dict(the_globals): try: if issubclass(g, ModTool): classdict[g.name] = g - for a in g.aliases: - classdict[a] = g + for alias in g.aliases: + classdict[alias] = g except (TypeError, AttributeError): pass return classdict - diff --git a/gr-utils/python/modtool/modtool_disable.py b/gr-utils/python/modtool/modtool_disable.py index 4ae2242f99..a23e16eccb 100644 --- a/gr-utils/python/modtool/modtool_disable.py +++ b/gr-utils/python/modtool/modtool_disable.py @@ -45,7 +45,7 @@ class ModToolDisable(ModTool): self._info['pattern'] = args[1] else: self._info['pattern'] = raw_input('Which blocks do you want to disable? (Regex): ') - if len(self._info['pattern']) == 0: + if not self._info['pattern'] or self._info['pattern'].isspace(): self._info['pattern'] = '.' def run(self): @@ -70,11 +70,11 @@ class ModToolDisable(ModTool): def _handle_cc_qa(cmake, fname): """ Do stuff for cc qa """ if self._info['version'] == '37': - cmake.comment_out_lines('\$\{CMAKE_CURRENT_SOURCE_DIR\}/'+fname) + 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('#include\s+"%s.h"' % fname_base, comment_str='//') - ed.comment_out_lines('%s::suite\(\)' % fname_base, comment_str='//') + ed.comment_out_lines(r'#include\s+"%s.h"' % fname_base, comment_str='//') + ed.comment_out_lines(r'%s::suite\(\)' % fname_base, comment_str='//') ed.write() self.scm.mark_file_updated(self._file['qalib']) elif self._info['version'] == '36': @@ -87,9 +87,8 @@ class ModToolDisable(ModTool): """ Comment out include files from the SWIG file, as well as the block magic """ swigfile = open(self._file['swig']).read() - (swigfile, nsubs) = re.subn('(.include\s+"(%s/)?%s")' % ( - self._info['modname'], fname), - r'//\1', swigfile) + (swigfile, nsubs) = re.subn(r'(.include\s+"(%s/)?%s")' % ( + self._info['modname'], fname), r'//\1', swigfile) if nsubs > 0: print "Changing %s..." % self._file['swig'] if nsubs > 1: # Need to find a single BLOCK_MAGIC @@ -109,7 +108,7 @@ class ModToolDisable(ModTool): blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0] if self._info['version'] == '37': blockname = os.path.splitext(fname)[0] - swigfile = re.sub('(%include\s+"'+fname+'")', r'//\1', swigfile) + swigfile = re.sub(r'(%include\s+"'+fname+'")', r'//\1', swigfile) print "Changing %s..." % self._file['swig'] swigfile = re.sub('(GR_SWIG_BLOCK_MAGIC2?.+'+blockname+'.+;)', r'//\1', swigfile) open(self._file['swig'], 'w').write(swigfile) @@ -117,15 +116,16 @@ class ModToolDisable(ModTool): return False # List of special rules: 0: subdir, 1: filename re match, 2: callback special_treatments = ( - ('python', 'qa.+py$', _handle_py_qa), - ('python', '^(?!qa).+py$', _handle_py_mod), - ('lib', 'qa.+\.cc$', _handle_cc_qa), - ('include/%s' % self._info['modname'], '.+\.h$', _handle_h_swig), - ('include', '.+\.h$', _handle_h_swig), - ('swig', '.+\.i$', _handle_i_swig) + ('python', r'qa.+py$', _handle_py_qa), + ('python', r'^(?!qa).+py$', _handle_py_mod), + ('lib', r'qa.+\.cc$', _handle_cc_qa), + ('include/%s' % self._info['modname'], r'.+\.h$', _handle_h_swig), + ('include', r'.+\.h$', _handle_h_swig), + ('swig', r'.+\.i$', _handle_i_swig) ) for subdir in self._subdirs: - if self._skip_subdirs[subdir]: continue + if self._skip_subdirs[subdir]: + continue if self._info['version'] == '37' and subdir == 'include': subdir = 'include/%s' % self._info['modname'] try: @@ -153,4 +153,3 @@ class ModToolDisable(ModTool): cmake.write() self.scm.mark_files_updated((os.path.join(subdir, 'CMakeLists.txt'),)) print "Careful: 'gr_modtool disable' does not resolve dependencies." - diff --git a/gr-utils/python/modtool/modtool_help.py b/gr-utils/python/modtool/modtool_help.py index b894e272e8..6c7a62e891 100644 --- a/gr-utils/python/modtool/modtool_help.py +++ b/gr-utils/python/modtool/modtool_help.py @@ -65,4 +65,3 @@ class ModToolHelp(ModTool): print_class_descriptions() return cmd_dict[help_requested_for]().setup_parser().print_help() - diff --git a/gr-utils/python/modtool/modtool_info.py b/gr-utils/python/modtool/modtool_info.py index 5596a7db83..3380760725 100644 --- a/gr-utils/python/modtool/modtool_info.py +++ b/gr-utils/python/modtool/modtool_info.py @@ -44,9 +44,9 @@ class ModToolInfo(ModTool): parser.usage = '%prog info [options]. \n Call %prog without any options to run it interactively.' ogroup = OptionGroup(parser, "Info options") ogroup.add_option("--python-readable", action="store_true", default=None, - help="Return the output in a format that's easier to read for Python scripts.") + help="Return the output in a format that's easier to read for Python scripts.") ogroup.add_option("--suggested-dirs", default=None, type="string", - help="Suggest typical include dirs if nothing better can be detected.") + help="Suggest typical include dirs if nothing better can be detected.") parser.add_option_group(ogroup) return parser @@ -69,7 +69,7 @@ class ModToolInfo(ModTool): if self._info['version'] == '36' and ( os.path.isdir(os.path.join('include', mod_info['modname'])) or os.path.isdir(os.path.join('include', 'gnuradio', mod_info['modname'])) - ): + ): self._info['version'] = '37' mod_info['version'] = self._info['version'] if 'is_component' in self._info.keys() and self._info['is_component']: @@ -110,7 +110,7 @@ class ModToolInfo(ModTool): base_build_dir = mod_info['base_dir'] if 'is_component' in mod_info.keys(): (base_build_dir, rest_dir) = os.path.split(base_build_dir) - has_build_dir = os.path.isdir(os.path.join(base_build_dir , 'build')) + has_build_dir = os.path.isdir(os.path.join(base_build_dir, 'build')) if (has_build_dir and os.path.isfile(os.path.join(base_build_dir, 'CMakeCache.txt'))): return os.path.join(base_build_dir, 'build') else: @@ -130,10 +130,11 @@ class ModToolInfo(ModTool): cmakecache_fid = open(os.path.join(mod_info['build_dir'], 'CMakeCache.txt')) for line in cmakecache_fid: if line.find('GNURADIO_RUNTIME_INCLUDE_DIRS:%s' % path_or_internal) != -1: - inc_dirs += line.replace('GNURADIO_RUNTIME_INCLUDE_DIRS:%s=' % path_or_internal, '').strip().split(';') + inc_dirs += line.replace('GNURADIO_RUNTIME_INCLUDE_DIRS:%s=' + % path_or_internal, '').strip().split(';') except IOError: pass - if len(inc_dirs) == 0 and self._suggested_dirs is not None: + if (not inc_dirs or inc_dirs.isspace) and self._suggested_dirs is not None: inc_dirs = [os.path.normpath(path) for path in self._suggested_dirs.split(':') if os.path.isdir(path)] return inc_dirs @@ -147,9 +148,9 @@ class ModToolInfo(ModTool): for key in mod_info.keys(): if key == 'version': print " API version: %s" % { - '36': 'pre-3.7', - '37': 'post-3.7', - 'autofoo': 'Autotools (pre-3.5)' - }[mod_info['version']] + '36': 'pre-3.7', + '37': 'post-3.7', + 'autofoo': 'Autotools (pre-3.5)' + }[mod_info['version']] else: print '%19s: %s' % (index_names[key], mod_info[key]) diff --git a/gr-utils/python/modtool/modtool_makexml.py b/gr-utils/python/modtool/modtool_makexml.py index 9d047a67bc..c45759c605 100644 --- a/gr-utils/python/modtool/modtool_makexml.py +++ b/gr-utils/python/modtool/modtool_makexml.py @@ -57,7 +57,7 @@ class ModToolMakeXML(ModTool): self._info['pattern'] = args[1] else: self._info['pattern'] = raw_input('Which blocks do you want to parse? (Regex): ') - if len(self._info['pattern']) == 0: + if not self._info['pattern'] or self._info['pattern'].isspace(): self._info['pattern'] = '.' def run(self): @@ -85,7 +85,7 @@ class ModToolMakeXML(ModTool): for f in files: if re.search(self._info['pattern'], os.path.basename(f)) is not None: files_filt.append(f) - if len(files_filt) == 0: + if not files_filt: print "None found." return files_filt @@ -113,10 +113,10 @@ class ModToolMakeXML(ModTool): file_exists = True print "Warning: Overwriting existing GRC file." grc_generator = GRCXMLGenerator( - modname=self._info['modname'], - blockname=blockname, - params=params, - iosig=iosig + modname=self._info['modname'], + blockname=blockname, + params=params, + iosig=iosig ) grc_generator.save(path_to_xml) if file_exists: @@ -145,7 +145,7 @@ class ModToolMakeXML(ModTool): 'std::vector<int>': 'int_vector', 'std::vector<float>': 'real_vector', 'std::vector<gr_complex>': 'complex_vector', - } + } if p_type in ('int',) and default_v is not None and len(default_v) > 1 and default_v[:2].lower() == '0x': return 'hex' try: @@ -172,4 +172,3 @@ class ModToolMakeXML(ModTool): raise ModToolException("Can't open some of the files necessary to parse {}.".format(fname_cc)) return (parser.read_params(), parser.read_io_signature(), blockname) - diff --git a/gr-utils/python/modtool/modtool_newmod.py b/gr-utils/python/modtool/modtool_newmod.py index 3e05ecbf48..43ea44618e 100644 --- a/gr-utils/python/modtool/modtool_newmod.py +++ b/gr-utils/python/modtool/modtool_newmod.py @@ -26,7 +26,6 @@ import re from optparse import OptionGroup from gnuradio import gr from modtool_base import ModTool, ModToolException -from scm import SCMRepoFactory class ModToolNewModule(ModTool): """ Create a new out-of-tree module """ @@ -41,7 +40,7 @@ class ModToolNewModule(ModTool): parser.usage = '%prog nm [options]. \n Call %prog without any options to run it interactively.' ogroup = OptionGroup(parser, "New out-of-tree module options") ogroup.add_option("--srcdir", type="string", - help="Source directory for the module template.") + help="Source directory for the module template.") parser.add_option_group(ogroup) return parser @@ -99,4 +98,3 @@ class ModToolNewModule(ModTool): if self.scm.init_repo(path_to_repo="."): print "Created repository... you might want to commit before continuing." print "Use 'gr_modtool add' to add a new block to this currently empty module." - diff --git a/gr-utils/python/modtool/modtool_rename.py b/gr-utils/python/modtool/modtool_rename.py index cc6bd3bd02..dd9b0eaee8 100644 --- a/gr-utils/python/modtool/modtool_rename.py +++ b/gr-utils/python/modtool/modtool_rename.py @@ -23,13 +23,7 @@ import os import re from optparse import OptionGroup - -from util_functions import append_re_line_sequence, ask_yes_no -from cmakefile_editor import CMakeFileEditor from modtool_base import ModTool, ModToolException -from templates import Templates -from code_generator import get_template -import Cheetah.Template class ModToolRename(ModTool): @@ -47,8 +41,10 @@ class ModToolRename(ModTool): def setup_parser(self): parser = ModTool.setup_parser(self) ogroup = OptionGroup(parser, "Rename module options") - ogroup.add_option("-o", "--old-name", type="string", default=None, help="Current name of the block to rename.") - ogroup.add_option("-u", "--new-name", type="string", default=None, help="New name of the block.") + ogroup.add_option("-o", "--old-name", type="string", default=None, + help="Current name of the block to rename.") + ogroup.add_option("-u", "--new-name", type="string", default=None, + help="New name of the block.") parser.add_option_group(ogroup) return parser @@ -56,7 +52,7 @@ class ModToolRename(ModTool): ModTool.setup(self, options, args) if ((self._skip_subdirs['lib'] and self._info['lang'] == 'cpp') - or (self._skip_subdirs['python'] and self._info['lang'] == 'python')): + or (self._skip_subdirs['python'] and self._info['lang'] == 'python')): raise ModToolException('Missing or skipping relevant subdir.') # first make sure the old block name is provided diff --git a/gr-utils/python/modtool/modtool_rm.py b/gr-utils/python/modtool/modtool_rm.py index d03e915ef9..3393942af0 100644 --- a/gr-utils/python/modtool/modtool_rm.py +++ b/gr-utils/python/modtool/modtool_rm.py @@ -62,15 +62,15 @@ class ModToolRemove(ModTool): (base, ext) = os.path.splitext(filename) if ext == '.h': remove_pattern_from_file(self._file['qalib'], - '^#include "%s"\s*$' % filename) + r'^#include "%s"\s*$' % filename) remove_pattern_from_file(self._file['qalib'], - '^\s*s->addTest\(gr::%s::%s::suite\(\)\);\s*$' % ( - self._info['modname'], base) + r'^\s*s->addTest\(gr::%s::%s::suite\(\)\);\s*$' % ( + self._info['modname'], base) ) self.scm.mark_file_updated(self._file['qalib']) elif ext == '.cc': ed.remove_value('list', - '\$\{CMAKE_CURRENT_SOURCE_DIR\}/%s' % filename, + r'\$\{CMAKE_CURRENT_SOURCE_DIR\}/%s' % filename, to_ignore_start='APPEND test_%s_sources' % self._info['modname']) self.scm.mark_file_updated(ed.filename) else: @@ -112,8 +112,8 @@ class ModToolRemove(ModTool): py_files_deleted = self._run_subdir('python', ('*.py',), ('GR_PYTHON_INSTALL',), cmakeedit_func=_remove_py_test_case) for f in py_files_deleted: - remove_pattern_from_file(self._file['pyinit'], '.*import\s+%s.*' % f[:-3]) - remove_pattern_from_file(self._file['pyinit'], '.*from\s+%s\s+import.*\n' % f[:-3]) + remove_pattern_from_file(self._file['pyinit'], r'.*import\s+%s.*' % f[:-3]) + remove_pattern_from_file(self._file['pyinit'], r'.*from\s+%s\s+import.*\n' % f[:-3]) if not self._skip_subdirs['grc']: self._run_subdir('grc', ('*.xml',), ('install',)) @@ -134,7 +134,7 @@ class ModToolRemove(ModTool): for f in files: if re.search(self._info['pattern'], os.path.basename(f)) is not None: files_filt.append(f) - if len(files_filt) == 0: + if not files_filt: print "None found." return [] # 2. Delete files, Makefile entries and other occurrences |