Permalink
Browse files

Make more names pep8 compliant across the tree

Fix policy and utility function, method and variable names to use
lower case underscored style instead of camelCase.

Related to Issue #112.

Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
  • Loading branch information...
1 parent 4f0da96 commit 29e180fbc291686ee991952005c84c4b0d216a86 @bmr-cymru bmr-cymru committed Mar 28, 2013
Showing with 268 additions and 268 deletions.
  1. +1 −1 example_plugins/example.py
  2. +63 −63 sos/plugins/__init__.py
  3. +1 −1 sos/plugins/abrt.py
  4. +1 −1 sos/plugins/apache.py
  5. +1 −1 sos/plugins/as7.py
  6. +1 −1 sos/plugins/auditd.py
  7. +1 −1 sos/plugins/ceph.py
  8. +2 −2 sos/plugins/cloudforms.py
  9. +4 −4 sos/plugins/cluster.py
  10. +5 −5 sos/plugins/devicemapper.py
  11. +1 −1 sos/plugins/emc.py
  12. +2 −2 sos/plugins/filesys.py
  13. +2 −2 sos/plugins/general.py
  14. +2 −2 sos/plugins/gluster.py
  15. +1 −1 sos/plugins/hardware.py
  16. +1 −1 sos/plugins/infiniband.py
  17. +1 −1 sos/plugins/jboss.py
  18. +4 −4 sos/plugins/kernel.py
  19. +1 −1 sos/plugins/kvm.py
  20. +1 −1 sos/plugins/libraries.py
  21. +8 −8 sos/plugins/named.py
  22. +22 −22 sos/plugins/networking.py
  23. +1 −1 sos/plugins/nfsserver.py
  24. +1 −1 sos/plugins/nscd.py
  25. +1 −1 sos/plugins/openstack.py
  26. +1 −1 sos/plugins/postgresql.py
  27. +1 −1 sos/plugins/printing.py
  28. +1 −1 sos/plugins/psacct.py
  29. +1 −1 sos/plugins/pxe.py
  30. +1 −1 sos/plugins/rhevm.py
  31. +2 −2 sos/plugins/rhn.py
  32. +2 −2 sos/plugins/rhui.py
  33. +1 −1 sos/plugins/rpm.py
  34. +4 −4 sos/plugins/s390.py
  35. +3 −3 sos/plugins/sar.py
  36. +3 −3 sos/plugins/selinux.py
  37. +1 −1 sos/plugins/startup.py
  38. +3 −3 sos/plugins/sunrpc.py
  39. +1 −1 sos/plugins/veritas.py
  40. +6 −6 sos/plugins/xen.py
  41. +3 −3 sos/plugins/yum.py
  42. +55 −55 sos/policies/__init__.py
  43. +2 −2 sos/policies/debian.py
  44. +14 −14 sos/policies/redhat.py
  45. +1 −1 sos/policies/windows.py
  46. +16 −16 sos/sosreport.py
  47. +3 −3 sos/utilities.py
  48. +2 −2 tests/option_tests.py
  49. +5 −5 tests/plugin_tests.py
  50. +4 −4 tests/policy_tests.py
  51. +3 −3 tests/utilities_tests.py
