summaryrefslogtreecommitdiff
path: root/gr-utils/python/modtool/modtool_rename.py
diff options
context:
space:
mode:
authorSwapnil Negi <swapnil.negi09@gmail.com>2018-05-21 12:50:35 +0530
committerMartin Braun <martin.braun@ettus.com>2018-11-22 15:07:10 -0800
commit8dc5fa49dc4c669c28ffb1216625ae92475c4ec9 (patch)
treecb70f332e9840db442233c161830b8ecdeaf832c /gr-utils/python/modtool/modtool_rename.py
parent94af848ebe70450a655685d74a75b1977fa120c9 (diff)
utils: modtool: rename: Use SequenceCompleter to suggest blocknames
Diffstat (limited to 'gr-utils/python/modtool/modtool_rename.py')
-rw-r--r--gr-utils/python/modtool/modtool_rename.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/gr-utils/python/modtool/modtool_rename.py b/gr-utils/python/modtool/modtool_rename.py
index 4af860b5d4..60460680e3 100644
--- a/gr-utils/python/modtool/modtool_rename.py
+++ b/gr-utils/python/modtool/modtool_rename.py
@@ -26,12 +26,29 @@ from __future__ import unicode_literals
import os
import re
+import glob
from .util_functions import append_re_line_sequence, ask_yes_no
+from .util_functions import SequenceCompleter
from .cmakefile_editor import CMakeFileEditor
from .modtool_base import ModTool, ModToolException
from .templates import Templates
+def get_block_candidates():
+ cpp_filters = ["*.cc", "*.cpp"]
+ cpp_blocks = []
+ for ftr in cpp_filters:
+ cpp_blocks += filter(lambda x: not (x.startswith('qa_') or
+ x.startswith('test_')),
+ glob.glob1("lib", ftr))
+ python_blocks = filter(lambda x: not (x.startswith('qa_') or
+ x.startswith('build') or
+ x.startswith('__init__')),
+ glob.glob1("python", "*.py"))
+ block_candidates = [x.split('_impl')[0] for x in cpp_blocks] + [x.split('.')[0] for x in python_blocks]
+ return block_candidates
+
+
class ModToolRename(ModTool):
""" Rename a block in the out-of-tree module. """
name = 'rename'
@@ -63,6 +80,11 @@ class ModToolRename(ModTool):
self._info['oldname'] = options.blockname
if self._info['oldname'] is None:
self._info['oldname'] = input("Enter name of block/code to rename (without module name prefix): ")
+ else:
+ block_candidates = get_block_candidates()
+ with SequenceCompleter(block_candidates):
+ self._info['oldname'] = \
+ raw_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'])