From f4c55faa2a369688b2f8d5885d2861522fb1f7de Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 3 Apr 2014 21:22:50 +0100 Subject: [PATCH 62/72] Add Plugin.do_path_regex_sub() Add a method to the Plugin class to apply a regex substitution to a set of paths maching a path regex. For e.g.: self.do_path_regex_sub(r'/etc/foo.*', 'pw=(.*)', 'pw=****') The oVirt plugin will use this. Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 7e865cd..88c909f 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -191,6 +191,18 @@ class Plugin(object): replacements = 0 return replacements + def do_path_regex_sub(self, pathexp, regexp, subst): + '''Apply a regexp substituation to a set of files archived by + sos. The set of files to be substituted is generated by matching + collected file pathnames against pathexp which may be a regular + expression string or compiled re object. The portion of the file + to be replaced is specified via regexp and the replacement string + is passed in subst.''' + match = pathexp.match + file_list = [f for f in self.copied_files if match(f['srcpath'])] + for file in file_list: + self.do_file_sub(file['srcpath'], regexp, subst) + def do_regex_find_all(self, regex, fname): return regex_findall(regex, fname) -- 1.9.3