aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-04-03 21:22:50 +0100
committerBryn M. Reeves <bmr@redhat.com>2014-04-03 21:22:50 +0100
commit6e8c0429cf4cbba8f3dc8001f36d7fb0e245c14e (patch)
tree3966af135182a7e72740565e86febdd5eab8de10
parent51c429478b75c836705d0e877ee5222658210b3f (diff)
downloadsos-6e8c0429cf4cbba8f3dc8001f36d7fb0e245c14e.tar.gz
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 <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 7e865cdf..88c909f8 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)