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__)
34 def __init__(self, dbase, rpath):
37 :type dbase: object DbManage
41 self._mail_settings = MailSettings()
42 if os.path.exists(rpath):
45 def create_pdf(self, taskid):
46 task = TaskData(taskid, self._dbase)
47 scenario_list = task.common.get_scenariolist()
48 creator = CandyGenerator(task)
50 for scenario in scenario_list:
51 out_file = os.path.join(
52 self._rpath, "vstf_report_%s_%s.pdf" %
53 (scenario, time.strftime(
56 creator.create(scenario)
57 info = TemplateSettings()
58 provider = PdfProvider(info.settings)
59 reporter = PdfCreator(provider)
60 reporter.create(out_file)
61 attach_list.append(out_file)
64 self._mail_settings.mset_attach(attach_list)
66 def create_html(self, taskid):
67 task = TaskData(taskid, self._dbase)
69 creator = CandyGenerator(task)
72 html_settings = HtmlSettings()
73 info = TemplateSettings()
74 LOG.info(html_settings.settings)
76 provider = HtmlProvider(info.settings, html_settings.settings)
77 out_file = os.path.join(self._rpath, "mail.html")
80 html = HtmlCreator(provider)
81 content = html.create(out_file)
83 self._mail_settings.mset_subtype('html')
84 self._mail_settings.mset_content(content)
86 def report(self, taskid, mail_off):
87 self._mail_settings = MailSettings()
88 mail = SendMail(self._mail_settings.settings)
89 self.create_pdf(taskid)
90 self.create_html(taskid)
96 from vstf.common.log import setup_logging
99 log_file="/var/log/vstf/vstf-reporter.log",
102 parser = argparse.ArgumentParser(add_help=True)
103 parser.add_argument('-rpath',
107 help=" the path name of test results "
109 parser.add_argument('-mail_off',
111 help="is need send mail the for the report"
113 parser.add_argument('--taskid',
116 help="report depand of a history task id."
118 args = parser.parse_args()
121 report = Report(dbase, args.rpath)
122 if args.taskid == -1:
123 taskid = dbase.get_last_taskid()
126 report.report(taskid, args.mail_off)
129 if __name__ == '__main__':