diff options
author | shnavid <shnavid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-01-26 14:54:16 +0000 |
---|---|---|
committer | shnavid <shnavid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-01-26 14:54:16 +0000 |
commit | e10eb2f45c1ad655f1b965cddcdc1c7757364a87 (patch) | |
tree | 5c90900d53b19fea61eef05e494f0e6fba6c6b42 /src/lib | |
parent | 22460bf9befb2bd6fe6765d86556f2267a641121 (diff) | |
download | sos-e10eb2f45c1ad655f1b965cddcdc1c7757364a87.tar.gz |
Added doRegexSub() to be called in postproc() to apply a regexp substitution to a file which has been collected by sos.
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@68 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/sos/plugins/general.py | 3 | ||||
-rw-r--r-- | src/lib/sos/plugintools.py | 25 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/lib/sos/plugins/general.py b/src/lib/sos/plugins/general.py index 7488cc2c..d3cfa9a0 100644 --- a/src/lib/sos/plugins/general.py +++ b/src/lib/sos/plugins/general.py @@ -33,3 +33,6 @@ class general(sos.plugintools.PluginBase): self.collectExtOutput("/usr/bin/uptime") return + def postproc(self): + self.doRegexSub("/etc/sysconfig/rhn/up2date", r"(\s*proxyPassword\s*=\s*)\S+", r"\1***") + return diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index f6b9e40b..8f8de4d8 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -30,7 +30,7 @@ This is the base class for sosreport plugins """ from sos.helpers import * from threading import Thread -import os, os.path, sys, string, itertools, glob +import os, os.path, sys, string, itertools, glob, re class PluginBase: """ @@ -62,6 +62,29 @@ class PluginBase: self.optNames.append(opt[0]) self.optParms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]}) + # Method for applying regexp substitutions + def doRegexSub(self, srcpath, regexp, subst): + '''Apply a regexp substitution to a file archived by sosreport. + ''' + if len(self.copiedFiles): + for afile in self.copiedFiles: + if afile['srcpath'] == srcpath: + abspath = os.path.join(self.cInfo['dstroot'], srcpath.lstrip(os.path.sep)) + try: + fp = open(abspath, 'r') + tmpout, occurs = re.subn( regexp, subst, fp.read() ) + fp.close() + if occurs > 0: + fp = open(abspath,'w') + fp.write(tmpout) + fp.close() + return occurs + except: + sys.stderr.write("Problem at path %s\n" % abspath) + sys.stderr.flush() + break + return False + # Methods for copying files and shelling out def doCopyFileOrDir(self, srcpath): # pylint: disable-msg = R0912 |