From e10eb2f45c1ad655f1b965cddcdc1c7757364a87 Mon Sep 17 00:00:00 2001 From: shnavid Date: Fri, 26 Jan 2007 14:54:16 +0000 Subject: 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 --- src/lib/sos/plugins/general.py | 3 +++ src/lib/sos/plugintools.py | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/lib') 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 -- cgit