summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/modtool_add.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/python/modtool/modtool_add.py')
-rw-r--r--gr-utils/python/modtool/modtool_add.py48
1 files changed, 25 insertions, 23 deletions
diff --git a/gr-utils/python/modtool/modtool_add.py b/gr-utils/python/modtool/modtool_add.py
index 88b9068cda..1be20f0485 100644
--- a/gr-utils/python/modtool/modtool_add.py
+++ b/gr-utils/python/modtool/modtool_add.py
@@ -21,27 +21,30 @@
""" Module to add new blocks """
import os
-import sys
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
+from modtool_base import ModTool, ModToolException
from templates import Templates
from code_generator import get_template
import Cheetah.Template
+
class ModToolAdd(ModTool):
""" Add block to the out-of-tree module. """
name = 'add'
aliases = ('insert',)
_block_types = ('sink', 'source', 'sync', 'decimator', 'interpolator',
'general', 'tagged_stream', 'hier', 'noblock')
+
def __init__(self):
ModTool.__init__(self)
self._add_cc_qa = False
self._add_py_qa = False
+ self._skip_cmakefiles = False
+ self._license_file = None
def setup_parser(self):
parser = ModTool.setup_parser(self)
@@ -63,9 +66,9 @@ class ModToolAdd(ModTool):
parser.add_option_group(ogroup)
return parser
- def setup(self):
- ModTool.setup(self)
- options = self.options
+ def setup(self, options, args):
+ ModTool.setup(self, options, args)
+
self._info['blocktype'] = options.block_type
if self._info['blocktype'] is None:
while self._info['blocktype'] not in self._block_types:
@@ -79,17 +82,15 @@ class ModToolAdd(ModTool):
if ((self._skip_subdirs['lib'] and self._info['lang'] == 'cpp')
or (self._skip_subdirs['python'] and self._info['lang'] == 'python')):
- print "Missing or skipping relevant subdir."
- exit(1)
+ raise ModToolException('Missing or skipping relevant subdir.')
if self._info['blockname'] is None:
- if len(self.args) >= 2:
- self._info['blockname'] = self.args[1]
+ if len(args) >= 2:
+ self._info['blockname'] = args[1]
else:
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']):
- print 'Invalid block name.'
- exit(2)
+ raise ModToolException('Invalid block name.')
print "Block/code identifier: " + self._info['blockname']
self._info['fullblockname'] = self._info['modname'] + '_' + self._info['blockname']
self._info['license'] = self.setup_choose_license()
@@ -107,11 +108,12 @@ class ModToolAdd(ModTool):
self._add_cc_qa = options.add_cpp_qa
if self._add_cc_qa is None:
self._add_cc_qa = ask_yes_no('Add C++ QA code?', not self._add_py_qa)
- if self._info['version'] == 'autofoo' and not self.options.skip_cmakefiles:
+ self._skip_cmakefiles = options.skip_cmakefiles
+ if self._info['version'] == 'autofoo' and not self._skip_cmakefiles:
print "Warning: Autotools modules are not supported. ",
print "Files will be created, but Makefiles will not be edited."
- self.options.skip_cmakefiles = True
-
+ self._skip_cmakefiles = True
+ self._license_file = options.license_file
def setup_choose_license(self):
""" Select a license by the following rules, in this order:
@@ -119,9 +121,9 @@ class ModToolAdd(ModTool):
2) The contents of the file LICENSE or LICENCE in the modules
top directory
3) The default license. """
- if self.options.license_file is not None \
- and os.path.isfile(self.options.license_file):
- return open(self.options.license_file).read()
+ if self._license_file is not None \
+ and os.path.isfile(self._license_file):
+ return open(self._license_file).read()
elif os.path.isfile('LICENSE'):
return open('LICENSE').read()
elif os.path.isfile('LICENCE'):
@@ -170,7 +172,7 @@ class ModToolAdd(ModTool):
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)
- if not self.options.skip_cmakefiles:
+ if not self._skip_cmakefiles:
try:
append_re_line_sequence(self._file['cmlib'],
'\$\{CMAKE_CURRENT_SOURCE_DIR\}/qa_%s.cc.*\n' % self._info['modname'],
@@ -189,7 +191,7 @@ class ModToolAdd(ModTool):
" Add C++ QA files for pre-3.7 API (not autotools) "
fname_qa_cc = 'qa_%s.cc' % self._info['fullblockname']
self._write_tpl('qa_cpp36', 'lib', fname_qa_cc)
- if not self.options.skip_cmakefiles:
+ if not self._skip_cmakefiles:
open(self._file['cmlib'], 'a').write(
str(
Cheetah.Template.Template(
@@ -221,7 +223,7 @@ class ModToolAdd(ModTool):
fname_cc = self._info['fullblockname'] + '.cc'
self._write_tpl('block_h36', self._info['includedir'], fname_h)
self._write_tpl('block_cpp36', 'lib', fname_cc)
- if not self.options.skip_cmakefiles:
+ if not self._skip_cmakefiles:
ed = CMakeFileEditor(self._file['cmlib'])
cmake_list_var = '[a-z]*_?' + self._info['modname'] + '_sources'
if not ed.append_value('list', fname_cc, to_ignore_start='APPEND ' + cmake_list_var):
@@ -272,7 +274,7 @@ class ModToolAdd(ModTool):
fname_py_qa = 'qa_' + self._info['blockname'] + '.py'
self._write_tpl('qa_python', self._info['pydir'], fname_py_qa)
os.chmod(os.path.join(self._info['pydir'], fname_py_qa), 0755)
- if self.options.skip_cmakefiles or CMakeFileEditor(self._file['cmpython']).check_for_glob('qa_*.py'):
+ if self._skip_cmakefiles or CMakeFileEditor(self._file['cmpython']).check_for_glob('qa_*.py'):
return
print "Editing %s/CMakeLists.txt..." % self._info['pydir']
open(self._file['cmpython'], 'a').write(
@@ -291,7 +293,7 @@ class ModToolAdd(ModTool):
append_re_line_sequence(self._file['pyinit'],
'(^from.*import.*\n|# import any pure.*\n)',
'from %s import %s' % (self._info['blockname'], self._info['blockname']))
- if self.options.skip_cmakefiles:
+ if self._skip_cmakefiles:
return
ed = CMakeFileEditor(self._file['cmpython'])
ed.append_value('GR_PYTHON_INSTALL', fname_py, to_ignore_end='DESTINATION[^()]+')
@@ -306,7 +308,7 @@ class ModToolAdd(ModTool):
fname_grc = self._info['fullblockname'] + '.xml'
self._write_tpl('grc_xml', 'grc', fname_grc)
ed = CMakeFileEditor(self._file['cmgrc'], '\n ')
- if self.options.skip_cmakefiles or ed.check_for_glob('*.xml'):
+ if self._skip_cmakefiles or ed.check_for_glob('*.xml'):
return
print "Editing grc/CMakeLists.txt..."
ed.append_value('install', fname_grc, to_ignore_end='DESTINATION[^()]+')