Better error reporting; return options from run_report to see what happened and where it went
svn: r13554
This commit is contained in:
parent
16b1cbfa50
commit
a3abc0950d
@ -30,7 +30,9 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import traceback
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(".")
|
log = logging.getLogger(".")
|
||||||
@ -420,6 +422,7 @@ def cl_report(database, name, category, report_class, options_class,
|
|||||||
MyReport.begin_report()
|
MyReport.begin_report()
|
||||||
MyReport.write_report()
|
MyReport.write_report()
|
||||||
MyReport.end_report()
|
MyReport.end_report()
|
||||||
|
return clr
|
||||||
except ReportError, msg:
|
except ReportError, msg:
|
||||||
(m1, m2) = msg.messages()
|
(m1, m2) = msg.messages()
|
||||||
print err_msg
|
print err_msg
|
||||||
@ -428,7 +431,13 @@ def cl_report(database, name, category, report_class, options_class,
|
|||||||
if len(log.handlers) > 0:
|
if len(log.handlers) > 0:
|
||||||
log.error(err_msg, exc_info=True)
|
log.error(err_msg, exc_info=True)
|
||||||
else:
|
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):
|
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",
|
>>> run_report(db, "ancestor_report", off="txt",
|
||||||
of="ancestor-007.txt", pid="I37")
|
of="ancestor-007.txt", pid="I37")
|
||||||
|
|
||||||
returns True if successfully runs the report, False
|
returns CommandLineReport (clr) if successfully runs the report,
|
||||||
otherwise.
|
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()
|
dbstate = DbState.DbState()
|
||||||
climanager = CLIManager(dbstate, False) # don't load db
|
climanager = CLIManager(dbstate, False) # don't load db
|
||||||
climanager.do_reg_plugins()
|
climanager.do_reg_plugins()
|
||||||
pmgr = BasePluginManager.get_instance()
|
pmgr = BasePluginManager.get_instance()
|
||||||
cl_list = pmgr.get_reg_reports()
|
cl_list = pmgr.get_reg_reports()
|
||||||
|
clr = None
|
||||||
for pdata in cl_list:
|
for pdata in cl_list:
|
||||||
if name == pdata.id:
|
if name == pdata.id:
|
||||||
mod = pmgr.load_plugin(pdata)
|
mod = pmgr.load_plugin(pdata)
|
||||||
if not mod:
|
if not mod:
|
||||||
#import of plugin failed
|
#import of plugin failed
|
||||||
return False
|
return clr
|
||||||
category = pdata.category
|
category = pdata.category
|
||||||
report_class = getattr(mod, pdata.reportclass)
|
report_class = getattr(mod, pdata.reportclass)
|
||||||
options_class = getattr(mod, pdata.optionclass)
|
options_class = getattr(mod, pdata.optionclass)
|
||||||
@ -465,8 +479,8 @@ def run_report(db, name, **options_str_dict):
|
|||||||
options_class(db, name, category,
|
options_class(db, name, category,
|
||||||
options_str_dict)
|
options_str_dict)
|
||||||
else:
|
else:
|
||||||
cl_report(db, name, category,
|
clr = cl_report(db, name, category,
|
||||||
report_class, options_class,
|
report_class, options_class,
|
||||||
options_str_dict)
|
options_str_dict)
|
||||||
return True
|
return clr
|
||||||
return False
|
return clr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user