@@ -28,7 +28,7 @@ class example(Plugin, RedHatPlugin):
# each option is a tuple of the following format:
# (name, description, fast or slow, default value)
# each option will be addressable like -k name=value
- optionList = [("init.d", 'Gathers the init.d directory', 'slow', 0),
+ option_list = [("init.d", 'Gathers the init.d directory', 'slow', 0),
('follicles', 'Gathers information about each follicle on every toe', 'slow', 0),
('color', 'Gathers toenail polish color', 'fast', 0)]
View
@@ -25,7 +25,7 @@
# pylint: disable-msg = W0613
from __future__ import with_statement
-from sos.utilities import sosGetCommandOutput, import_module, grep, fileobj, tail
+from sos.utilities import sos_get_command_output, import_module, grep, fileobj, tail
from sos import _sos as _
import inspect
import os
@@ -123,30 +123,30 @@ class Plugin(object):
files = ()
def __init__(self, commons):
- if not getattr(self, "optionList", False):
- self.optionList = []
+ if not getattr(self, "option_list", False):
+ self.option_list = []
- self.copiedFiles = []
- self.executedCommands = []
+ self.copied_files = []
+ self.executed_commands = []
self.alerts = []
- self.customText = ""
- self.optNames = []
- self.optParms = []
- self.cInfo = commons
- self.forbiddenPaths = []
- self.copyPaths = []
- self.copyStrings = []
- self.collectProgs = []
+ self.custom_text = ""
+ self.opt_names = []
+ self.opt_parms = []
+ self.commons = commons
+ self.forbidden_paths = []
+ self.copy_paths = []
+ self.copy_strings = []
+ self.collect_cmds = []
self.must_exit = False
- self.soslog = self.cInfo['soslog']
- self.proflog = self.cInfo['proflog']
+ self.soslog = self.commons['soslog']
+ self.proflog = self.commons['proflog']
# get the option list into a dictionary
- for opt in self.optionList:
- self.optNames.append(opt[0])
- self.optParms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]})
+ for opt in self.option_list:
+ self.opt_names.append(opt[0])
+ self.opt_parms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]})
@classmethod
def name(class_):
@@ -158,11 +158,11 @@ def name(class_):
return class_.__name__.lower()
def policy(self):
- return self.cInfo["policy"]
+ return self.commons["policy"]
def is_installed(self, package_name):
'''Is the package $package_name installed?'''
- return (self.policy().pkgByName(package_name) is not None)
+ return (self.policy().pkg_by_name(package_name) is not None)
def do_cmd_output_sub(self, cmd, regexp, subst):
'''Apply a regexp substitution to command output archived by sosreport.
@@ -175,16 +175,16 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
This function returns the number of replacements made.
'''
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
start_time = time()
globstr = '*' + cmd + '*'
self.soslog.debug("substituting '%s' for '%s' in commands matching %s"
% (subst, regexp, globstr))
try:
- for called in self.executedCommands:
+ for called in self.executed_commands:
if fnmatch.fnmatch(called['exe'], globstr):
- path = os.path.join(self.cInfo['cmddir'], called['file'])
+ path = os.path.join(self.commons['cmddir'], called['file'])
self.soslog.debug("applying substitution to %s" % path)
readable = self.archive.open_file(path)
result, replacements = re.subn(
@@ -197,7 +197,7 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e))
replacements = 0
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("subst: %-75s time: %f"
% (globstr, time_passed))
@@ -211,7 +211,7 @@ def do_file_sub(self, srcpath, regexp, subst):
This function returns the number of replacements made.
'''
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
start_time = time()
try:
@@ -230,7 +230,7 @@ def do_file_sub(self, srcpath, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e))
replacements = 0
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("subst : %-75s time: %f"
% (srcpath, time_passed))
@@ -282,7 +282,7 @@ def copy_symlink(self, srcpath, sub=None):
%(linkdest, absdest))
self.do_copy_file_or_dir(absdest)
- self.copiedFiles.append({
+ self.copied_files.append({
'srcpath':srcpath,
'dstpath':srcpath,
'symlink':"yes",
@@ -293,7 +293,7 @@ def copy_dir(self, srcpath, sub=None):
self.do_copy_file_or_dir(os.path.join(srcpath, afile), dest=None, sub=sub)
def _get_dest_for_srcpath(self, srcpath):
- for copied in self.copiedFiles:
+ for copied in self.copied_files:
if srcpath == copied["srcpath"]:
return copied["dstpath"]
return None
@@ -311,10 +311,10 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
/configurations/my_file.conf.
'''
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
start_time = time()
- if self._path_in_path_list(srcpath, self.forbiddenPaths):
+ if self._path_in_path_list(srcpath, self.forbidden_paths):
self.soslog.debug("%s is in the forbidden path list" % srcpath)
return ''
@@ -349,12 +349,12 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
else:
self.archive.add_file(srcpath, dest)
- self.copiedFiles.append({
+ self.copied_files.append({
'srcpath':srcpath,
'dstpath':dest,
'symlink':"no"})
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("copied: %-75s time: %f" % (srcpath, time_passed))
except Exception, e:
@@ -363,20 +363,20 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
def add_forbidden_path(self, forbiddenPath):
- """Specify a path to not copy, even if it's part of a copyPaths[]
+ """Specify a path to not copy, even if it's part of a copy_paths[]
entry.
"""
# Glob case handling is such that a valid non-glob is a reduced glob
for filespec in glob.glob(forbiddenPath):
- self.forbiddenPaths.append(filespec)
+ self.forbidden_paths.append(filespec)
def get_all_options(self):
"""return a list of all options selected"""
- return (self.optNames, self.optParms)
+ return (self.opt_names, self.opt_parms)
def set_option(self, optionname, value):
'''set the named option to value.'''
- for name, parms in izip(self.optNames, self.optParms):
+ for name, parms in izip(self.opt_names, self.opt_parms):
if name == optionname:
parms['enabled'] = value
return True
@@ -402,13 +402,13 @@ def _check(key):
else:
return key == optionname
- for name, parms in izip(self.optNames, self.optParms):
+ for name, parms in izip(self.opt_names, self.opt_parms):
if _check(name):
val = parms['enabled']
if val != None:
return val
- for key, value in self.cInfo.get('global_plugin_options', {}).iteritems():
+ for key, value in self.commons.get('global_plugin_options', {}).iteritems():
if _check(key):
return value
@@ -475,17 +475,17 @@ def add_copy_spec(self, copyspec, sub=None):
return False
# Glob case handling is such that a valid non-glob is a reduced glob
for filespec in glob.glob(copyspec):
- if filespec not in self.copyPaths:
- self.copyPaths.append((filespec, sub))
+ if filespec not in self.copy_paths:
+ self.copy_paths.append((filespec, sub))
def call_ext_prog(self, prog, timeout=300):
"""Execute a command independantly of the output gathering part of
sosreport.
"""
# pylint: disable-msg = W0612
- return sosGetCommandOutput(prog, timeout)
+ return sos_get_command_output(prog, timeout)
- def checkExtprog(self, prog):
+ def check_ext_prog(self, prog):
"""Execute a command independently of the output gathering part of
sosreport and check the return code. Return True for a return code of 0
and False otherwise.
@@ -496,7 +496,7 @@ def checkExtprog(self, prog):
def add_cmd_output(self, exe, suggest_filename=None, root_symlink=None, timeout=300):
"""Run a program and collect the output"""
- self.collectProgs.append( (exe, suggest_filename, root_symlink, timeout) )
+ self.collect_cmds.append( (exe, suggest_filename, root_symlink, timeout) )
def file_grep(self, regexp, *fnames):
"""Returns lines matched in fnames, where fnames can either be
@@ -511,7 +511,7 @@ def mangle_command(self, exe):
def make_command_filename(self, exe):
"""The internal function to build up a filename based on a command."""
- outfn = os.path.join(self.cInfo['cmddir'], self.name(), self.mangle_command(exe))
+ outfn = os.path.join(self.commons['cmddir'], self.name(), self.mangle_command(exe))
# check for collisions
if os.path.exists(outfn):
@@ -527,17 +527,17 @@ def make_command_filename(self, exe):
def add_string_as_file(self, content, filename):
"""Add a string to the archive as a file named `filename`"""
- self.copyStrings.append((content, filename))
+ self.copy_strings.append((content, filename))
def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, timeout=300):
"""Execute a command and save the output to a file for inclusion in the
report.
"""
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
start_time = time()
# pylint: disable-msg = W0612
- status, shout, runtime = sosGetCommandOutput(exe, timeout=timeout)
+ status, shout, runtime = sos_get_command_output(exe, timeout=timeout)
if (status == 127):
self.soslog.info("could not run '%s': command not found" % exe)
return None
@@ -547,16 +547,16 @@ def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, tim
else:
outfn = self.make_command_filename(exe)
- outfn_strip = outfn[len(self.cInfo['cmddir'])+1:]
+ outfn_strip = outfn[len(self.commons['cmddir'])+1:]
self.archive.add_string(shout, outfn)
if root_symlink:
self.archive.add_link(outfn, root_symlink)
# save info for later
- self.executedCommands.append({'exe': exe, 'file':outfn_strip}) # save in our list
- self.cInfo['xmlreport'].add_command(cmdline=exe,exitcode=status,f_stdout=outfn_strip,runtime=runtime)
+ self.executed_commands.append({'exe': exe, 'file':outfn_strip}) # save in our list
+ self.commons['xmlreport'].add_command(cmdline=exe,exitcode=status,f_stdout=outfn_strip,runtime=runtime)
- if self.cInfo['cmdlineopts'].profiler:
+ if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time
self.proflog.debug("output: %-75s time: %f" % (exe, time_passed))
@@ -573,22 +573,22 @@ def add_custom_text(self, text):
"""Append text to the custom text that is included in the report. This
is freeform and can include html.
"""
- self.customText += text
+ self.custom_text += text
def collect(self):
"""Collect the data for a plugin."""
- for path, sub in self.copyPaths:
+ for path, sub in self.copy_paths:
self.do_copy_file_or_dir(path, sub=sub)
- for string, file_name in self.copyStrings:
+ for string, file_name in self.copy_strings:
try:
self.archive.add_string(string,
os.path.join('sos_strings', self.name(), file_name))
except Exception, e:
self.soslog.debug("could not create %s, traceback follows: %s"
% (file_name, e))
- for progs in izip(self.collectProgs):
+ for progs in izip(self.collect_cmds):
prog, suggest_filename, root_symlink, timeout = progs[0]
self.soslog.debug("collecting output of '%s'" % prog)
try:
@@ -636,7 +636,7 @@ def default_enabled(self):
return True
def setup(self):
- """This method must be overridden to add the copyPaths, forbiddenPaths,
+ """This method must be overridden to add the copy_paths, forbidden_paths,
and external programs to be collected at a minimum.
"""
pass
@@ -658,9 +658,9 @@ def report(self):
html = html + "<h2> Plugin <em>" + self.name() + "</em></h2>\n"
# Files
- if len(self.copiedFiles):
+ if len(self.copied_files):
html = html + "<p>Files copied:<br><ul>\n"
- for afile in self.copiedFiles:
+ for afile in self.copied_files:
html = html + '<li><a href="%s">%s</a>' % \
(".." + afile['dstpath'], afile['srcpath'])
if (afile['symlink'] == "yes"):
@@ -669,13 +669,13 @@ def report(self):
html = html + "</ul></p>\n"
# Command Output
- if len(self.executedCommands):
+ if len(self.executed_commands):
html = html + "<p>Commands Executed:<br><ul>\n"
# convert file name to relative path from our root
# don't use relpath - these are HTML paths not OS paths.
- for cmd in self.executedCommands:
+ for cmd in self.executed_commands:
if cmd["file"] and len(cmd["file"]):
- cmdOutRelPath = "../" + self.cInfo['cmddir'] \
+ cmdOutRelPath = "../" + self.commons['cmddir'] \
+ "/" + cmd['file']
html = html + '<li><a href="%s">%s</a></li>\n' % \
(cmdOutRelPath, cmd['exe'])
@@ -691,9 +691,9 @@ def report(self):
html = html + "</ul></p>\n"
# Custom Text
- if (self.customText != ""):
+ if (self.custom_text != ""):
html = html + "<p>Additional Information:<br>\n"
- html = html + self.customText + "</p>\n"
+ html = html + self.custom_text + "</p>\n"
return html
View
@@ -21,7 +21,7 @@ class abrt(Plugin, RedHatPlugin):
"""ABRT log dump
"""
- optionList = [("backtraces", 'collect backtraces for every report', 'slow', False)]
+ option_list = [("backtraces", 'collect backtraces for every report', 'slow', False)]
def check_enabled(self):
return self.is_installed("abrt-cli") or \
View
@@ -19,7 +19,7 @@ class apache(Plugin):
"""
plugin_name = "apache"
- optionList = [("log", "gathers all apache logs", "slow", False)]
+ option_list = [("log", "gathers all apache logs", "slow", False)]
class RedHatApache(apache, RedHatPlugin):
"""Apache related information for Red Hat distributions
View
@@ -18,7 +18,7 @@ class AS7(Plugin, IndependentPlugin, AS7Mixin):
version = "1.0"
- optionList = [
+ option_list = [
("home", "JBoss's installation dir (i.e. JBOSS_HOME)", '', False),
("logsize", 'max size (MiB) to collect per log file', '', 15),
("stdjar", 'Collect jar statistics for standard jars.', '', True),
Oops, something went wrong.

0 comments on commit 29e180f

Please sign in to comment.