diff options
author | Solomon <solomonbstoner@yahoo.com.au> | 2021-06-25 20:27:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-25 08:27:32 -0400 |
commit | ac738e2a6db48f13929c780d89a87ba5e916e2d3 (patch) | |
tree | b598981e7001780661808b404576caa60f7192c6 /gr-utils/modtool/core/rename.py | |
parent | 5ed43ed63b20d74a2641c8d1e547f84cd98179e4 (diff) |
modtool: Fix `rm`, `disable`, `rename` and `makeyml` similar naming
* modtool: Fix issue #2672 for `rm`
In the event that the user specifies only one specific block to delete,
this PR ensures that the files for said block is not confused with files
of similarly named blocks.
Signed-off-by: Solomon Tan <solomonbstoner@yahoo.com.au>
* modtool: Fix issue #2672 for `rename` and more
This commit fixes the following for the `rename` command.
1. Issue #2672 that also affects `rename`
2. Fixes errorneous replacement of similarly named blocks in CMakeLists
3. Replaced the file search in `_run_file_rename` from `file.find` to
`re.search` so that block names will not be confused with names with one
or two prefix characters (e.g. "decoder" vs "adecoder").
4. Renames the bind function in `python_bindings.cc` as well.
Signed-off-by: Solomon Tan <solomonbstoner@yahoo.com.au>
* modtool: Fix Issue #2672 for `disable` & more
When the user specifies a block name, only the block with that specific
blockname should be disabled. Prior to this PR, all blocks matching said
specified block name are disabled. This PR fixes it.
This PR also fixes what appears to be a spelling error `self._info`. The
error is thrown for OOT module version 38:
Attribute error `'ModToolDisable' object has no attribute '_info'`
Signed-off-by: Solomon Tan <solomonbstoner@yahoo.com.au>
* modtool: Fix Issue #2672 for `makeyaml`
This PR fixes issue #2672 which also affects the `makeyaml` command.
Signed-off-by: Solomon Tan <solomonbstoner@yahoo.com.au>
Diffstat (limited to 'gr-utils/modtool/core/rename.py')
-rw-r--r-- | gr-utils/modtool/core/rename.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/gr-utils/modtool/core/rename.py b/gr-utils/modtool/core/rename.py index 183b3a2694..edae90389a 100644 --- a/gr-utils/modtool/core/rename.py +++ b/gr-utils/modtool/core/rename.py @@ -73,8 +73,10 @@ class ModToolRename(ModTool): self._run_file_replace(ccfile, old, new) self._run_file_replace(hfile, old, new) self._run_file_replace(hfile, old.upper(), new.upper()) # take care of include guards - self._run_cmakelists('./lib/', old, new) - self._run_file_rename('./lib/', old, new) + self._run_cmakelists('./lib/', old, new, '_impl.cc') + self._run_cmakelists('./lib/', old, new, '_impl.h') + self._run_file_rename('./lib/', old, new, '_impl.cc') + self._run_file_rename('./lib/', old, new, '_impl.h') self._run_cpp_qa(module, old, new) def _run_cpp_qa(self, module, old, new): @@ -88,7 +90,8 @@ class ModToolRename(ModTool): filename = 'qa_' + old + '.h' self._run_file_replace(path + filename, old, new) self._run_file_replace(path + filename, old.upper(), new.upper()) - self._run_file_rename(path, 'qa_' + old, 'qa_' + new) + self._run_file_rename(path, 'qa_' + old, 'qa_' + new, '.cc') + self._run_file_rename(path, 'qa_' + old, 'qa_' + new, '.h') else: logger.info("No C++ QA code detected, skipping...") @@ -97,8 +100,8 @@ class ModToolRename(ModTool): filename = path + old + '.h' self._run_file_replace(filename, old, new) self._run_file_replace(filename, old.upper(), new.upper()) # take care of include guards - self._run_cmakelists(path, old, new) - self._run_file_rename(path, old, new) + self._run_cmakelists(path, old, new, '.h') + self._run_file_rename(path, old, new, '.h') def _run_python(self, module, old, new): path = './python/' @@ -108,8 +111,8 @@ class ModToolRename(ModTool): logger.info("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) + self._run_cmakelists(path, old, new, '.py') + self._run_file_rename(path, old, new, '.py') else: logger.info("Not a Python block, nothing to do here...") @@ -117,8 +120,8 @@ class ModToolRename(ModTool): 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) + self._run_file_rename(path, old, new, '_python.cc') + self._run_cmakelists(path, old, new, '_python.cc') # update the hash in the new file import hashlib hasher = hashlib.md5() @@ -136,36 +139,43 @@ class ModToolRename(ModTool): file_txt = re.sub(oldhash, newhash, file_txt) with open(newfilename, "w") as f: f.write(file_txt) - + + filename = path + 'python_bindings.cc' + self._run_file_replace(filename, ' bind_' + old + '\\(', ' bind_' + new + '(') + path = './python/bindings/docstrings/' filename = path + old + '_pydoc_template.h' self._run_file_replace(filename, old, new) - self._run_file_rename(path, old, new) + self._run_file_rename(path, old, new, '_pydoc_template.h') def _run_python_qa(self, module, old, new): new = 'qa_' + new old = 'qa_' + old filename = './python/' + old + '.py' self._run_file_replace(filename, old, new) - self._run_cmakelists('./python/', old, new) - self._run_file_rename('./python/', old, new) + self._run_cmakelists('./python/', old, new, '.py') + self._run_file_rename('./python/', old, new, '.py') def _run_grc_rename(self, module, old, new): - grcfile = './grc/' + module + '_' + old + '.yml' + grcfile = './grc/' + module + '_' + old + '.block.yml' self._run_file_replace(grcfile, old, new) - self._run_cmakelists('./grc/', old, new) - self._run_file_rename('./grc/', module + '_' + old, module + '_' + new) + self._run_cmakelists('./grc/', module + '_' + old, module + '_' + new, '.block.yml') + self._run_file_rename('./grc/', module + '_' + old, module + '_' + new, '.block.yml') - def _run_cmakelists(self, path, first, second): + def _run_cmakelists(self, path, first, second, suffix): filename = path + 'CMakeLists.txt' - nsubs = self._run_file_replace(filename, first, second) + # space character and suffix ensures similiarly named blocks are not mixed up + nsubs = self._run_file_replace(filename, ' ' + first + suffix, ' ' + second + suffix) if nsubs < 1: logger.info(f"'{first}' wasn't in '{filename}'.") - def _run_file_rename(self, path, old, new): + def _run_file_rename(self, path, old, new, suffix): + old = old + suffix + new = new + suffix + old_regex = '^' + old files = os.listdir(path) for file in files: - if file.find(old) > -1 and file.find(old) < 3: + if re.search(old_regex, file): nl = file.replace(old, new) src = path + file dst = path + nl |