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
30 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(self._rpath, "vstf_report_%s_%s.pdf" % (scenario, time.strftime(cst.TIME_FORMAT3)))
53 creator.create(scenario)
54 info = TemplateSettings()
55 provider = PdfProvider(info.settings)
56 reporter = PdfCreator(provider)
57 reporter.create(out_file)
58 attach_list.append(out_file)
61 self._mail_settings.mset_attach(attach_list)
63 def create_html(self, taskid):
64 task = TaskData(taskid, self._dbase)
66 creator = CandyGenerator(task)
69 html_settings = HtmlSettings()
70 info = TemplateSettings()
71 LOG.info(html_settings.settings)
73 provider = HtmlProvider(info.settings, html_settings.settings)
74 out_file = os.path.join(self._rpath, "mail.html")
77 html = HtmlCreator(provider)
78 content = html.create(out_file)
80 self._mail_settings.mset_subtype('html')
81 self._mail_settings.mset_content(content)
83 def report(self, taskid, mail_off):
84 self._mail_settings = MailSettings()
85 mail = SendMail(self._mail_settings.settings)
86 self.create_pdf(taskid)
87 self.create_html(taskid)
93 from vstf.common.log import setup_logging
94 setup_logging(level=logging.DEBUG, log_file="/var/log/vstf/vstf-reporter.log", clevel=logging.INFO)
96 parser = argparse.ArgumentParser(add_help=True)
97 parser.add_argument('-rpath',
101 help=" the path name of test results "
103 parser.add_argument('-mail_off',
105 help="is need send mail the for the report"
107 parser.add_argument('--taskid',
110 help="report depand of a history task id."
112 args = parser.parse_args()
115 report = Report(dbase, args.rpath)
116 if args.taskid == -1:
117 taskid = dbase.get_last_taskid()
120 report.report(taskid, args.mail_off)
123 if __name__ == '__main__':