diff options
author | Adam Stokes <adam.stokes@ubuntu.com> | 2014-08-02 01:28:28 -0400 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2014-08-02 19:53:26 +0100 |
commit | 0a8a59a0c4983dfa35ba26c0b98a1f0d545214f9 (patch) | |
tree | a49f72ab34c1a6e1cf9f15cdf025029e6179742b | |
parent | 8014c192f77562eaeed5c1e1da1ecf529964fade (diff) | |
download | sos-0a8a59a0c4983dfa35ba26c0b98a1f0d545214f9.tar.gz |
[policies] pep8 compliance
Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
-rw-r--r-- | sos/policies/__init__.py | 70 | ||||
-rw-r--r-- | sos/policies/debian.py | 9 | ||||
-rw-r--r-- | sos/policies/osx.py | 5 | ||||
-rw-r--r-- | sos/policies/redhat.py | 44 | ||||
-rw-r--r-- | sos/policies/ubuntu.py | 5 |
5 files changed, 76 insertions, 57 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 9d01323b..5262785a 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -5,14 +5,13 @@ import re import platform import time import fnmatch -import sys import tempfile from os import environ -from sos.utilities import ImporterHelper, \ - import_module, \ - get_hash_name, \ - shell_out +from sos.utilities import (ImporterHelper, + import_module, + get_hash_name, + shell_out) from sos.plugins import IndependentPlugin from sos import _sos as _ import hashlib @@ -20,6 +19,7 @@ from textwrap import fill from six import print_ from six.moves import input + def import_policy(name): policy_fqname = "sos.policies.%s" % name try: @@ -27,6 +27,7 @@ def import_policy(name): except ImportError: return None + def load(cache={}): if 'policy' in cache: return cache.get('policy') @@ -87,7 +88,8 @@ class PackageManager(object): def get_pkg_list(self): """ returns a dictionary of packages in the following format: - {'package_name': {'name': 'package_name', 'version': 'major.minor.version'}} + {'package_name': {'name': 'package_name', ' + version': 'major.minor.version'}} """ if self.query_command: pkg_list = shell_out(self.query_command).splitlines() @@ -165,9 +167,10 @@ No changes will be made to system configuration. del self._valid_subclasses valid_subclasses = property(get_valid_subclasses, - set_valid_subclasses, - del_valid_subclasses, - "list of subclasses that this policy can process") + set_valid_subclasses, + del_valid_subclasses, + "list of subclasses that this policy can " + "process") def check(self): """ @@ -178,7 +181,8 @@ No changes will be made to system configuration. def get_preferred_archive(self): """ - Return the class object of the prefered archive format for this platform + Return the class object of the prefered archive format for this + platform """ from sos.archive import TarFileArchive return TarFileArchive @@ -190,7 +194,8 @@ No changes will be made to system configuration. """ if self.ticket_number: self.report_name += "." + self.ticket_number - return "sosreport-%s-%s" % (self.report_name, time.strftime("%Y%m%d%H%M%S")) + return "sosreport-%s-%s" % (self.report_name, + time.strftime("%Y%m%d%H%M%S")) def get_tmp_dir(self, opt_tmp_dir): if not opt_tmp_dir: @@ -212,7 +217,8 @@ No changes will be made to system configuration. Verifies that the plugin_class should execute under this policy """ valid_subclasses = [IndependentPlugin] + self.valid_subclasses - return any(issubclass(plugin_class, class_) for class_ in valid_subclasses) + return any(issubclass(plugin_class, class_) for + class_ in valid_subclasses) def pre_work(self): """ @@ -246,7 +252,7 @@ No changes will be made to system configuration. def set_exec_path(self): self._set_PATH(self.PATH) - + def is_root(self): """This method should return true if the user calling the script is considered to be a superuser""" @@ -271,7 +277,7 @@ No changes will be made to system configuration. # make sure a report exists if not final_filename: - return False + return False self._print() @@ -283,19 +289,21 @@ No changes will be made to system configuration. fp.write(checksum + "\n") fp.close() - self._print(_("Your sosreport has been generated and saved in:\n %s") % final_filename) + self._print(_("Your sosreport has been generated and saved " + "in:\n %s") % final_filename) else: checksum = None - self._print(_("sosreport build tree is located at : %s" % final_filename)) + self._print(_("sosreport build tree is located at : %s" % + final_filename)) self._print() if checksum: self._print(_("The checksum is: ") + checksum) self._print() - self._print(_("Please send this file to your support representative.")) + self._print(_("Please send this file to your support " + "representative.")) self._print() - def _print(self, msg=None): """A wrapper around print that only prints if we are not running in quiet mode""" @@ -305,7 +313,6 @@ No changes will be made to system configuration. else: print_() - def get_msg(self): """This method is used to prepare the preamble text to display to the user in non-batch mode. If your policy sets self.distro that @@ -313,12 +320,12 @@ No changes will be made to system configuration. method to do something more complicated.""" width = 72 _msg = self.msg % {'distro': self.distro, 'vendor': self.vendor, - 'vendor_url': self.vendor_url, - 'vendor_text': self.vendor_text, - 'tmpdir': self.commons['tmpdir']} + 'vendor_url': self.vendor_url, + 'vendor_text': self.vendor_text, + 'tmpdir': self.commons['tmpdir']} _fmt = "" for line in _msg.splitlines(): - _fmt = _fmt + fill(line, width, replace_whitespace = False) + '\n' + _fmt = _fmt + fill(line, width, replace_whitespace=False) + '\n' return _fmt @@ -331,8 +338,8 @@ class GenericPolicy(Policy): class LinuxPolicy(Policy): - """This policy is meant to be an abc class that provides common implementations used - in Linux distros""" + """This policy is meant to be an abc class that provides common + implementations used in Linux distros""" distro = "Linux" vendor = "None" @@ -390,11 +397,15 @@ class LinuxPolicy(Policy): localname = self.get_local_name() - if not self.commons['cmdlineopts'].batch and not self.commons['cmdlineopts'].quiet: + if not self.commons['cmdlineopts'].batch and not \ + self.commons['cmdlineopts'].quiet: try: - self.report_name = input(_("Please enter your first initial and last name [%s]: ") % localname) + self.report_name = input(_("Please enter your first initial " + "and last name [%s]: ") % localname) - self.ticket_number = input(_("Please enter the case number that you are generating this report for: ")) + self.ticket_number = input(_("Please enter the case number " + "that you are generating this " + "report for: ")) self._print() except: self._print() @@ -411,7 +422,8 @@ class LinuxPolicy(Policy): self.report_name = self.sanitize_report_name(self.report_name) if self.ticket_number: - self.ticket_number = self.sanitize_ticket_number(self.ticket_number) + self.ticket_number = self.sanitize_ticket_number( + self.ticket_number) if (self.report_name == ""): self.report_name = "default" diff --git a/sos/policies/debian.py b/sos/policies/debian.py index 80bbc881..a2834f7e 100644 --- a/sos/policies/debian.py +++ b/sos/policies/debian.py @@ -3,22 +3,25 @@ from sos.policies import PackageManager, LinuxPolicy import os + class DebianPolicy(LinuxPolicy): distro = "Debian" vendor = "the Debian project" vendor_url = "http://www.debian.org/" report_name = "" ticket_number = "" - package_manager = PackageManager("dpkg-query -W -f='${Package}|${Version}\\n' \*") + package_manager = PackageManager( + "dpkg-query -W -f='${Package}|${Version}\\n' \*") valid_subclasses = [DebianPlugin] PATH = "/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" \ - + ":/usr/local/sbin:/usr/local/bin" + + ":/usr/local/sbin:/usr/local/bin" def __init__(self): super(DebianPolicy, self).__init__() self.report_name = "" self.ticket_number = "" - self.package_manager = PackageManager("dpkg-query -W -f='${Package}|${Version}\\n' \*") + self.package_manager = PackageManager( + "dpkg-query -W -f='${Package}|${Version}\\n' \*") self.valid_subclasses = [DebianPlugin] @classmethod diff --git a/sos/policies/osx.py b/sos/policies/osx.py index 2e3c5aca..adbeea4f 100644 --- a/sos/policies/osx.py +++ b/sos/policies/osx.py @@ -1,6 +1,7 @@ -from sos.policies import PackageManager, Policy +from sos.policies import Policy from sos.utilities import shell_out + class OSXPolicy(Policy): distro = "Mac OS X" @@ -9,7 +10,7 @@ class OSXPolicy(Policy): def check(class_): try: return "Mac OS X" in shell_out("sw_vers") - except Exception as e: + except Exception: return False # vim: et ts=4 sw=4 diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index 6959e205..fa26a855 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -1,18 +1,18 @@ -## Copyright (C) Steve Conklin <sconklin@redhat.com> +# Copyright (C) Steve Conklin <sconklin@redhat.com> -### This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # This enables the use of with syntax in python 2.5 (e.g. jython) import os @@ -31,6 +31,7 @@ except: # might fail if non-RHEL pass + class RedHatPolicy(LinuxPolicy): distro = "Red Hat" vendor = "Red Hat" @@ -42,7 +43,7 @@ class RedHatPolicy(LinuxPolicy): self.report_name = "" self.ticket_number = "" self.package_manager = PackageManager( - 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"') + 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"') self.valid_subclasses = [RedHatPlugin] # handle PATH for UsrMove @@ -91,6 +92,7 @@ class RedHatPolicy(LinuxPolicy): def get_local_name(self): return self.host_name() + class RHELPolicy(RedHatPolicy): distro = "Red Hat Enterprise Linux" vendor = "Red Hat" @@ -129,11 +131,11 @@ No changes will be made to system configuration. def rhel_version(self): try: pkg = self.pkg_by_name("redhat-release") or \ - self.all_pkgs_by_name_regex("redhat-release-.*")[-1] + self.all_pkgs_by_name_regex("redhat-release-.*")[-1] pkgname = pkg["version"] if pkgname[0] == "4": return 4 - elif pkgname[0] in [ "5Server", "5Client" ]: + elif pkgname[0] in ["5Server", "5Client"]: return 5 elif pkgname[0] == "6": return 6 @@ -145,9 +147,10 @@ No changes will be made to system configuration. def rhn_username(self): try: - cfg = config.initUp2dateConfig() + # cfg = config.initUp2dateConfig() - return rpclib.xmlrpclib.loads(up2dateAuth.getSystemId())[0][0]['username'] + return rpclib.xmlrpclib.loads( + up2dateAuth.getSystemId())[0][0]['username'] except: # ignore any exception and return an empty username return "" @@ -155,6 +158,7 @@ No changes will be made to system configuration. def get_local_name(self): return self.rhn_username() or self.host_name() + class FedoraPolicy(RedHatPolicy): distro = "Fedora" @@ -166,13 +170,13 @@ class FedoraPolicy(RedHatPolicy): @classmethod def check(self): - """This method checks to see if we are running on Fedora. It returns True - or False.""" + """This method checks to see if we are running on Fedora. It returns + True or False.""" return os.path.isfile('/etc/fedora-release') def fedora_version(self): pkg = self.pkg_by_name("fedora-release") or \ - self.all_pkgs_by_name_regex("fedora-release-.*")[-1] + self.all_pkgs_by_name_regex("fedora-release-.*")[-1] return int(pkg["version"]) diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py index cc83f921..4436df18 100644 --- a/sos/policies/ubuntu.py +++ b/sos/policies/ubuntu.py @@ -1,10 +1,9 @@ from __future__ import with_statement -import os - -from sos.plugins import UbuntuPlugin, DebianPlugin, IndependentPlugin +from sos.plugins import UbuntuPlugin, DebianPlugin from sos.policies.debian import DebianPolicy + class UbuntuPolicy(DebianPolicy): distro = "Ubuntu" vendor = "Ubuntu" |