Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / reporters / report / html / htmlcreator.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10
11 import logging
12
13 import vstf.common.candy_text as candy
14 from vstf.controller.reporters.report.provider.html_provider import HtmlProvider
15 from vstf.controller.settings.template_settings import TemplateSettings
16 from vstf.controller.settings.html_settings import HtmlSettings
17 from vstf.controller.reporters.report.html.html_base import HtmlBase, pyhtm
18
19 LOG = logging.getLogger(__name__)
20
21
22 class HtmlCreator(HtmlBase):
23
24     def create_story(self):
25         self.add_context()
26
27     def add_context(self):
28         context = self._provider.get_context
29         self._raw_context(context)
30
31     def _raw_context(self, context, ci=0, si=0, ui=0, level=-1):
32         _story = []
33         for key, value in sorted(context.items()):
34             LOG.info(key)
35             LOG.info(value)
36             _sn, _node, _style = candy.text2tuple(key)
37             if _node in candy.dom:
38                 if _node == candy.chapter:
39                     ci = _style
40                 elif _node == candy.section:
41                     si = _style
42                 else:
43                     ui = _style
44                 self._raw_context(value, ci, si, ui, level + 1)
45
46             else:
47                 LOG.info("node: %s  %s" % (_node, candy.title))
48                 if _node == candy.title:
49                     assert value
50                     if level in range(len(candy.dom)):
51                         if level == 0:
52                             value[0] = "Chapter %s %s" % (ci, value[0])
53                             for title in value:
54                                 self._page << pyhtm.H2(title)
55                         elif level == 1:
56                             value[0] = "%s.%s %s" % (ci, si, value[0])
57                             for title in value:
58                                 self._page << pyhtm.H3(title)
59                         else:
60                             value[0] = "%s.%s.%s %s" % (ci, si, ui, value[0])
61                             for title in value:
62                                 self._page << pyhtm.H3(title)
63
64                 elif _node == candy.table:
65                     self.add_table(value)
66                 elif _node == candy.paragraph:
67                     for para in value:
68                         para = pyhtm.space(2) + para
69                         self._page << pyhtm.P(para)
70
71
72 def unit_test():
73     from vstf.common.log import setup_logging
74     setup_logging(
75         level=logging.DEBUG,
76         log_file="/var/log/html-creator.log",
77         clevel=logging.INFO)
78
79     out_file = "vstf_report.html"
80
81     info = TemplateSettings()
82     html_settings = HtmlSettings()
83     provider = HtmlProvider(info.settings, html_settings.settings)
84     reporter = HtmlCreator(provider)
85     reporter.create(out_file)
86
87 if __name__ == '__main__':
88     unit_test()