5 # see license for license details
11 from vstf.controller.reporters.report.pdf.pdfcreator import PdfvSwitchCreator
12 from vstf.controller.reporters.report.html.htmlcreator import HtmlvSwitchCreator
13 from vstf.controller.reporters.report.data_factory import CommonData, TaskData, ScenarioData, HistoryData
14 from vstf.controller.database.dbinterface import DbManage
15 from vstf.controller.settings.mail_settings import MailSettings
16 from vstf.controller.reporters.mail.sendmail import SendMail
17 from vstf.controller.settings.html_settings import HtmlSettings
18 from vstf.controller.reporters.report.provider.html_provider import StyleProvider
19 import vstf.common.constants as cst
23 LOG = logging.getLogger(__name__)
27 def __init__(self, dbase, rpath):
30 :type dbase: object DbManage
34 if os.path.exists(rpath):
37 def create_pdf(self, taskid):
38 common_data = CommonData(taskid, self._dbase)
39 scenario_list = common_data.get_scenariolist()
40 history_data = HistoryData(taskid, self._dbase)
42 for scenario in scenario_list:
43 out_file = os.path.join(self._rpath, "vstf_report_%s_%s.pdf" % (scenario, time.strftime(cst.TIME_STR)))
45 scenario_data = ScenarioData(taskid, self._dbase, scenario)
46 pdf = PdfvSwitchCreator(out_file, common_data, scenario_data, history_data)
49 attach_list.append(out_file)
51 self._mail_settings.mset_attach(attach_list)
53 def create_html(self, taskid):
54 task_data = TaskData(taskid, self._dbase)
56 html_settings = HtmlSettings()
57 LOG.info(html_settings.settings)
59 provider = StyleProvider(html_settings.settings)
60 out_file = os.path.join(self._rpath, "mail.html")
63 html = HtmlvSwitchCreator(task_data, provider, out_file)
64 content = html.create()
66 self._mail_settings.mset_subtype('html')
67 self._mail_settings.mset_content(content)
69 def report(self, taskid, mail_off):
70 self._mail_settings = MailSettings()
71 mail = SendMail(self._mail_settings.settings)
72 self.create_pdf(taskid)
73 self.create_html(taskid)
79 from vstf.common.log import setup_logging
80 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-reporter.log", clevel=logging.INFO)
82 parser = argparse.ArgumentParser(add_help=True)
83 parser.add_argument('-rpath',
87 help=" the path name of test results "
89 parser.add_argument('-mail_off',
91 help="is need send mail the for the report"
93 parser.add_argument('--taskid',
96 help="report depand of a history task id."
98 args = parser.parse_args()
101 report = Report(dbase, args.rpath)
102 if args.taskid == -1:
103 taskid = dbase.get_last_taskid()
106 report.report(taskid, args.mail_off)
109 if __name__ == '__main__':