Skip to content

Commit

Permalink
Make more names pep8 compliant across the tree
Browse files Browse the repository at this point in the history
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
bmr-cymru committed Mar 28, 2013
1 parent 4f0da96 commit 29e180f
Show file tree
Hide file tree
Showing 51 changed files with 268 additions and 268 deletions.
2 changes: 1 addition & 1 deletion example_plugins/example.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class example(Plugin, RedHatPlugin):
# each option is a tuple of the following format: # each option is a tuple of the following format:
# (name, description, fast or slow, default value) # (name, description, fast or slow, default value)
# each option will be addressable like -k name=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), ('follicles', 'Gathers information about each follicle on every toe', 'slow', 0),
('color', 'Gathers toenail polish color', 'fast', 0)] ('color', 'Gathers toenail polish color', 'fast', 0)]


Expand Down
126 changes: 63 additions & 63 deletions sos/plugins/__init__.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# pylint: disable-msg = W0613 # pylint: disable-msg = W0613
from __future__ import with_statement 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 _ from sos import _sos as _
import inspect import inspect
import os import os
Expand Down Expand Up @@ -123,30 +123,30 @@ class Plugin(object):
files = () files = ()


def __init__(self, commons): def __init__(self, commons):
if not getattr(self, "optionList", False): if not getattr(self, "option_list", False):
self.optionList = [] self.option_list = []


self.copiedFiles = [] self.copied_files = []
self.executedCommands = [] self.executed_commands = []
self.alerts = [] self.alerts = []
self.customText = "" self.custom_text = ""
self.optNames = [] self.opt_names = []
self.optParms = [] self.opt_parms = []
self.cInfo = commons self.commons = commons
self.forbiddenPaths = [] self.forbidden_paths = []
self.copyPaths = [] self.copy_paths = []
self.copyStrings = [] self.copy_strings = []
self.collectProgs = [] self.collect_cmds = []


self.must_exit = False self.must_exit = False


self.soslog = self.cInfo['soslog'] self.soslog = self.commons['soslog']
self.proflog = self.cInfo['proflog'] self.proflog = self.commons['proflog']


# get the option list into a dictionary # get the option list into a dictionary
for opt in self.optionList: for opt in self.option_list:
self.optNames.append(opt[0]) self.opt_names.append(opt[0])
self.optParms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]}) self.opt_parms.append({'desc':opt[1], 'speed':opt[2], 'enabled':opt[3]})


@classmethod @classmethod
def name(class_): def name(class_):
Expand All @@ -158,11 +158,11 @@ def name(class_):
return class_.__name__.lower() return class_.__name__.lower()


def policy(self): def policy(self):
return self.cInfo["policy"] return self.commons["policy"]


