diff options
author | Josh Morman <mormjb@gmail.com> | 2020-05-29 08:05:28 -0400 |
---|---|---|
committer | Josh Morman <mormjb@gmail.com> | 2020-06-04 10:05:48 -0400 |
commit | fbb1f97a4d3e879fcfd15e9826f3b05cfc8504bd (patch) | |
tree | 718cbb1d95263dfb42117ec2be2845d77fcae1dd /gr-utils/modtool/tools/cppfile_editor.py | |
parent | 34d8e7281fd908f26e1c77830e7779bcaac0b5b7 (diff) |
pybind: incorporate modtool rm
Diffstat (limited to 'gr-utils/modtool/tools/cppfile_editor.py')
-rw-r--r-- | gr-utils/modtool/tools/cppfile_editor.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/gr-utils/modtool/tools/cppfile_editor.py b/gr-utils/modtool/tools/cppfile_editor.py index 9f2d3f1fda..052a887221 100644 --- a/gr-utils/modtool/tools/cppfile_editor.py +++ b/gr-utils/modtool/tools/cppfile_editor.py @@ -45,9 +45,25 @@ class CPPFileEditor(object): return 1 - def remove_value(self, entry, value, to_ignore_start='', to_ignore_end=''): - # TODO - gr_modtool rm - pass + def remove_value(self, start_tag, end_tag, value): + + cfile_lines = self.cfile.splitlines() + try: + start_line_idx = [cfile_lines.index(s) for s in cfile_lines if start_tag in s][0] + end_line_idx = [cfile_lines.index(s) for s in cfile_lines if end_tag in s][0] + except: + logger.warning("Could not find start or end tags in search") + return 0 + + try: + lines_between_tags = cfile_lines[(start_line_idx+1):end_line_idx] + remove_index = [lines_between_tags.index(s) for s in cfile_lines if value in s][0] + lines_between_tags.pop(remove_index) + except: + return 0 + + self.cfile = '\n'.join((cfile_lines[0:(start_line_idx+1)]+lines_between_tags+cfile_lines[end_line_idx:])) + return 1 def delete_entry(self, entry, value_pattern=''): """Remove an entry from the current buffer.""" |