aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2018-06-11 14:39:17 -0400
committerBryn M. Reeves <bmr@redhat.com>2018-06-20 16:28:42 +0100
commitd8b6793fd81cf4b7391f038d40616494ff10f624 (patch)
tree09e7fe12c0e312193b07ffdf746ba3dadbc2aee2
parentbba78dd1a0b45896848e36ec375f7dc78bd4eeb3 (diff)
downloadsos-d8b6793fd81cf4b7391f038d40616494ff10f624.tar.gz
[global] Transition to pycodestyle
The 'pep8' tool has been renamed to 'pycodestyle' to avoid confusion with pep8 the document. pep8 (the tool) will no longer be updated and as such we should transition to the new pycodestyle. This commit fixes a number of PEP8 issues with the new pycodestyle linter that has tests for new additions to PEP8 that the pep8 tool did not include. Most of these are exception handling fixes like: sos/plugins/logs.py:96:13: E722 do not use bare 'except' Which are relatively straight forward to address, by instead catching just the applicable exceptions, e.g. IOError, ValueError, etc... In cases where there were many possible exceptions or where the "bare 'except'" was a final catch-all, we now use 'except Exception' to catch anything from the base exception class. Another frequent correction was for escape sequencing, such as: sos/plugins/logs.py:48:15: W605 invalid escape sequence '\S' The solution for this is to mark these regex strings as raw strings, which is preferred by `re` as future releases of that module may/will become more strict in its parsing of regex strings. Resolves: #1344 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--.travis.yml2
-rw-r--r--requirements.txt2
-rw-r--r--sos/__init__.py1
-rw-r--r--sos/archive.py2
-rw-r--r--sos/plugins/__init__.py4
-rw-r--r--sos/plugins/cman.py2
-rw-r--r--sos/plugins/corosync.py2
-rw-r--r--sos/plugins/dnf.py2
-rw-r--r--sos/plugins/ds.py2
-rw-r--r--sos/plugins/etcd.py4
-rw-r--r--sos/plugins/gluster.py4
-rw-r--r--sos/plugins/haproxy.py6
-rw-r--r--sos/plugins/infiniband.py4
-rw-r--r--sos/plugins/iprconfig.py2
-rw-r--r--sos/plugins/kpatch.py2
-rw-r--r--sos/plugins/libvirt.py6
-rw-r--r--sos/plugins/logs.py4
-rw-r--r--sos/plugins/named.py2
-rw-r--r--sos/plugins/navicli.py2
-rw-r--r--sos/plugins/networking.py10
-rw-r--r--sos/plugins/nfsserver.py2
-rw-r--r--sos/plugins/openstack_horizon.py4
-rw-r--r--sos/plugins/openstack_swift.py4
-rw-r--r--sos/plugins/ovirt.py4
-rw-r--r--sos/plugins/ovn_central.py2
-rw-r--r--sos/plugins/pacemaker.py2
-rw-r--r--sos/plugins/pcp.py6
-rw-r--r--sos/plugins/powerpc.py2
-rw-r--r--sos/plugins/rpm.py2
-rw-r--r--sos/plugins/sapnw.py2
-rw-r--r--sos/plugins/sar.py2
-rw-r--r--sos/policies/__init__.py4
-rw-r--r--sos/policies/debian.py2
-rw-r--r--sos/policies/ibmkvm.py4
-rw-r--r--sos/policies/redhat.py11
-rw-r--r--sos/policies/suse.py2
-rw-r--r--sos/policies/ubuntu.py4
-rw-r--r--sos/sosreport.py24
-rw-r--r--sos/utilities.py2
39 files changed, 76 insertions, 74 deletions
diff --git a/.travis.yml b/.travis.yml
index ae242849..90adba23 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,7 +22,7 @@ install:
- "pip install -r requirements.txt"
- "python setup.py install"
script:
- - "pep8 sos"
+ - "pycodestyle sos"
- "nosetests -v --with-cover --cover-package=sos --cover-html"
- "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport --help"
- "sudo ~/virtualenv/python$TRAVIS_PYTHON_VERSION/bin/python ./sosreport -l --config-file=sos.conf"
diff --git a/requirements.txt b/requirements.txt
index 6888f3fd..236189eb 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-pep8>=1.7.0
+pycodestyle>=2.4.0
nose>=1.3.7
coverage>=4.0.3
Sphinx>=1.3.5
diff --git a/sos/__init__.py b/sos/__init__.py
index 8b3641f6..7d0f92b5 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -28,4 +28,5 @@ gettext.bindtextdomain(gettext_app, gettext_dir)
def _default(msg):
return gettext.dgettext(gettext_app, msg)
+
_sos = _default
diff --git a/sos/archive.py b/sos/archive.py
index d631b6c0..d53baf41 100644
--- a/sos/archive.py
+++ b/sos/archive.py
@@ -499,7 +499,7 @@ class TarFileArchive(FileCacheArchive):
try:
(rc, c) = selinux.getfilecon(path)
return c
- except:
+ except Exception:
return None
def name(self):
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 03b060db..3f434353 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -96,7 +96,7 @@ class Plugin(object):
this and set the class variables where applicable.
plugin_name is a string returned by plugin.name(). If this is set to None
- (the default) class\_.__name__.tolower() will be returned. Be sure to set
+ (the default) class\\_.__name__.tolower() will be returned. Be sure to set
this if you are defining multiple plugins that do the same thing on
different platforms.
@@ -949,7 +949,7 @@ class Plugin(object):
if hasattr(self, '__doc__') and self.__doc__:
return self.__doc__.strip()
return super(self.__class__, self).__doc__.strip()
- except:
+ except Exception:
return "<no description available>"
def check_enabled(self):
diff --git a/sos/plugins/cman.py b/sos/plugins/cman.py
index a359756e..d5f65166 100644
--- a/sos/plugins/cman.py
+++ b/sos/plugins/cman.py
@@ -65,7 +65,7 @@ class Cman(Plugin, RedHatPlugin):
)
self.do_path_regex_sub(
- "/var/lib/luci/etc/.*\.ini",
+ r"/var/lib/luci/etc/.*\.ini",
r"(.*secret\s*=\s*)\S+",
r"\1******"
)
diff --git a/sos/plugins/corosync.py b/sos/plugins/corosync.py
index 8a415755..174e8936 100644
--- a/sos/plugins/corosync.py
+++ b/sos/plugins/corosync.py
@@ -45,7 +45,7 @@ class Corosync(Plugin):
# or
# logging.log_size: filename
# (it isnt precise but sufficient)
- pattern = '^\s*(logging.)?logfile:\s*(\S+)$'
+ pattern = r'^\s*(logging.)?logfile:\s*(\S+)$'
try:
with open("/etc/corosync/corosync.conf") as f:
for line in f:
diff --git a/sos/plugins/dnf.py b/sos/plugins/dnf.py
index 570bfb7d..0bcbf0c4 100644
--- a/sos/plugins/dnf.py
+++ b/sos/plugins/dnf.py
@@ -28,7 +28,7 @@ class DNFPlugin(Plugin, RedHatPlugin):
if module_file:
try:
module_out = open(module_file).read()
- except:
+ except IOError:
self._log_warn("could not read module list file")
return
# take just lines with the module names, i.e. containing "[i]" and
diff --git a/sos/plugins/ds.py b/sos/plugins/ds.py
index b2786323..70507c4f 100644
--- a/sos/plugins/ds.py
+++ b/sos/plugins/ds.py
@@ -48,7 +48,7 @@ class DirectoryServer(Plugin, RedHatPlugin):
if d[0:5] == 'slapd':
certpath = os.path.join("/etc/dirsrv", d)
self.add_cmd_output("certutil -L -d %s" % certpath)
- except:
+ except OSError:
self._log_warn("could not list /etc/dirsrv")
if not self.check_version():
diff --git a/sos/plugins/etcd.py b/sos/plugins/etcd.py
index 27ad4b82..c343f750 100644
--- a/sos/plugins/etcd.py
+++ b/sos/plugins/etcd.py
@@ -55,7 +55,7 @@ class etcd(Plugin, RedHatPlugin):
if line.startswith('ETCD_LISTEN_CLIENT_URLS'):
return line.split('=')[1].replace('"', '').strip()
# If we can't read etcd.conf, assume defaults by etcd version
- except:
+ except IOError:
# assume v3 is the default
url = 'http://localhost:2379'
try:
@@ -63,7 +63,7 @@ class etcd(Plugin, RedHatPlugin):
ver = ver['version'][0]
if ver == '2':
url = 'http://localhost:4001'
- except:
+ except Exception:
# fallback when etcd is not installed
pass
return url
diff --git a/sos/plugins/gluster.py b/sos/plugins/gluster.py
index 9b4d4ddd..30738d95 100644
--- a/sos/plugins/gluster.py
+++ b/sos/plugins/gluster.py
@@ -43,7 +43,7 @@ class Gluster(Plugin, RedHatPlugin):
def make_preparations(self, name_dir):
try:
os.mkdir(name_dir)
- except:
+ except OSError:
pass
fp = open('/tmp/glusterdump.options', 'w')
data = 'path=' + name_dir + '\n'
@@ -71,7 +71,7 @@ class Gluster(Plugin, RedHatPlugin):
os.remove(os.path.join(self.statedump_dir, dirs))
os.rmdir(self.statedump_dir)
os.unlink('/tmp/glusterdump.options')
- except:
+ except OSError:
pass
def setup(self):
diff --git a/sos/plugins/haproxy.py b/sos/plugins/haproxy.py
index 36c8c1c5..4e0c40b5 100644
--- a/sos/plugins/haproxy.py
+++ b/sos/plugins/haproxy.py
@@ -48,8 +48,8 @@ class HAProxy(Plugin, RedHatPlugin, DebianPlugin):
if matched:
provision_ip = line.split()[1]
break
- matched = match(".*haproxy\.stats.*", line)
- except:
+ matched = match(r".*haproxy\.stats.*", line)
+ except IOError:
# fallback when the cfg file is not accessible
pass
@@ -60,7 +60,7 @@ class HAProxy(Plugin, RedHatPlugin, DebianPlugin):
if urlparse("http://"+provision_ip).port is None:
provision_ip = provision_ip + ":1993"
- self.add_cmd_output("curl http://"+provision_ip+"/\;csv",
+ self.add_cmd_output("curl http://"+provision_ip+r"/\;csv",
suggest_filename="haproxy_overview.txt")
# vim: set et ts=4 sw=4 :
diff --git a/sos/plugins/infiniband.py b/sos/plugins/infiniband.py
index 5b2864d8..8e74817c 100644
--- a/sos/plugins/infiniband.py
+++ b/sos/plugins/infiniband.py
@@ -60,7 +60,7 @@ class Infiniband(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
try:
p = open(IB_SYS_DIR + ib + "/ports/" + port +
"/link_layer")
- except:
+ except IOError:
continue
link_layer = p.readline()
p.close()
@@ -69,7 +69,7 @@ class Infiniband(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
try:
s = open(IB_SYS_DIR + ib + "/ports/" + port + "/state")
- except:
+ except IOError:
continue
state = s.readline()
s.close()
diff --git a/sos/plugins/iprconfig.py b/sos/plugins/iprconfig.py
index 7e4886ce..11742654 100644
--- a/sos/plugins/iprconfig.py
+++ b/sos/plugins/iprconfig.py
@@ -99,7 +99,7 @@ class IprConfig(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
for line in show_config['output'].splitlines():
if "Enclosure" in line:
- temp = re.split('\s+', line)
+ temp = re.split(r'\s+', line)
# temp[1] holds the PCI/SCSI location
pci, scsi = temp[1].split('/')
for line in altconfig['output'].splitlines():
diff --git a/sos/plugins/kpatch.py b/sos/plugins/kpatch.py
index b14d8d0b..e1d09cb8 100644
--- a/sos/plugins/kpatch.py
+++ b/sos/plugins/kpatch.py
@@ -26,7 +26,7 @@ class Kpatch(Plugin, RedHatPlugin):
return
kpatches = open(kpatch_list, "r").read().splitlines()
for patch in kpatches:
- if not re.match("^kpatch-.*\(.*\)", patch):
+ if not re.match(r"^kpatch-.*\(.*\)", patch):
continue
(module, version) = patch.split()
self.add_cmd_output("kpatch info " + module)
diff --git a/sos/plugins/libvirt.py b/sos/plugins/libvirt.py
index 4601b476..07052af3 100644
--- a/sos/plugins/libvirt.py
+++ b/sos/plugins/libvirt.py
@@ -67,9 +67,9 @@ class Libvirt(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
def postproc(self):
match_exp = r"(\s*passwd=\s*')([^']*)('.*)"
libvirt_path_exps = [
- "/etc/libvirt/qemu/.*\.xml",
- "/var/run/libvirt/qemu/.*\.xml",
- "/etc/libvirt/.*\.conf"
+ r"/etc/libvirt/qemu/.*\.xml",
+ r"/var/run/libvirt/qemu/.*\.xml",
+ r"/etc/libvirt/.*\.conf"
]
for path_exp in libvirt_path_exps:
self.do_path_regex_sub(path_exp, match_exp, r"\1******\3")
diff --git a/sos/plugins/logs.py b/sos/plugins/logs.py
index c67d3e66..56ec7b01 100644
--- a/sos/plugins/logs.py
+++ b/sos/plugins/logs.py
@@ -45,7 +45,7 @@ class Logs(Plugin):
if not os.path.exists(conf):
continue
config = self.join_sysroot(conf)
- logs += self.do_regex_find_all("^\S+\s+(-?\/.*$)\s+", config)
+ logs += self.do_regex_find_all(r"^\S+\s+(-?\/.*$)\s+", config)
for i in logs:
if i.startswith("-"):
@@ -93,7 +93,7 @@ class RedHatLogs(Logs, RedHatPlugin):
if not os.path.exists(messages) and self.is_installed("systemd"):
try:
days = int(self.get_option("log_days"))
- except:
+ except ValueError:
days = 3
if self.get_option("all_logs"):
since = ""
diff --git a/sos/plugins/named.py b/sos/plugins/named.py
index 143a59d6..8a47a872 100644
--- a/sos/plugins/named.py
+++ b/sos/plugins/named.py
@@ -34,7 +34,7 @@ class Named(Plugin):
def get_dns_dir(self, config_file):
""" grab directory path from named{conf,boot}
"""
- directory_list = self.do_regex_find_all("directory\s+\"(.*)\"",
+ directory_list = self.do_regex_find_all(r"directory\s+\"(.*)\"",
config_file)
if directory_list:
return normpath(directory_list[0])
diff --git a/sos/plugins/navicli.py b/sos/plugins/navicli.py
index 5794212e..965dbd1f 100644
--- a/sos/plugins/navicli.py
+++ b/sos/plugins/navicli.py
@@ -66,7 +66,7 @@ class Navicli(Plugin, RedHatPlugin):
while CLARiiON_IP_loop == "stay_in":
try:
ans = input("CLARiiON SP IP Address or [Enter] to exit: ")
- except:
+ except Exception:
return
if self.check_ext_prog("navicli -h %s getsptime" % (ans,)):
CLARiiON_IP_address_list.append(ans)
diff --git a/sos/plugins/networking.py b/sos/plugins/networking.py
index ad3bcd22..fa3d0cda 100644
--- a/sos/plugins/networking.py
+++ b/sos/plugins/networking.py
@@ -32,7 +32,7 @@ class Networking(Plugin):
out = []
try:
brctl_out = open(brctl_file).read()
- except:
+ except IOError:
return out
for line in brctl_out.splitlines():
if line.startswith("bridge name") \
@@ -62,7 +62,7 @@ class Networking(Plugin):
out = []
try:
ip_netns_out = open(ip_netns_file).read()
- except:
+ except IOError:
return out
for line in ip_netns_out.splitlines():
# If there's no namespaces, no need to continue
@@ -152,14 +152,14 @@ class Networking(Plugin):
# tables, collect 3 default ones (nat, mangle, filter)
try:
ip_tables_names = open("/proc/net/ip_tables_names").read()
- except:
+ except IOError:
ip_tables_names = "nat\nmangle\nfilter\n"
for table in ip_tables_names.splitlines():
self.collect_iptable(table)
# collect the same for ip6tables
try:
ip_tables_names = open("/proc/net/ip6_tables_names").read()
- except:
+ except IOError:
ip_tables_names = "nat\nmangle\nfilter\n"
for table in ip_tables_names.splitlines():
self.collect_ip6table(table)
@@ -273,7 +273,7 @@ class RedHatNetworking(Networking, RedHatPlugin):
# major version
if int(netstat_pkg['version'][0]) < 2:
self.ns_wide = "-T"
- except:
+ except Exception:
# default to upstream option
pass
diff --git a/sos/plugins/nfsserver.py b/sos/plugins/nfsserver.py
index 63191a13..3ee08cd4 100644
--- a/sos/plugins/nfsserver.py
+++ b/sos/plugins/nfsserver.py
@@ -31,7 +31,7 @@ class NfsServer(Plugin, RedHatPlugin):
xtab = os.stat("/var/lib/nfs/xtab")[ST_SIZE]
if exports or xtab:
return True
- except:
+ except OSError:
pass
return False
diff --git a/sos/plugins/openstack_horizon.py b/sos/plugins/openstack_horizon.py
index 6e090135..725e7021 100644
--- a/sos/plugins/openstack_horizon.py
+++ b/sos/plugins/openstack_horizon.py
@@ -60,11 +60,11 @@ class OpenStackHorizon(Plugin):
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
self.do_path_regex_sub(
- "/etc/openstack-dashboard/.*\.json",
+ r"/etc/openstack-dashboard/.*\.json",
regexp, r"\1*********"
)
self.do_path_regex_sub(
- var_puppet_gen + "/etc/openstack-dashboard/.*\.json",
+ var_puppet_gen + r"/etc/openstack-dashboard/.*\.json",
regexp, r"\1*********"
)
self.do_path_regex_sub(
diff --git a/sos/plugins/openstack_swift.py b/sos/plugins/openstack_swift.py
index 5f99b997..c396227d 100644
--- a/sos/plugins/openstack_swift.py
+++ b/sos/plugins/openstack_swift.py
@@ -51,9 +51,9 @@ class OpenStackSwift(Plugin):
self.add_cmd_output("rpm -V %s" % ' '.join(self.packages))
def apply_regex_sub(self, regexp, subst):
- self.do_path_regex_sub("/etc/swift/.*\.conf.*", regexp, subst)
+ self.do_path_regex_sub(r"/etc/swift/.*\.conf.*", regexp, subst)
self.do_path_regex_sub(
- self.var_puppet_gen + "/swift/etc/swift/.*\.conf.*",
+ self.var_puppet_gen + r"/swift/etc/swift/.*\.conf.*",
regexp, subst
)
diff --git a/sos/plugins/ovirt.py b/sos/plugins/ovirt.py
index d644ea47..ea01fd07 100644
--- a/sos/plugins/ovirt.py
+++ b/sos/plugins/ovirt.py
@@ -62,7 +62,7 @@ class Ovirt(Plugin, RedHatPlugin):
def setup(self):
if self.get_option('jbosstrace') and self.is_installed('ovirt-engine'):
- engine_pattern = "^ovirt-engine\ -server.*jboss-modules.jar"
+ engine_pattern = r"^ovirt-engine\ -server.*jboss-modules.jar"
pgrep = "pgrep -f '%s'" % engine_pattern
lines = self.call_ext_prog(pgrep)['output'].splitlines()
engine_pids = [int(x) for x in lines]
@@ -214,7 +214,7 @@ class Ovirt(Plugin, RedHatPlugin):
]
regexp = r"((?m)^\s*#*(%s)\s*=\s*)(.*)" % "|".join(protect_keys)
- self.do_path_regex_sub("/etc/ovirt-engine/aaa/.*\.properties", regexp,
+ self.do_path_regex_sub(r"/etc/ovirt-engine/aaa/.*\.properties", regexp,
r"\1*********")
# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/sos/plugins/ovn_central.py b/sos/plugins/ovn_central.py
index c7d9a4dd..e0585687 100644
--- a/sos/plugins/ovn_central.py
+++ b/sos/plugins/ovn_central.py
@@ -25,7 +25,7 @@ class OVNCentral(Plugin):
with open(filename, 'r') as f:
try:
db = json.load(f)
- except:
+ except Exception:
# If json can't be parsed, then exit early
self._log_error("Cannot parse JSON file %s" % filename)
return
diff --git a/sos/plugins/pacemaker.py b/sos/plugins/pacemaker.py
index 8c508870..59305bbf 100644
--- a/sos/plugins/pacemaker.py
+++ b/sos/plugins/pacemaker.py
@@ -111,7 +111,7 @@ class Pacemaker(Plugin):
# collect user-defined logfiles, matching a shell-style syntax:
# PCMK_logfile=filename
# specified in the pacemaker start-up environment file.
- pattern = '^\s*PCMK_logfile=[\'\"]?(\S+)[\'\"]?\s*(\s#.*)?$'
+ pattern = r'^\s*PCMK_logfile=[\'\"]?(\S+)[\'\"]?\s*(\s#.*)?$'
if os.path.isfile(self.envfile):
self.add_copy_spec(self.envfile)
with open(self.envfile) as f:
diff --git a/sos/plugins/pcp.py b/sos/plugins/pcp.py
index d30603fb..5ad55a09 100644
--- a/sos/plugins/pcp.py
+++ b/sos/plugins/pcp.py
@@ -48,7 +48,7 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):
pcpconf = open(self.pcp_conffile, "r")
lines = pcpconf.readlines()
pcpconf.close()
- except:
+ except IOError:
return False
env_vars = {}
for line in lines:
@@ -57,14 +57,14 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):
try:
(key, value) = line.strip().split('=')
env_vars[key] = value
- except:
+ except (ValueError, KeyError):
pass
try:
self.pcp_sysconf_dir = env_vars['PCP_SYSCONF_DIR']
self.pcp_var_dir = env_vars['PCP_VAR_DIR']
self.pcp_log_dir = env_vars['PCP_LOG_DIR']
- except:
+ except Exception:
# Fail if all three env variables are not found
return False
diff --git a/sos/plugins/powerpc.py b/sos/plugins/powerpc.py
index f5ab1c6a..94137568 100644
--- a/sos/plugins/powerpc.py
+++ b/sos/plugins/powerpc.py
@@ -29,7 +29,7 @@ class PowerPC(Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin):
contents = fp.read()
ispSeries = "pSeries" in contents
isPowerNV = "PowerNV" in contents
- except:
+ except IOError:
ispSeries = False
isPowerNV = False
diff --git a/sos/plugins/rpm.py b/sos/plugins/rpm.py
index 8eb19225..f26c4b11 100644
--- a/sos/plugins/rpm.py
+++ b/sos/plugins/rpm.py
@@ -40,7 +40,7 @@ class Rpm(Plugin, RedHatPlugin):
query_fmt = query_fmt + '%{INSTALLTIME:date}\n"'
filter_cmd = 'awk -F "~~" ' \
- '"{printf \\"%-59s %s\\n\\",\$1,\$2}"|sort -V'
+ r'"{printf \\"%-59s %s\\n\\",\$1,\$2}"|sort -V'
add_rpm_cmd(query_fmt, filter_cmd, "installed-rpms", None)
diff --git a/sos/plugins/sapnw.py b/sos/plugins/sapnw.py
index 371b935d..57363118 100644
--- a/sos/plugins/sapnw.py
+++ b/sos/plugins/sapnw.py
@@ -13,7 +13,7 @@ from sos.plugins import Plugin, RedHatPlugin
def get_directory_listing(path):
try:
dir_list = os.listdir(path)
- except:
+ except OSError:
dir_list = []
return dir_list
diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py
index cf456a4d..492c38a2 100644
--- a/sos/plugins/sar.py
+++ b/sos/plugins/sar.py
@@ -43,7 +43,7 @@ class Sar(Plugin,):
try:
dir_list = os.listdir(self.sa_path)
- except:
+ except OSError:
self._log_warn("sar: could not list %s" % self.sa_path)
return
# find all the sa files that don't have an existing sar file
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 43ac1fc2..4eef8df0 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -497,7 +497,7 @@ class LinuxPolicy(Policy):
checksum = "md5"
try:
fp = open("/proc/sys/crypto/fips_enabled", "r")
- except:
+ except IOError:
self._preferred_hash_name = checksum
return checksum
@@ -514,7 +514,7 @@ class LinuxPolicy(Policy):
pattern = r"id:(\d{1}):initdefault:"
text = fp.read()
return int(re.findall(pattern, text)[0])
- except:
+ except (IndexError, IOError):
return 3
def kernel_version(self):
diff --git a/sos/policies/debian.py b/sos/policies/debian.py
index 358e831b..72864430 100644
--- a/sos/policies/debian.py
+++ b/sos/policies/debian.py
@@ -47,7 +47,7 @@ class DebianPolicy(LinuxPolicy):
elif "jessie/sid" in rel_string:
return 7
return False
- except:
+ except IOError:
return False
# vim: set et ts=4 sw=4 :
diff --git a/sos/policies/ibmkvm.py b/sos/policies/ibmkvm.py
index 8592dffb..e8c55c0d 100644
--- a/sos/policies/ibmkvm.py
+++ b/sos/policies/ibmkvm.py
@@ -39,7 +39,7 @@ class PowerKVMPolicy(RedHatPolicy):
version_string = fp.read()
return version_string[2][0]
return False
- except:
+ except IOError:
return False
@@ -64,7 +64,7 @@ class ZKVMPolicy(RedHatPolicy):
version_string = fp.read()
return version_string.split(' ', 4)[3][0]
return False
- except:
+ except IOError:
return False
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index a6d314f1..91c84d48 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -22,7 +22,7 @@ try:
from up2date_client import up2dateAuth
from up2date_client import config
from rhn import rpclib
-except:
+except ImportError:
# might fail if non-RHEL
pass
@@ -121,7 +121,7 @@ class RedHatPolicy(LinuxPolicy):
for tabs in out.split()[1:]:
try:
(runlevel, onoff) = tabs.split(":", 1)
- except:
+ except IndexError:
pass
else:
if onoff == "on":
@@ -136,6 +136,7 @@ class RedHatPolicy(LinuxPolicy):
def get_local_name(self):
return self.host_name()
+
# Container environment variables on Red Hat systems.
ENV_CONTAINER = 'container'
ENV_HOST_SYSROOT = 'HOST'
@@ -208,7 +209,7 @@ No changes will be made to system configuration.
return 6
elif pkgname[0] == "7":
return 7
- except:
+ except Exception:
pass
return False
@@ -218,7 +219,7 @@ No changes will be made to system configuration.
rhn_username = rpclib.xmlrpclib.loads(
up2dateAuth.getSystemId())[0][0]['username']
return rhn_username.encode('utf-8', 'ignore')
- except:
+ except Exception:
# ignore any exception and return an empty username
return ""
@@ -257,7 +258,7 @@ organization before being passed to any third party.
try:
for line in open(host_release, "r").read().splitlines():
atomic |= 'Atomic' in line
- except:
+ except IOError:
pass
return atomic
diff --git a/sos/policies/suse.py b/sos/policies/suse.py
index 6712c19b..2cd1def8 100644
--- a/sos/policies/suse.py
+++ b/sos/policies/suse.py
@@ -64,7 +64,7 @@ class SuSEPolicy(LinuxPolicy):
for tabs in out.split()[1:]:
try:
(runlevel, onoff) = tabs.split(":", 1)
- except:
+ except IndexError:
pass
else:
if onoff == "on":
diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py
index 6309631e..1165fb7c 100644
--- a/sos/policies/ubuntu.py
+++ b/sos/policies/ubuntu.py
@@ -20,7 +20,7 @@ class UbuntuPolicy(DebianPolicy):
try:
with open('/etc/lsb-release', 'r') as fp:
return "Ubuntu" in fp.read()
- except:
+ except IOError:
return False
def dist_version(self):
@@ -33,7 +33,7 @@ class UbuntuPolicy(DebianPolicy):
if "DISTRIB_RELEASE" in line:
return line.split("=")[1].strip()
return False
- except:
+ except IOError:
return False
# vim: set et ts=4 sw=4 :
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 5dae5cd8..3e1e3ebe 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -1042,7 +1042,7 @@ class SoSReport(object):
# split up "general.syslogsize=5"
try:
opt, val = opt.split("=")
- except:
+ except ValueError:
val = True
else:
if val.lower() in ["off", "disable", "disabled", "false"]:
@@ -1051,13 +1051,13 @@ class SoSReport(object):
# try to convert string "val" to int()
try:
val = int(val)
- except:
+ except ValueError:
pass
# split up "general.syslogsize"
try:
plug, opt = opt.split(".")
- except:
+ except ValueError:
plug = opt
opt = True
@@ -1259,7 +1259,7 @@ class SoSReport(object):
self.ui_log.error("")
self._exit(1)
self.handle_exception(plugname, "setup")
- except:
+ except Exception:
self.handle_exception(plugname, "setup")
def version(self):
@@ -1315,7 +1315,7 @@ class SoSReport(object):
count, plugname = plugin
plug = self.loaded_plugins[count-1][1]
self.running_plugs.append(plugname)
- except:
+ except Exception:
return False
numplugs = len(self.loaded_plugins)
status_line = " Starting %-5s %-15s %s" % (
@@ -1331,11 +1331,11 @@ class SoSReport(object):
# so we can't blindly call remove() on these two.
try:
self.pluglist.remove(plugin)
- except:
+ except ValueError:
pass
try:
self.running_plugs.remove(plugname)
- except:
+ except ValueError:
pass
status = ''
if (len(self.pluglist) <= int(self.opts.threads) and
@@ -1354,7 +1354,7 @@ class SoSReport(object):
% e.strerror)
self._exit(1)
self.handle_exception(plugname, "collect")
- except:
+ except Exception:
self.handle_exception(plugname, "collect")
def ui_progress(self, status_line):
@@ -1372,7 +1372,7 @@ class SoSReport(object):
try:
self.xml_report.add_file(oneFile["srcpath"],
os.stat(oneFile["srcpath"]))
- except:
+ except IOError:
pass
try:
self.xml_report.serialize_to_file(os.path.join(self.rptdir,
@@ -1486,7 +1486,7 @@ class SoSReport(object):
for plugname, plug in self.loaded_plugins:
try:
html = plug.report()
- except:
+ except Exception:
self.handle_exception()
else:
rfd.write(html)
@@ -1507,7 +1507,7 @@ class SoSReport(object):
self.ui_log.error("")
self._exit(1)
self.handle_exception(plugname, "postproc")
- except:
+ except Exception:
self.handle_exception(plugname, "postproc")
def _create_checksum(self, archive, hash_name):
@@ -1553,7 +1553,7 @@ class SoSReport(object):
print("")
if e.errno in fatal_fs_errors:
self._exit(1)
- except:
+ except Exception:
if self.opts.debug:
raise
else:
diff --git a/sos/utilities.py b/sos/utilities.py
index 4899c58c..7c749aec 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -40,7 +40,7 @@ def fileobj(path_or_file, mode='r'):
if isinstance(path_or_file, six.string_types):
try:
return open(path_or_file, mode)
- except:
+ except IOError:
log = logging.getLogger('sos')
log.debug("fileobj: %s could not be opened" % path_or_file)
return closing(StringIO())