Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / reporters / report / pdf / story.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 __doc__ = """
11 Story Decorator contains ImageStory, HeaderStory, PageBreakStory,
12 TableStory, LinePlotStory, TitleStory, ParagraphStory
13 """
14 import sys
15 import os
16 from reportlab.platypus import PageBreak
17 from reportlab.lib import colors
18 from reportlab.platypus.tableofcontents import TableOfContents
19 from styles import *
20 from element import *
21
22
23 class Story(object):
24
25     def __init__(self):
26         self._storylist = []
27
28     @property
29     def storylist(self):
30         return self._storylist
31
32
33 class StoryDecorator(Story):
34
35     def __init__(self, story, data=None, style=None):
36         self._story = story
37         self._data = data
38         self._style = style
39         print self._data
40         self.new_story()
41
42     #       print self._story.storylist
43     @property
44     def storylist(self):
45         return self._story.storylist
46
47     def new_story(self):
48         raise NotImplementedError("abstract StoryDecorator")
49
50
51 class ImageStory(StoryDecorator):
52
53     def new_story(self):
54         print "Image Story"
55         for filename in self._data:
56             if os.path.exists(filename) == False:
57                 print "not find %s" % filename
58                 continue
59             if 'Traffic-types' in filename:
60                 style = is_traffic
61                 image_height = style.image_height
62                 image_width = style.image_width
63                 image_hAlign = style.image_hAlign
64                 image_vAlign = style.image_vAlign
65                 self._story.storylist.append(
66                     eImage(
67                         filename,
68                         image_width,
69                         image_height,
70                         hAlign=image_hAlign,
71                         vAlign=image_vAlign))
72             else:
73                 style = is_default
74                 image_height = style.image_height
75                 image_width = style.image_width
76                 image_hAlign = style.image_hAlign
77                 image_vAlign = style.image_vAlign
78                 #    self._story.storylist.append(eGraphicsTable([[' ' * 5, eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign)]], ts_left).table)
79                 self._story.storylist.append(
80                     eImage(
81                         filename,
82                         image_width,
83                         image_height,
84                         hAlign=image_hAlign,
85                         vAlign=image_vAlign))
86
87
88 class HeaderStory(StoryDecorator):
89
90     def new_story(self):
91         print "header story"
92         self._story.storylist.append(PageBreak())
93
94
95 class PageBreakStory(StoryDecorator):
96
97     def new_story(self):
98         print "PageBreak story"
99         self._story.storylist.append(PageBreak())
100
101
102 class TableOfContentsStory(StoryDecorator):
103
104     def new_story(self):
105         print "TableOfContents story"
106         self._data = [" ", " ", "Table Of Contents", ""]
107         style = ps_head_lv4
108         self._story.storylist.append(eParagraph(self._data, style).para)
109         toc = TableOfContents()
110         toc.levelStyles = [ps_head_lv7, ps_head_lv8, ps_head_lv9]
111         self._story.storylist.append(toc)
112
113
114 class SpaceStory(StoryDecorator):
115
116     def new_story(self):
117         style = ps_space
118         self._story.storylist.append(eParagraph([" ", " "], style).para)
119
120
121 class TableStory(StoryDecorator):
122
123     def new_story(self):
124         print "table story"
125         style = ts_default
126         if self._style == 1:
127             self._story.storylist.append(eDataTable(self._data, style).table)
128         elif self._style == 2:
129             style = ts_left
130             self._story.storylist.append(eCommonTable(self._data, style).table)
131         elif self._style == 3:
132             self._story.storylist.append(eConfigTable(self._data, style).table)
133         elif self._style == 4:
134             self._story.storylist.append(
135                 eOptionsTable(self._data, style).table)
136         elif self._style == 5:
137             self._story.storylist.append(
138                 eProfileTable(self._data, style).table)
139         elif self._style == 6:
140             self._story.storylist.append(
141                 eSummaryTable(self._data, style).table)
142         elif self._style == 7:
143             self._story.storylist.append(
144                 eScenarioTable(self._data, style).table)
145         elif self._style == 8:
146             self._story.storylist.append(
147                 eGitInfoTable(self._data, style).table)
148
149
150 class LinePlotStory(StoryDecorator):
151
152     def new_story(self):
153         print "LinePlot"
154         style = lps_default
155         if not self._data:
156             print "data error "
157             return
158         data = eGraphicsTable([[eLinePlot(self._data, style).draw]]).table
159         if data:
160             self._story.storylist.append(data)
161
162
163 class LineChartStory(StoryDecorator):
164
165     def new_story(self):
166         print "LineChartStory: "
167         style = lcs_default
168         if not self._data:
169             print "data error "
170             return
171         data = eGraphicsTable(
172             [[eHorizontalLineChart(self._data, style).draw]]).table
173         if data:
174             self._story.storylist.append(data)
175
176
177 class BarChartStory(StoryDecorator):
178
179     def new_story(self):
180         print "BarChartStory: "
181         style = bcs_default
182         if not self._data:
183             print "data error "
184             return
185
186         data = eGraphicsTable(
187             [[eBarChartColumn(self._data, style).draw]]).table
188         if data:
189             self._story.storylist.append(data)
190
191
192 class ParagraphStory(StoryDecorator):
193
194     def new_story(self):
195         print "Paragraph Story"
196         style = ps_body
197         if not self._data:
198             print "data error "
199             return
200         data = eParagraph(self._data, style).para
201         if data:
202             self._story.storylist.append(data)
203
204
205 class TitleStory(StoryDecorator):
206
207     def new_story(self):
208         print "Paragraph Story"
209         if self._style - 1 in range(9):
210             style = eval("ps_head_lv" + "%d" % self._style)
211         else:
212             style = ps_body
213         # print style
214         # print self._data
215
216         self._story.storylist.append(eParagraph(self._data, style).para)