summaryrefslogtreecommitdiff
path: root/gr-utils/modtool/core/rename.py
diff options
context:
space:
mode:
Diffstat (limited to 'gr-utils/modtool/core/rename.py')
-rw-r--r--gr-utils/modtool/core/rename.py42
1 files changed, 30 insertions, 12 deletions
diff --git a/gr-utils/modtool/core/rename.py b/gr-utils/modtool/core/rename.py
index ac6f07215a..61f98b3722 100644
--- a/gr-utils/modtool/core/rename.py
+++ b/gr-utils/modtool/core/rename.py
@@ -62,25 +62,14 @@ class ModToolRename(ModTool):
oldname = self.info['oldname']
newname = self.info['newname']
logger.info(f"In module '{module}' rename block '{oldname}' to '{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)
self._run_python(self.info['modname'], oldname, newname)
self._run_lib(self.info['modname'], oldname, newname)
self._run_include(self.info['modname'], oldname, newname)
+ self._run_pybind(self.info['modname'], oldname, newname)
return
- def _run_swig_rename(self, swigfilename, old, new):
- """ Rename SWIG includes and block_magic """
- nsubs = self._run_file_replace(swigfilename, old, new)
- if nsubs < 1:
- logger.info(f"Couldn't find '{old}' in file '{swigfilename}'.")
- if nsubs == 2:
- logger.info("Changing 'noblock' type file")
- if nsubs > 3:
- logger.warning(f"Hm, changed more then expected while editing {swigfilename}.")
- return False
-
def _run_lib(self, module, old, new):
ccfile = './lib/' + old + '_impl.cc'
if not os.path.isfile(ccfile): # in case it is a 'noblock'
@@ -129,6 +118,35 @@ class ModToolRename(ModTool):
else:
logger.info("Not a Python block, nothing to do here...")
+ def _run_pybind(self, module, old, new):
+ path = './python/bindings/'
+ filename = path + old + '_python.cc'
+ self._run_file_replace(filename, old, new)
+ self._run_file_rename(path, old, new)
+ self._run_cmakelists(path, old, new)
+ # update the hash in the new file
+ import hashlib
+ hasher = hashlib.md5()
+ header_filename = './include/' + module + '/' + new + '.h' # note this requires _run_pybind to be called after _run_include
+ with open(header_filename, 'rb') as file_in:
+ buf = file_in.read()
+ hasher.update(buf)
+ newhash = hasher.hexdigest()
+ newfilename = path + new + '_python.cc'
+ with open(newfilename) as f:
+ file_txt = f.read()
+ m = re.search(r'BINDTOOL_HEADER_FILE_HASH\(([^\s]*)\)', file_txt)
+ if (m):
+ oldhash = m.group(1)
+ file_txt = re.sub(oldhash, newhash, file_txt)
+ with open(newfilename, "w") as f:
+ f.write(file_txt)
+
+ path = './python/bindings/docstrings/'
+ filename = path + old + '_pydoc_template.h'
+ self._run_file_replace(filename, old, new)
+ self._run_file_rename(path, old, new)
+
def _run_python_qa(self, module, old, new):
new = 'qa_' + new
old = 'qa_' + old