summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/modtool_disable.py
diff options
context:
space:
mode:
authorMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
committerMarcus Müller <marcus@hostalia.de>2018-08-31 23:02:22 +0200
commit254fe5e89403d4de1fa6663d09efdf946996aff3 (patch)
tree62877d7ac7fdedf6c397c51e22ac6f97eba97ddf /gr-utils/python/modtool/modtool_disable.py
parent896d1c9da31963ecf5b0d90942c2af51ca998a69 (diff)
parent5ad935c3a3dd46ce2860b13e2b774e4841784616 (diff)
Merge remote-tracking branch 'origin/next' into merge_next
Diffstat (limited to 'gr-utils/python/modtool/modtool_disable.py')
-rw-r--r--gr-utils/python/modtool/modtool_disable.py48
1 files changed, 28 insertions, 20 deletions
diff --git a/gr-utils/python/modtool/modtool_disable.py b/gr-utils/python/modtool/modtool_disable.py
index a23e16eccb..556b2e1ab2 100644
--- a/gr-utils/python/modtool/modtool_disable.py
+++ b/gr-utils/python/modtool/modtool_disable.py
@@ -20,35 +20,41 @@
#
""" Disable blocks module """
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
import os
import re
import sys
-from modtool_base import ModTool
-from cmakefile_editor import CMakeFileEditor
+from .modtool_base import ModTool
+from .cmakefile_editor import CMakeFileEditor
class ModToolDisable(ModTool):
""" Disable block (comments out CMake entries for files) """
name = 'disable'
- aliases = ('dis',)
+ description = 'Disable selected block in module.'
def __init__(self):
ModTool.__init__(self)
- def setup(self, options, args):
- ModTool.setup(self, options, args)
+ @staticmethod
+ def setup_parser(parser):
+ ModTool.setup_parser_block(parser)
+
+ def setup(self, options):
+ ModTool.setup(self, options)
- if options.block_name is not None:
- self._info['pattern'] = options.block_name
- elif len(args) >= 2:
- self._info['pattern'] = args[1]
+ if options.blockname is not None:
+ self._info['pattern'] = options.blockname
else:
- self._info['pattern'] = raw_input('Which blocks do you want to disable? (Regex): ')
- if not self._info['pattern'] or self._info['pattern'].isspace():
+ self._info['pattern'] = input('Which blocks do you want to disable? (Regex): ')
+ if len(self._info['pattern']) == 0:
self._info['pattern'] = '.'
- def run(self):
+ def run(self, options):
""" Go, go, go! """
def _handle_py_qa(cmake, fname):
""" Do stuff for py qa """
@@ -60,7 +66,7 @@ class ModToolDisable(ModTool):
try:
initfile = open(self._file['pyinit']).read()
except IOError:
- print "Could not edit __init__.py, that might be a problem."
+ print("Could not edit __init__.py, that might be a problem.")
return False
pymodname = os.path.splitext(fname)[0]
initfile = re.sub(r'((from|import)\s+\b'+pymodname+r'\b)', r'#\1', initfile)
@@ -90,14 +96,14 @@ class ModToolDisable(ModTool):
(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']
+ print("Changing %s..." % self._file['swig'])
if nsubs > 1: # Need to find a single BLOCK_MAGIC
blockname = os.path.splitext(fname[len(self._info['modname'])+1:])[0]
if self._info['version'] == '37':
blockname = os.path.splitext(fname)[0]
(swigfile, nsubs) = re.subn('(GR_SWIG_BLOCK_MAGIC2?.+%s.+;)' % blockname, r'//\1', swigfile)
if nsubs > 1:
- print "Hm, changed more then expected while editing %s." % self._file['swig']
+ print("Hm, changed more then expected while editing %s." % self._file['swig'])
open(self._file['swig'], 'w').write(swigfile)
self.scm.mark_file_updated(self._file['swig'])
return False
@@ -108,12 +114,13 @@ 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(r'(%include\s+"'+fname+'")', r'//\1', swigfile)
- print "Changing %s..." % self._file['swig']
+ swigfile = re.sub('(%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)
self.scm.mark_file_updated(self._file['swig'])
return False
+ self.setup(options)
# List of special rules: 0: subdir, 1: filename re match, 2: callback
special_treatments = (
('python', r'qa.+py$', _handle_py_qa),
@@ -132,13 +139,13 @@ class ModToolDisable(ModTool):
cmake = CMakeFileEditor(os.path.join(subdir, 'CMakeLists.txt'))
except IOError:
continue
- print "Traversing %s..." % subdir
+ print("Traversing %s..." % subdir)
filenames = cmake.find_filenames_match(self._info['pattern'])
yes = self._info['yes']
for fname in filenames:
file_disabled = False
if not yes:
- ans = raw_input("Really disable %s? [Y/n/a/q]: " % fname).lower().strip()
+ ans = input("Really disable %s? [Y/n/a/q]: " % fname).lower().strip()
if ans == 'a':
yes = True
if ans == 'q':
@@ -152,4 +159,5 @@ class ModToolDisable(ModTool):
cmake.disable_file(fname)
cmake.write()
self.scm.mark_files_updated((os.path.join(subdir, 'CMakeLists.txt'),))
- print "Careful: 'gr_modtool disable' does not resolve dependencies."
+ print("Careful: 'gr_modtool disable' does not resolve dependencies.")
+