diff options
author | shnavid <shnavid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-04-18 09:19:23 +0000 |
---|---|---|
committer | shnavid <shnavid@ef72aa8b-4018-0410-8976-d6e080ef94d8> | 2007-04-18 09:19:23 +0000 |
commit | 11a37a509cbb6f14e4cf7e492acb6d062a297c94 (patch) | |
tree | 64a896dbe17668d8bd5dd228df9c82bb455372e0 /src | |
parent | e08b794fa844a91f84519a3c587bb2db0e2f99cc (diff) | |
download | sos-11a37a509cbb6f14e4cf7e492acb6d062a297c94.tar.gz |
Import logging module to make sure we have access to logging.*
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/sos/trunk@121 ef72aa8b-4018-0410-8976-d6e080ef94d8
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/sos/plugintools.py | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/lib/sos/plugintools.py b/src/lib/sos/plugintools.py index f0347ca8..b40e68e8 100644 --- a/src/lib/sos/plugintools.py +++ b/src/lib/sos/plugintools.py @@ -31,6 +31,7 @@ This is the base class for sosreport plugins from sos.helpers import * from threading import Thread, activeCount import os, os.path, sys, string, itertools, glob, re +import logging class PluginBase: """ @@ -292,18 +293,8 @@ class PluginBase: """ self.collectProgs.append(exe) - def collectOutputNow(self, exe): - """ Execute a command and save the output to a file for inclusion in - the report - """ - # First check to make sure the binary exists and is runnable. - if not os.access(exe.split()[0], os.X_OK): - self.cInfo['soslog'](logging.VERBOSE2, "Binary '%s' does not exist or is not runnable" % exe.split()[0]) - return - - # pylint: disable-msg = W0612 - status, shout, sherr = sosGetCommandOutput(exe) - + def makeCommandFilename(self, exe): + """ The internal function to build up a filename based on a command """ # build file name for output rawcmd = os.path.basename(exe).strip()[:28] @@ -317,6 +308,22 @@ class PluginBase: while os.path.exists(outfn): outfn = outfn + "z" + return outfn + + def collectOutputNow(self, exe): + """ Execute a command and save the output to a file for inclusion in + the report + """ + # First check to make sure the binary exists and is runnable. + if not os.access(exe.split()[0], os.X_OK): + self.cInfo['soslog'](logging.VERBOSE2, "Binary '%s' does not exist or is not runnable" % exe.split()[0]) + return + + # pylint: disable-msg = W0612 + status, shout, sherr = sosGetCommandOutput(exe) + + outfn = self.makeCommandFilename(exe) + outfd = open(outfn, "w") outfd.write(shout) outfd.close() @@ -325,6 +332,21 @@ class PluginBase: # save info for later self.executedCommands.append({'exe': exe, 'file':outfn}) # save in our list return outfn + + def writeTextToCommand(self, exe, text): + """ A function that allows you to write a random text string to the + command output location referenced by exe; this is useful if you want + to conditionally collect information, but still want the output file + to exist so as not to confuse readers """ + + outfn = self.makeCommandFilename(exe) + + outfd = open(outfn, "w") + outfd.write(text) + outfd.close() + + self.executedCommands.append({'exe': exe, 'file': outfn}) # save in our list + return outfn # For adding output def addAlert(self, alertstring): |