diff options
-rw-r--r-- | sos/archive.py | 6 | ||||
-rw-r--r-- | sos/plugins/__init__.py | 11 | ||||
-rw-r--r-- | sos/reporting.py | 1 | ||||
-rw-r--r-- | sos/sosreport.py | 49 | ||||
-rw-r--r-- | sos/utilities.py | 15 |
5 files changed, 23 insertions, 59 deletions
diff --git a/sos/archive.py b/sos/archive.py index c38e5f64..04b9ff43 100644 --- a/sos/archive.py +++ b/sos/archive.py @@ -37,7 +37,9 @@ import six if six.PY3: long = int + class Archive(object): + """Abstract base class for archives.""" @classmethod def archive_type(class_): @@ -111,6 +113,8 @@ class Archive(object): class FileCacheArchive(Archive): + """ Abstract superclass for archive types that use a temporary cache + directory in the file system. """ _tmp_dir = "" _archive_root = "" @@ -221,6 +225,7 @@ class FileCacheArchive(Archive): class TarFileArchive(FileCacheArchive): + """ archive class using python TarFile to create tar archives""" method = None _with_selinux_context = False @@ -308,6 +313,7 @@ class TarFileArchive(FileCacheArchive): class ZipFileArchive(Archive): + """ archive class using python ZipFile to create zip archives """ def __init__(self, name): self._name = name diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 97c28140..f65c19fc 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -16,13 +16,6 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# pylint: disable-msg = R0902 -# pylint: disable-msg = R0904 -# pylint: disable-msg = W0702 -# pylint: disable-msg = W0703 -# pylint: disable-msg = R0201 -# pylint: disable-msg = W0611 -# pylint: disable-msg = W0613 from __future__ import with_statement from sos.utilities import sos_get_command_output, import_module, grep, fileobj, tail @@ -298,8 +291,6 @@ class Plugin(object): # Methods for copying files and shelling out def do_copy_path(self, srcpath, dest=None): - # pylint: disable-msg = R0912 - # pylint: disable-msg = R0915 '''Copy file or directory to the destination tree. If a directory, then everything below it is recursively copied. A list of copied files are saved for use later in preparing a report. @@ -472,7 +463,6 @@ class Plugin(object): """Execute a command independantly of the output gathering part of sosreport. """ - # pylint: disable-msg = W0612 return self.get_command_output(prog, timeout=timeout, runat=runat) def check_ext_prog(self, prog): @@ -552,7 +542,6 @@ class Plugin(object): report. """ start = time() - # pylint: disable-msg = W0612 result = self.get_command_output(exe, timeout=timeout, runat=runat) if (result['status'] == 127): return None diff --git a/sos/reporting.py b/sos/reporting.py index 039a75fc..809af705 100644 --- a/sos/reporting.py +++ b/sos/reporting.py @@ -16,6 +16,7 @@ class Node(object): def can_add(self, node): return False + class Leaf(Node): """Marker class that can be added to a Section node""" pass diff --git a/sos/sosreport.py b/sos/sosreport.py index 354c147e..bf3d5d5c 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -21,17 +21,6 @@ supplied for application-specific information ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# pylint: disable-msg = W0611 -# pylint: disable-msg = W0702 -# pylint: disable-msg = R0912 -# pylint: disable-msg = R0914 -# pylint: disable-msg = R0915 -# pylint: disable-msg = R0913 -# pylint: disable-msg = E0611 -# pylint: disable-msg = E1101 -# pylint: disable-msg = R0904 -# pylint: disable-msg = R0903 - import sys import traceback import os @@ -61,6 +50,9 @@ else: from ConfigParser import ConfigParser from six import print_ +# file system errors that should terminate a run +fatal_fs_errors = (errno.ENOSPC, errno.EROFS) + class TempFileUtil(object): @@ -103,6 +95,7 @@ class OptionParserExtended(OptionParser): print_( " # sosreport -n memory,samba -k rpm.rpmva=off") print_() + class SosOption(Option): """Allow to specify comma delimited list of plugins""" ACTIONS = Option.ACTIONS + ("extend",) @@ -122,9 +115,9 @@ class SosOption(Option): Option.take_action(self, action, dest, opt, value, values, parser) - class XmlReport(object): """ Report build class """ + def __init__(self): try: import libxml2 @@ -204,6 +197,7 @@ class XmlReport(object): self.archive.add_file(outf.name, dest=fname) outf.close() + class SoSOptions(object): _list_plugins = False _noplugins = [] @@ -230,12 +224,12 @@ class SoSOptions(object): self._options = self._parse_args(args) else: self._options = None - + def _check_options_initialized(self): if self._options != None: raise ValueError("SoSOptions object already initialized " + "from command line") - + @property def list_plugins(self): if self._options != None: @@ -359,7 +353,7 @@ class SoSOptions(object): if not isinstance(value, bool): raise TypeError("SoSOptions.quiet expects a boolean") self._quiet = value - + @property def debug(self): if self._options != None: @@ -441,7 +435,6 @@ class SoSOptions(object): self._check_options_initialized() self._compression_type = value - def _parse_args(self, args): """ Parse command line options and arguments""" @@ -501,10 +494,9 @@ class SoSOptions(object): return parser.parse_args(args)[0] -# file system errors that should terminate a run -fatal_fs_errors = (errno.ENOSPC, errno.EROFS) class SoSReport(object): + """The main sosreport class""" def __init__(self, args): self.loaded_plugins = deque() @@ -521,16 +513,17 @@ class SoSReport(object): except Exception: pass # not available in java, but we don't care - - #self.opts = self.parse_options(args)[0] self.opts = SoSOptions(args) self._set_debug() self._read_config() + try: self.policy = sos.policies.load() except KeyboardInterrupt: self._exit(0) + self._is_root = self.policy.is_root() + self.tmpdir = os.path.abspath( self.policy.get_tmp_dir(self.opts.tmp_dir)) if not os.path.isdir(self.tmpdir) \ @@ -720,7 +713,6 @@ class SoSReport(object): plugin_class(self.get_commons()) )) - def load_plugins(self): import sos.plugins @@ -961,7 +953,6 @@ class SoSReport(object): versions.append("%s: %s" % (plugname, plug.version)) self.archive.add_string(content="\n".join(versions), dest='version.txt') - def collect(self): self.ui_log.info(_(" Running plugins. Please wait ...")) self.ui_log.info("") @@ -997,7 +988,6 @@ class SoSReport(object): self._log_plugin_exception(plugname) self.ui_log.info("") - def report(self): for plugname, plug in self.loaded_plugins: for oneFile in plug.copied_files: @@ -1005,7 +995,6 @@ class SoSReport(object): self.xml_report.add_file(oneFile["srcpath"], os.stat(oneFile["srcpath"])) except: pass - try: self.xml_report.serialize_to_file(os.path.join(self.rptdir, "sosreport.xml")) except (OSError, IOError) as e: @@ -1016,7 +1005,6 @@ class SoSReport(object): self.ui_log.error("") self._exit(1) - def plain_report(self): report = Report() @@ -1080,7 +1068,6 @@ class SoSReport(object): <body> """) - # Make a pass to gather Alerts and a list of module names allAlerts = deque() plugNames = deque() @@ -1110,7 +1097,6 @@ class SoSReport(object): rfd.write('<li>%s</li>' % alert) rfd.write('</ul>') - # Call the report method for each plugin for plugname, plug in self.loaded_plugins: try: @@ -1120,11 +1106,8 @@ class SoSReport(object): raise else: rfd.write(html) - rfd.write("</body></html>") - rfd.flush() - self.archive.add_file(rfd.name, dest=os.path.join('sos_reports', 'sos.html')) def postproc(self): @@ -1164,27 +1147,21 @@ class SoSReport(object): raise else: return False - else: final_filename = self.archive.get_archive_path() - self.policy.display_results(final_filename, build = self.opts.build) self.tempfile_util.clean() - return True - def verify_plugins(self): if not self.loaded_plugins: self.soslog.error(_("no valid plugins were enabled")) return False return True - def set_global_plugin_option(self, key, value): self.global_plugin_options[key] = value; - def execute(self): try: self._setup_logging() diff --git a/sos/utilities.py b/sos/utilities.py index 6e577126..0423dfce 100644 --- a/sos/utilities.py +++ b/sos/utilities.py @@ -12,14 +12,6 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# pylint: disable-msg = R0902 -# pylint: disable-msg = R0904 -# pylint: disable-msg = W0702 -# pylint: disable-msg = W0703 -# pylint: disable-msg = R0201 -# pylint: disable-msg = W0611 -# pylint: disable-msg = W0613 - from __future__ import with_statement import os @@ -51,7 +43,6 @@ def tail(filename, number_of_bytes): f.seek(-number_of_bytes, 2) return f.read() - def fileobj(path_or_file, mode='r'): """Returns a file-like object that can be used as a context manager""" if isinstance(path_or_file, six.string_types): @@ -109,7 +100,6 @@ def find(file_pattern, top_dir, max_depth=None, path_pattern=None): for name in fnmatch.filter(filelist, file_pattern): yield os.path.join(path, name) - def grep(pattern, *files_or_paths): """Returns lines matched in fnames, where fnames can either be pathnames to files to grep through or open file objects to grep through line by line""" @@ -137,7 +127,7 @@ def sos_get_command_output(command, timeout=300, runat=None): os.chdir(runat) except: self.log_error("failed to chdir to '%s'" % runat) - + cmd_env = os.environ # ensure consistent locale for collected command output cmd_env['LC_ALL'] = 'C' @@ -162,7 +152,7 @@ def sos_get_command_output(command, timeout=300, runat=None): # call with shell=False for a non-existant binary will raise OSError. if p.returncode == 127: stdout = six.binary_type(b"") - + return {'status': p.returncode, 'output': stdout.decode('utf-8')} def import_module(module_fqname, superclasses=None): @@ -186,6 +176,7 @@ def shell_out(cmd, runat=None): """ return sos_get_command_output(cmd, runat=runat)['output'] + class ImporterHelper(object): """Provides a list of modules that can be imported in a package. Importable modules are located along the module __path__ list and modules |