diff options
Diffstat (limited to 'gr-utils/python/modtool/modtool_newmod.py')
-rw-r--r-- | gr-utils/python/modtool/modtool_newmod.py | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/gr-utils/python/modtool/modtool_newmod.py b/gr-utils/python/modtool/modtool_newmod.py index 6e55c5ea59..3e05ecbf48 100644 --- a/gr-utils/python/modtool/modtool_newmod.py +++ b/gr-utils/python/modtool/modtool_newmod.py @@ -25,7 +25,8 @@ import os import re from optparse import OptionGroup from gnuradio import gr -from modtool_base import ModTool +from modtool_base import ModTool, ModToolException +from scm import SCMRepoFactory class ModToolNewModule(ModTool): """ Create a new out-of-tree module """ @@ -44,17 +45,16 @@ class ModToolNewModule(ModTool): parser.add_option_group(ogroup) return parser - def setup(self): - (options, self.args) = self.parser.parse_args() + def setup(self, options, args): + # Don't call ModTool.setup(), that assumes an existing module. self._info['modname'] = options.module_name if self._info['modname'] is None: - if len(self.args) >= 2: - self._info['modname'] = self.args[1] + if len(args) >= 2: + self._info['modname'] = args[1] else: self._info['modname'] = raw_input('Name of the new module: ') if not re.match('[a-zA-Z0-9_]+$', self._info['modname']): - print 'Invalid module name.' - exit(2) + raise ModToolException('Invalid module name.') self._dir = options.directory if self._dir == '.': self._dir = './gr-%s' % self._info['modname'] @@ -63,14 +63,14 @@ class ModToolNewModule(ModTool): except OSError: pass # This is what should happen else: - print 'The given directory exists.' - exit(2) + raise ModToolException('The given directory exists.') if options.srcdir is None: options.srcdir = '/usr/local/share/gnuradio/modtool/gr-newmod' self._srcdir = gr.prefs().get_string('modtool', 'newmod_path', options.srcdir) if not os.path.isdir(self._srcdir): - print 'Error: Could not find gr-newmod source dir.' - exit(2) + raise ModToolException('Could not find gr-newmod source dir.') + self.options = options + self._setup_scm(mode='new') def run(self): """ @@ -83,9 +83,7 @@ class ModToolNewModule(ModTool): shutil.copytree(self._srcdir, self._dir) os.chdir(self._dir) except OSError: - print 'Failed.' - print 'Could not create directory %s. Quitting.' % self._dir - exit(2) + raise ModToolException('Could not create directory %s.' % self._dir) for root, dirs, files in os.walk('.'): for filename in files: f = os.path.join(root, filename) @@ -98,5 +96,7 @@ class ModToolNewModule(ModTool): if os.path.basename(root) == 'howto': os.rename(root, os.path.join(os.path.dirname(root), self._info['modname'])) print "Done." + 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." |