summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/modtool_rename.py
diff options
context:
space:
mode:
authorAndrej Rode <mail@andrejro.de>2018-06-23 23:41:42 +0200
committerAndrej Rode <mail@andrejro.de>2018-06-24 00:03:35 +0200
commit167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch)
treea01049672d9d7d1bf3d295ed96698a323941f8e8 /gr-utils/python/modtool/modtool_rename.py
parent3c8e6008b092287246234001db7cf1a4038300da (diff)
parentfcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff)
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following conflicts: * Typos: * gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py * gr-blocks/python/blocks/qa_wavfile.py * gr-filter/examples/gr_filtdes_api.py * grc/blocks/parameter.xml * gr-uhd/python/uhd/__init__.py * ValueError -> RuntimeError: * gr-blocks/python/blocks/qa_hier_block2.py * relative Imports & other Py3k: * gr-digital/python/digital/psk_constellations.py * gr-digital/python/digital/qam_constellations.py * gr-digital/python/digital/test_soft_decisions.py * gr-digital/python/digital/gfsk.py * SequenceCompleter: * gr-utils/python/modtool/modtool_add.py * gr-utils/python/modtool/modtool_rename.py * gr-utils/python/modtool/modtool_rm.py * Updated API on next: * gr-blocks/grc/blocks_file_source.xml * gr-blocks/python/blocks/qa_file_source_sink.py * gr-qtgui/grc/qtgui_time_sink_x.xml * GRC Py3k Updates: * grc/core/Block.py * grc/core/Constants.py * grc/core/Platform.py * grc/core/utils/odict.py * grc/gui/Actions.py * grc/gui/Block.py * grc/gui/Executor.py * grc/gui/Port.py
Diffstat (limited to 'gr-utils/python/modtool/modtool_rename.py')
-rw-r--r--gr-utils/python/modtool/modtool_rename.py42
1 files changed, 23 insertions, 19 deletions
diff --git a/gr-utils/python/modtool/modtool_rename.py b/gr-utils/python/modtool/modtool_rename.py
index 6b1f6da11d..b9112fb8c4 100644
--- a/gr-utils/python/modtool/modtool_rename.py
+++ b/gr-utils/python/modtool/modtool_rename.py
@@ -20,13 +20,17 @@
#
""" Module to rename blocks """
+from __future__ import print_function
+from __future__ import absolute_import
+from __future__ import unicode_literals
+
import os
import re
-from util_functions import append_re_line_sequence, ask_yes_no
-from cmakefile_editor import CMakeFileEditor
-from modtool_base import ModTool, ModToolException
-from templates import Templates
+from .util_functions import append_re_line_sequence, ask_yes_no
+from .cmakefile_editor import CMakeFileEditor
+from .modtool_base import ModTool, ModToolException
+from .templates import Templates
class ModToolRename(ModTool):
""" Rename a block in the out-of-tree module. """
@@ -58,20 +62,20 @@ class ModToolRename(ModTool):
# first make sure the old block name is provided
self._info['oldname'] = options.blockname
if self._info['oldname'] is None:
- self._info['oldname'] = raw_input("Enter name of block/code to rename (without module name prefix): ")
+ self._info['oldname'] = input("Enter name of block/code to rename (without module name prefix): ")
if not re.match('[a-zA-Z0-9_]+', self._info['oldname']):
raise ModToolException('Invalid block name.')
- print "Block/code to rename identifier: " + self._info['oldname']
+ print("Block/code to rename identifier: " + self._info['oldname'])
self._info['fulloldname'] = self._info['modname'] + '_' + self._info['oldname']
# now get the new block name
if options.new_name is None:
- self._info['newname'] = raw_input("Enter name of block/code (without module name prefix): ")
+ self._info['newname'] = input("Enter name of block/code (without module name prefix): ")
else:
self._info['newname'] = options.new_name[0]
if not re.match('[a-zA-Z0-9_]+', self._info['newname']):
raise ModToolException('Invalid block name.')
- print "Block/code identifier: " + self._info['newname']
+ print("Block/code identifier: " + self._info['newname'])
self._info['fullnewname'] = self._info['modname'] + '_' + self._info['newname']
def run(self, options):
@@ -80,7 +84,7 @@ class ModToolRename(ModTool):
module = self._info['modname']
oldname = self._info['oldname']
newname = self._info['newname']
- print "In module '%s' rename block '%s' to '%s'" % (module, oldname, newname)
+ print("In module '%s' rename block '%s' to '%s'" % (module, oldname, newname))
self._run_swig_rename(self._file['swig'], oldname, newname)
self._run_grc_rename(self._info['modname'], oldname, newname)
self._run_python_qa(self._info['modname'], oldname, newname)
@@ -93,11 +97,11 @@ class ModToolRename(ModTool):
""" Rename SWIG includes and block_magic """
nsubs = self._run_file_replace(swigfilename, old, new)
if nsubs < 1:
- print "Couldn't find '%s' in file '%s'." % (old, swigfilename)
+ print("Couldn't find '%s' in file '%s'." % (old, swigfilename))
if nsubs == 2:
- print "Changing 'noblock' type file"
+ print("Changing 'noblock' type file")
if nsubs > 3:
- print "Hm, changed more then expected while editing %s." % swigfilename
+ print("Hm, changed more then expected while editing %s." % swigfilename)
return False
def _run_lib(self, module, old, new):
@@ -117,7 +121,7 @@ class ModToolRename(ModTool):
filename = 'qa_' + module + '.cc'
nsubs = self._run_file_replace(path + filename, old, new)
if nsubs > 0:
- print "C++ QA code detected, renaming..."
+ print("C++ QA code detected, renaming...")
filename = 'qa_' + old + '.cc'
self._run_file_replace(path + filename, old, new)
filename = 'qa_' + old + '.h'
@@ -125,7 +129,7 @@ class ModToolRename(ModTool):
self._run_file_replace(path + filename, old.upper(), new.upper())
self._run_file_rename(path, 'qa_' + old, 'qa_' + new)
else:
- print "No C++ QA code detected, skipping..."
+ print("No C++ QA code detected, skipping...")
def _run_include(self, module, old, new):
path = './include/' + module + '/'
@@ -140,13 +144,13 @@ class ModToolRename(ModTool):
filename = '__init__.py'
nsubs = self._run_file_replace(path + filename, old, new)
if nsubs > 0:
- print "Python block detected, renaming..."
+ print("Python block detected, renaming...")
filename = old + '.py'
self._run_file_replace(path + filename, old, new)
self._run_cmakelists(path, old, new)
self._run_file_rename(path, old, new)
else:
- print "Not a Python block, nothing to do here..."
+ print("Not a Python block, nothing to do here...")
def _run_python_qa(self, module, old, new):
new = 'qa_' + new
@@ -166,7 +170,7 @@ class ModToolRename(ModTool):
filename = path + 'CMakeLists.txt'
nsubs = self._run_file_replace(filename, first, second)
if nsubs < 1:
- print "'%s' wasn't in '%s'." % (first, filename)
+ print("'%s' wasn't in '%s'." % (first, filename))
def _run_file_rename(self, path, old, new):
files = os.listdir(path)
@@ -175,14 +179,14 @@ class ModToolRename(ModTool):
nl = file.replace(old, new)
src = path + file
dst = path + nl
- print "Renaming file '%s' to '%s'." % (src, dst)
+ print("Renaming file '%s' to '%s'." % (src, dst))
os.rename(src, dst)
def _run_file_replace(self, filename, old, new):
if not os.path.isfile(filename):
return False
else:
- print "In '%s' renaming occurrences of '%s' to '%s'" % (filename, old, new)
+ print("In '%s' renaming occurrences of '%s' to '%s'" % (filename, old, new))
cfile = open(filename).read()
(cfile, nsubs) = re.subn(old, new, cfile)