1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from vstf.controller.reporters.report.provider.html_provider import HtmlProvider
16 from vstf.controller.reporters.report.provider.pdf_provider import PdfProvider
17 from vstf.controller.settings.template_settings import TemplateSettings
18 from vstf.controller.reporters.report.data_factory import TaskData
19 from vstf.controller.reporters.report.html.htmlcreator import HtmlCreator
20 from vstf.controller.reporters.report.pdf.pdfcreator import PdfCreator
21 from vstf.controller.database.dbinterface import DbManage
22 from vstf.controller.settings.mail_settings import MailSettings
23 from vstf.controller.reporters.mail.sendmail import SendMail
24 from vstf.controller.settings.html_settings import HtmlSettings
25 from vstf.controller.reporters.report.candy_generator import CandyGenerator
26 import vstf.common.constants as cst
29 LOG = logging.getLogger(__name__)
33 def __init__(self, dbase, rpath):
36 :type dbase: object DbManage
40 self._mail_settings = MailSettings()
41 if os.path.exists(rpath):
44 def create_pdf(self, taskid):
45 task = TaskData(taskid, self._dbase)
46 scenario_list = task.common.get_scenariolist()
47 creator = CandyGenerator(task)
49 for scenario in scenario_list:
50 out_file = os.path.join(self._rpath, "vstf_report_%s_%s.pdf" % (scenario, time.strftime(cst.TIME_FORMAT3)))
52 creator.create(scenario)
53 info = TemplateSettings()
54 provider = PdfProvider(info.settings)
55 reporter = PdfCreator(provider)
56 reporter.create(out_file)
57 attach_list.append(out_file)
60 self._mail_settings.mset_attach(attach_list)
62 def create_html(self, taskid):
63 task = TaskData(taskid, self._dbase)
65 creator = CandyGenerator(task)
68 html_settings = HtmlSettings()
69 info = TemplateSettings()
70 LOG.info(html_settings.settings)
72 provider = HtmlProvider(info.settings, html_settings.settings)
73 out_file = os.path.join(self._rpath, "mail.html")
76 html = HtmlCreator(provider)
77 content = html.create(out_file)
79 self._mail_settings.mset_subtype('html')
80 self._mail_settings.mset_content(content)
82 def report(self, taskid, mail_off):
83 self._mail_settings = MailSettings()
84 mail = SendMail(self._mail_settings.settings)
85 self.create_pdf(taskid)
86 self.create_html(taskid)
92 from vstf.common.log import setup_logging
93 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-reporter.log", clevel=logging.INFO)
95 parser = argparse.ArgumentParser(add_help=True)
96 parser.add_argument('-rpath',
100 help=" the path name of test results "
102 parser.add_argument('-mail_off',
104 help="is need send mail the for the report"
106 parser.add_argument('--taskid',
109 help="report depand of a history task id."
111 args = parser.parse_args()
114 report = Report(dbase, args.rpath)
115 if args.taskid == -1:
116 taskid = dbase.get_last_taskid()
119 report.report(taskid, args.mail_off)
122 if __name__ == '__main__':