def is_installed(self, package_name): def is_installed(self, package_name):
'''Is the package $package_name installed?''' '''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): def do_cmd_output_sub(self, cmd, regexp, subst):
'''Apply a regexp substitution to command output archived by sosreport. '''Apply a regexp substitution to command output archived by sosreport.
Expand All @@ -175,16 +175,16 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
This function returns the number of replacements made. This function returns the number of replacements made.
''' '''
if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
start_time = time() start_time = time()


globstr = '*' + cmd + '*' globstr = '*' + cmd + '*'
self.soslog.debug("substituting '%s' for '%s' in commands matching %s" self.soslog.debug("substituting '%s' for '%s' in commands matching %s"
% (subst, regexp, globstr)) % (subst, regexp, globstr))
try: try:
for called in self.executedCommands: for called in self.executed_commands:
if fnmatch.fnmatch(called['exe'], globstr): 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) self.soslog.debug("applying substitution to %s" % path)
readable = self.archive.open_file(path) readable = self.archive.open_file(path)
result, replacements = re.subn( result, replacements = re.subn(
Expand All @@ -197,7 +197,7 @@ def do_cmd_output_sub(self, cmd, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"' msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e)) self.soslog.error(msg % (path, self.name(), e))
replacements = 0 replacements = 0
if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time time_passed = time() - start_time
self.proflog.debug("subst: %-75s time: %f" self.proflog.debug("subst: %-75s time: %f"
% (globstr, time_passed)) % (globstr, time_passed))
Expand All @@ -211,7 +211,7 @@ def do_file_sub(self, srcpath, regexp, subst):
This function returns the number of replacements made. This function returns the number of replacements made.
''' '''
if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
start_time = time() start_time = time()


try: try:
Expand All @@ -230,7 +230,7 @@ def do_file_sub(self, srcpath, regexp, subst):
msg = 'regex substitution failed for %s in plugin %s with: "%s"' msg = 'regex substitution failed for %s in plugin %s with: "%s"'
self.soslog.error(msg % (path, self.name(), e)) self.soslog.error(msg % (path, self.name(), e))
replacements = 0 replacements = 0
if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time time_passed = time() - start_time
self.proflog.debug("subst : %-75s time: %f" self.proflog.debug("subst : %-75s time: %f"
% (srcpath, time_passed)) % (srcpath, time_passed))
Expand Down Expand Up @@ -282,7 +282,7 @@ def copy_symlink(self, srcpath, sub=None):
%(linkdest, absdest)) %(linkdest, absdest))
self.do_copy_file_or_dir(absdest) self.do_copy_file_or_dir(absdest)


self.copiedFiles.append({ self.copied_files.append({
'srcpath':srcpath, 'srcpath':srcpath,
'dstpath':srcpath, 'dstpath':srcpath,
'symlink':"yes", 'symlink':"yes",
Expand All @@ -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) self.do_copy_file_or_dir(os.path.join(srcpath, afile), dest=None, sub=sub)


def _get_dest_for_srcpath(self, srcpath): def _get_dest_for_srcpath(self, srcpath):
for copied in self.copiedFiles: for copied in self.copied_files:
if srcpath == copied["srcpath"]: if srcpath == copied["srcpath"]:
return copied["dstpath"] return copied["dstpath"]
return None return None
Expand All @@ -311,10 +311,10 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
/configurations/my_file.conf. /configurations/my_file.conf.
''' '''


if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
start_time = time() 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) self.soslog.debug("%s is in the forbidden path list" % srcpath)
return '' return ''


Expand Down Expand Up @@ -349,12 +349,12 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):
else: else:
self.archive.add_file(srcpath, dest) self.archive.add_file(srcpath, dest)


self.copiedFiles.append({ self.copied_files.append({
'srcpath':srcpath, 'srcpath':srcpath,
'dstpath':dest, 'dstpath':dest,
'symlink':"no"}) 'symlink':"no"})


if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
time_passed = time() - start_time time_passed = time() - start_time
self.proflog.debug("copied: %-75s time: %f" % (srcpath, time_passed)) self.proflog.debug("copied: %-75s time: %f" % (srcpath, time_passed))
except Exception, e: except Exception, e:
Expand All @@ -363,20 +363,20 @@ def do_copy_file_or_dir(self, srcpath, dest=None, sub=None):




def add_forbidden_path(self, forbiddenPath): 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. entry.
""" """
# Glob case handling is such that a valid non-glob is a reduced glob # Glob case handling is such that a valid non-glob is a reduced glob
for filespec in glob.glob(forbiddenPath): for filespec in glob.glob(forbiddenPath):
self.forbiddenPaths.append(filespec) self.forbidden_paths.append(filespec)


def get_all_options(self): def get_all_options(self):
"""return a list of all options selected""" """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): def set_option(self, optionname, value):
'''set the named option to 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: if name == optionname:
parms['enabled'] = value parms['enabled'] = value
return True return True
Expand All @@ -402,13 +402,13 @@ def _check(key):
else: else:
return key == optionname 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): if _check(name):
val = parms['enabled'] val = parms['enabled']
if val != None: if val != None:
return val 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): if _check(key):
return value return value


