diff options
Diffstat (limited to 'gr-utils/python/modtool/modtool_add.py')
-rw-r--r-- | gr-utils/python/modtool/modtool_add.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/gr-utils/python/modtool/modtool_add.py b/gr-utils/python/modtool/modtool_add.py index 416c0943b7..b7d33c6113 100644 --- a/gr-utils/python/modtool/modtool_add.py +++ b/gr-utils/python/modtool/modtool_add.py @@ -22,7 +22,6 @@ import os import re -from optparse import OptionGroup from util_functions import append_re_line_sequence, ask_yes_no from cmakefile_editor import CMakeFileEditor @@ -33,7 +32,7 @@ from code_generator import render_template class ModToolAdd(ModTool): """ Add block to the out-of-tree module. """ name = 'add' - aliases = ('insert',) + description = 'Add new block into module.' _block_types = ('sink', 'source', 'sync', 'decimator', 'interpolator', 'general', 'tagged_stream', 'hier', 'noblock') @@ -44,30 +43,29 @@ class ModToolAdd(ModTool): self._skip_cmakefiles = False self._license_file = None - def setup_parser(self): - 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)) - ogroup.add_option("--license-file", type="string", default=None, + @staticmethod + def setup_parser(parser): + parser.add_argument("-t", "--block-type", choices=ModToolAdd._block_types, + help="One of %s." % ', '.join(ModToolAdd._block_types)) + parser.add_argument("--license-file", help="File containing the license header for every source code file.") - ogroup.add_option("--copyright", type="string", default=None, + parser.add_argument("--copyright", help="Name of the copyright holder (you or your company) MUST be a quoted string.") - ogroup.add_option("--argument-list", type="string", default=None, + parser.add_argument("--argument-list", help="The argument list for the constructor and make functions.") - ogroup.add_option("--add-python-qa", action="store_true", default=None, + parser.add_argument("--add-python-qa", action="store_true", default=None, help="If given, Python QA code is automatically added if possible.") - ogroup.add_option("--add-cpp-qa", action="store_true", default=None, + parser.add_argument("--add-cpp-qa", action="store_true", default=None, help="If given, C++ QA code is automatically added if possible.") - ogroup.add_option("--skip-cmakefiles", action="store_true", default=False, + parser.add_argument("--skip-cmakefiles", action="store_true", 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)") - parser.add_option_group(ogroup) + parser.add_argument("-l", "--lang", choices=('cpp', 'c++', 'python'), + help="Programing language") + ModTool.setup_parser_block(parser) return parser - def setup(self, options, args): - ModTool.setup(self, options, args) + def setup(self, options): + ModTool.setup(self, options) self._info['blocktype'] = options.block_type if self._info['blocktype'] is None: @@ -80,7 +78,7 @@ class ModToolAdd(ModTool): # Allow user to specify language interactively if not set self._info['lang'] = options.lang if self._info['lang'] is None: - while self._info['lang'] not in ['cpp', 'python']: + while self._info['lang'] not in ['c++', 'cpp', 'python']: self._info['lang'] = raw_input("Language (python/cpp): ") if self._info['lang'] == 'c++': self._info['lang'] = 'cpp' @@ -92,10 +90,7 @@ class ModToolAdd(ModTool): raise ModToolException('Missing or skipping relevant subdir.') if self._info['blockname'] is None: - if len(args) >= 2: - self._info['blockname'] = args[1] - else: - self._info['blockname'] = raw_input("Enter name of block/code (without module name prefix): ") + self._info['blockname'] = raw_input("Enter name of block/code (without module name prefix): ") if not re.match('[a-zA-Z0-9_]+', self._info['blockname']): raise ModToolException('Invalid block name.') print "Block/code identifier: " + self._info['blockname'] @@ -152,8 +147,9 @@ class ModToolAdd(ModTool): open(path_to_file, 'w').write(render_template(tpl, **self._info)) self.scm.add_files((path_to_file,)) - def run(self): + def run(self, options): """ Go, go, go. """ + self.setup(options) has_swig = ( self._info['lang'] == 'cpp' and not self._skip_subdirs['swig'] |