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.py71
1 files changed, 47 insertions, 24 deletions
diff --git a/gr-utils/python/modtool/modtool_add.py b/gr-utils/python/modtool/modtool_add.py
index acc0385ac4..46ff74168a 100644
--- a/gr-utils/python/modtool/modtool_add.py
+++ b/gr-utils/python/modtool/modtool_add.py
@@ -1,5 +1,5 @@
#
-# Copyright 2013-2014 Free Software Foundation, Inc.
+# Copyright 2013, 2017 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -71,6 +71,18 @@ class ModToolAdd(ModTool):
def setup(self, options):
ModTool.setup(self, options)
+ 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): ")
+ if os.path.isfile("./lib/"+self._info['blockname']+"_impl.cc") or os.path.isfile("./python/"+self._info['blockname']+".py"):
+ raise ModToolException('The given blockname already exists!')
+ if not re.match('[a-zA-Z0-9_]+', self._info['blockname']):
+ raise ModToolException('Invalid block name.')
+ print "Block/code identifier: " + self._info['blockname']
+ self._info['fullblockname'] = self._info['modname'] + '_' + self._info['blockname']
+
self._info['blocktype'] = options.block_type
if self._info['blocktype'] is None:
# Print list out of blocktypes to user for reference
@@ -94,7 +106,7 @@ 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 self._info['blockname'] is None:
@@ -106,7 +118,16 @@ class ModToolAdd(ModTool):
if not options.license_file:
self._info['copyrightholder'] = options.copyright
if self._info['copyrightholder'] is None:
- self._info['copyrightholder'] = '<+YOU OR YOUR COMPANY+>'
+ user = getpass.getuser()
+ git_user = self.scm.get_gituser()
+ if git_user:
+ copyright_candidates = (user, git_user, 'GNU Radio')
+ else:
+ copyright_candidates = (user, 'GNU Radio')
+ with SequenceCompleter(copyright_candidates):
+ self._info['copyrightholder'] = raw_input("Please specify the copyright holder: ")
+ if not self._info['copyrightholder'] or self._info['copyrightholder'].isspace():
+ self._info['copyrightholder'] = "gr-"+self._info['modname']+" author"
elif self._info['is_component']:
print("For GNU Radio components the FSF is added as copyright holder")
self._license_file = options.license_file
@@ -159,8 +180,8 @@ class ModToolAdd(ModTool):
""" Go, go, go. """
self.setup(options)
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':
@@ -186,14 +207,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',
@@ -202,26 +223,26 @@ 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.")
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()
@@ -254,14 +275,15 @@ class ModToolAdd(ModTool):
swig_block_magic_str = render_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'],))
@@ -280,8 +302,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):
@@ -295,7 +317,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