Expand Down Expand Up @@ -475,17 +475,17 @@ def add_copy_spec(self, copyspec, sub=None):
return False return False
# Glob case handling is such that a valid non-glob is a reduced glob # Glob case handling is such that a valid non-glob is a reduced glob
for filespec in glob.glob(copyspec): for filespec in glob.glob(copyspec):
if filespec not in self.copyPaths: if filespec not in self.copy_paths:
self.copyPaths.append((filespec, sub)) self.copy_paths.append((filespec, sub))


def call_ext_prog(self, prog, timeout=300): def call_ext_prog(self, prog, timeout=300):
"""Execute a command independantly of the output gathering part of """Execute a command independantly of the output gathering part of
sosreport. sosreport.
""" """
# pylint: disable-msg = W0612 # 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 """Execute a command independently of the output gathering part of
sosreport and check the return code. Return True for a return code of 0 sosreport and check the return code. Return True for a return code of 0
and False otherwise. and False otherwise.
Expand All @@ -496,7 +496,7 @@ def checkExtprog(self, prog):


def add_cmd_output(self, exe, suggest_filename=None, root_symlink=None, timeout=300): def add_cmd_output(self, exe, suggest_filename=None, root_symlink=None, timeout=300):
"""Run a program and collect the output""" """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): def file_grep(self, regexp, *fnames):
"""Returns lines matched in fnames, where fnames can either be """Returns lines matched in fnames, where fnames can either be
Expand All @@ -511,7 +511,7 @@ def mangle_command(self, exe):
def make_command_filename(self, exe): def make_command_filename(self, exe):
"""The internal function to build up a filename based on a command.""" """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 # check for collisions
if os.path.exists(outfn): if os.path.exists(outfn):
Expand All @@ -527,17 +527,17 @@ def make_command_filename(self, exe):


def add_string_as_file(self, content, filename): def add_string_as_file(self, content, filename):
"""Add a string to the archive as a file named `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): 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 """Execute a command and save the output to a file for inclusion in the
report. report.
""" """
if self.cInfo['cmdlineopts'].profiler: if self.commons['cmdlineopts'].profiler:
start_time = time() start_time = time()


# pylint: disable-msg = W0612 # pylint: disable-msg = W0612
status, shout, runtime = sosGetCommandOutput(exe, timeout=timeout) status, shout, runtime = sos_get_command_output(exe, timeout=timeout)
if (status == 127): if (status == 127):
self.soslog.info("could not run '%s': command not found" % exe) self.soslog.info("could not run '%s': command not found" % exe)
return None return None
Expand All @@ -547,16 +547,16 @@ def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, tim
else: else:
outfn = self.make_command_filename(exe) 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) self.archive.add_string(shout, outfn)
if root_symlink: if root_symlink:
self.archive.add_link(outfn, root_symlink) self.archive.add_link(outfn, root_symlink)


# save info for later # save info for later
self.executedCommands.append({'exe': exe, 'file':outfn_strip}) # save in our list self.executed_commands.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.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 time_passed = time() - start_time
self.proflog.debug("output: %-75s time: %f" % (exe, time_passed)) self.proflog.debug("output: %-75s time: %f" % (exe, time_passed))


Expand All @@ -573,22 +573,22 @@ def add_custom_text(self, text):
"""Append text to the custom text that is included in the report. This """Append text to the custom text that is included in the report. This
is freeform and can include html. is freeform and can include html.
""" """
self.customText += text self.custom_text += text


