From a3abc0950da95a1fbb95737564cafc3d8e41fe39 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 11 Nov 2009 13:42:34 +0000 Subject: [PATCH] Better error reporting; return options from run_report to see what happened and where it went svn: r13554 --- src/ReportBase/_CommandLineReport.py | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ReportBase/_CommandLineReport.py b/src/ReportBase/_CommandLineReport.py index caebc1bc1..72abacce6 100644 --- a/src/ReportBase/_CommandLineReport.py +++ b/src/ReportBase/_CommandLineReport.py @@ -30,7 +30,9 @@ # #------------------------------------------------------------------------- from gettext import gettext as _ +import traceback import os +import sys import logging log = logging.getLogger(".") @@ -420,6 +422,7 @@ def cl_report(database, name, category, report_class, options_class, MyReport.begin_report() MyReport.write_report() MyReport.end_report() + return clr except ReportError, msg: (m1, m2) = msg.messages() print err_msg @@ -428,7 +431,13 @@ def cl_report(database, name, category, report_class, options_class, if len(log.handlers) > 0: log.error(err_msg, exc_info=True) else: - print >> os.stderr, err_msg + print >> sys.stderr, err_msg + ## Something seems to eat the exception above. + ## Hack to re-get the exception: + try: + raise + except: + traceback.print_exc() def run_report(db, name, **options_str_dict): """ @@ -444,20 +453,25 @@ def run_report(db, name, **options_str_dict): >>> run_report(db, "ancestor_report", off="txt", of="ancestor-007.txt", pid="I37") - returns True if successfully runs the report, False - otherwise. + returns CommandLineReport (clr) if successfully runs the report, + None otherwise. + + You can see: + options and values used in clr.option_class.options_dict + filename in clr.option_class.get_output() """ dbstate = DbState.DbState() climanager = CLIManager(dbstate, False) # don't load db climanager.do_reg_plugins() pmgr = BasePluginManager.get_instance() cl_list = pmgr.get_reg_reports() + clr = None for pdata in cl_list: if name == pdata.id: mod = pmgr.load_plugin(pdata) if not mod: #import of plugin failed - return False + return clr category = pdata.category report_class = getattr(mod, pdata.reportclass) options_class = getattr(mod, pdata.optionclass) @@ -465,8 +479,8 @@ def run_report(db, name, **options_str_dict): options_class(db, name, category, options_str_dict) else: - cl_report(db, name, category, - report_class, options_class, - options_str_dict) - return True - return False + clr = cl_report(db, name, category, + report_class, options_class, + options_str_dict) + return clr + return clr