aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2013-04-23 17:54:58 +0100
committerBryn M. Reeves <bmr@redhat.com>2013-04-23 17:54:58 +0100
commit624034ec2184ca6f6a719f45f7b0addaa4718dac (patch)
tree5338946f7e844702a4a2d1f8dfc13405c9417d4e
parent5e7346542ac1d11d73e9cbf84cecce910c5c823d (diff)
downloadsos-624034ec2184ca6f6a719f45f7b0addaa4718dac.tar.gz
Clean up SoSReport.execute()
Reorganise the SoSReport object's execute() method to facilitate separation of the command line and report generation logic: - Rename ensure_plugins() as verify_plugins() and have it return a boolean to the execute() method. - Push logging down from execute into the individual action methods that carry out the tasks being logged. - Have execute() return a boolean indicating whether the requested operation completed successfully or not. Longer term it may be better to define an enumeration class for sos return statuses. This would allow more expression than simple 'pass' or 'fail' and would help the move toward an API. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/sosreport.py37
1 files changed, 22 insertions, 15 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py
index 9a72b142..6e4a6141 100644
--- a/sos/sosreport.py
+++ b/sos/sosreport.py
@@ -631,6 +631,9 @@ class SoSReport(object):
def collect(self):
+ self.ui_log.info(_(" Running plugins. Please wait ..."))
+ self.ui_log.info("")
+
plugruncount = 0
for i in izip(self.loaded_plugins):
plugruncount += 1
@@ -647,6 +650,8 @@ class SoSReport(object):
raise
else:
self._log_plugin_exception(plugname)
+ self.ui_log.info("")
+
def report(self):
for plugname, plug in self.loaded_plugins:
@@ -768,7 +773,11 @@ class SoSReport(object):
self._finish_logging()
- final_filename = self.archive.compress(self.opts.compression_type)
+ # compression could fail for a number of reasons
+ try:
+ final_filename = self.archive.compress(self.opts.compression_type)
+ except:
+ return False
# automated submission will go here
if not self.opts.upload:
@@ -778,12 +787,13 @@ class SoSReport(object):
self.tempfile_util.clean()
- return final_filename
+ return True
- def ensure_plugins(self):
+ def verify_plugins(self):
if not self.loaded_plugins:
self.soslog.error(_("no valid plugins were enabled"))
- self._exit(1)
+ return False
+ return True
def parse_options(self, args):
""" Parse command line options """
@@ -854,9 +864,11 @@ class SoSReport(object):
option = self.parser.get_option(name)
option.process(name, value, self.opts, self.parser)
+
def set_global_plugin_option(self, key, value):
self.global_plugin_options[key] = value;
+
def execute(self):
try:
self._setup_logging()
@@ -869,31 +881,26 @@ class SoSReport(object):
if self.opts.listPlugins:
self.list_plugins()
- return
+ return True
+
+ # verify that at least one plug-in is enabled
+ if not self.verify_plugins():
+ return False
- self.ensure_plugins()
self.batch()
self.prework()
self.setup()
-
- self.ui_log.info(_(" Running plugins. Please wait ..."))
- self.ui_log.info("")
-
self.collect()
-
- self.ui_log.info("")
-
if self.opts.report:
self.report()
self.html_report()
self.plain_report()
-
self.postproc()
self.version()
return self.final_work()
except SystemExit:
- return None
+ return False
def main(args):
"""The main entry point"""