def collect(self): def collect(self):
"""Collect the data for a plugin.""" """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) 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: try:
self.archive.add_string(string, self.archive.add_string(string,
os.path.join('sos_strings', self.name(), file_name)) os.path.join('sos_strings', self.name(), file_name))
except Exception, e: except Exception, e:
self.soslog.debug("could not create %s, traceback follows: %s" self.soslog.debug("could not create %s, traceback follows: %s"
% (file_name, e)) % (file_name, e))


for progs in izip(self.collectProgs): for progs in izip(self.collect_cmds):
prog, suggest_filename, root_symlink, timeout = progs[0] prog, suggest_filename, root_symlink, timeout = progs[0]
self.soslog.debug("collecting output of '%s'" % prog) self.soslog.debug("collecting output of '%s'" % prog)
try: try:
Expand Down Expand Up @@ -636,7 +636,7 @@ def default_enabled(self):
return True return True


def setup(self): 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. and external programs to be collected at a minimum.
""" """
pass pass
Expand All @@ -658,9 +658,9 @@ def report(self):
html = html + "<h2> Plugin <em>" + self.name() + "</em></h2>\n" html = html + "<h2> Plugin <em>" + self.name() + "</em></h2>\n"


# Files # Files
if len(self.copiedFiles): if len(self.copied_files):
html = html + "<p>Files copied:<br><ul>\n" 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>' % \ html = html + '<li><a href="%s">%s</a>' % \
(".." + afile['dstpath'], afile['srcpath']) (".." + afile['dstpath'], afile['srcpath'])
if (afile['symlink'] == "yes"): if (afile['symlink'] == "yes"):
Expand All @@ -669,13 +669,13 @@ def report(self):
html = html + "</ul></p>\n" html = html + "</ul></p>\n"


# Command Output # Command Output
if len(self.executedCommands): if len(self.executed_commands):
html = html + "<p>Commands Executed:<br><ul>\n" html = html + "<p>Commands Executed:<br><ul>\n"
# convert file name to relative path from our root # convert file name to relative path from our root
# don't use relpath - these are HTML paths not OS paths. # 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"]): if cmd["file"] and len(cmd["file"]):
cmdOutRelPath = "../" + self.cInfo['cmddir'] \ cmdOutRelPath = "../" + self.commons['cmddir'] \
+ "/" + cmd['file'] + "/" + cmd['file']
html = html + '<li><a href="%s">%s</a></li>\n' % \ html = html + '<li><a href="%s">%s</a></li>\n' % \
(cmdOutRelPath, cmd['exe']) (cmdOutRelPath, cmd['exe'])
Expand All @@ -691,9 +691,9 @@ def report(self):
html = html + "</ul></p>\n" html = html + "</ul></p>\n"


# Custom Text # Custom Text
if (self.customText != ""): if (self.custom_text != ""):
html = html + "<p>Additional Information:<br>\n" html = html + "<p>Additional Information:<br>\n"
html = html + self.customText + "</p>\n" html = html + self.custom_text + "</p>\n"


return html return html


Expand Down
2 changes: 1 addition & 1 deletion sos/plugins/abrt.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class abrt(Plugin, RedHatPlugin):
"""ABRT log dump """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): def check_enabled(self):
return self.is_installed("abrt-cli") or \ return self.is_installed("abrt-cli") or \
Expand Down
2 changes: 1 addition & 1 deletion sos/plugins/apache.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class apache(Plugin):
""" """
plugin_name = "apache" plugin_name = "apache"


optionList = [("log", "gathers all apache logs", "slow", False)] option_list = [("log", "gathers all apache logs", "slow", False)]


class RedHatApache(apache, RedHatPlugin): class RedHatApache(apache, RedHatPlugin):
"""Apache related information for Red Hat distributions """Apache related information for Red Hat distributions
Expand Down
2 changes: 1 addition & 1 deletion sos/plugins/as7.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class AS7(Plugin, IndependentPlugin, AS7Mixin):


version = "1.0" version = "1.0"


optionList = [ option_list = [
("home", "JBoss's installation dir (i.e. JBOSS_HOME)", '', False), ("home", "JBoss's installation dir (i.e. JBOSS_HOME)", '', False),
("logsize", 'max size (MiB) to collect per log file', '', 15), ("logsize", 'max size (MiB) to collect per log file', '', 15),
("stdjar", 'Collect jar statistics for standard jars.', '', True), ("stdjar", 'Collect jar statistics for standard jars.', '', True),
Expand Down
Loading

0 comments on commit 29e180f

Please sign in to comment.