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 ##############################################################################
11 Story Decorator contains ImageStory, HeaderStory, PageBreakStory,
12 TableStory, LinePlotStory, TitleStory, ParagraphStory
16 from reportlab.platypus import PageBreak
17 from reportlab.lib import colors
18 from reportlab.platypus.tableofcontents import TableOfContents
30 return self._storylist
33 class StoryDecorator(Story):
35 def __init__(self, story, data=None, style=None):
42 # print self._story.storylist
45 return self._story.storylist
48 raise NotImplementedError("abstract StoryDecorator")
51 class ImageStory(StoryDecorator):
55 for filename in self._data:
56 if os.path.exists(filename) == False:
57 print "not find %s" % filename
59 if 'Traffic-types' in filename:
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(
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(
88 class HeaderStory(StoryDecorator):
92 self._story.storylist.append(PageBreak())
95 class PageBreakStory(StoryDecorator):
98 print "PageBreak story"
99 self._story.storylist.append(PageBreak())
102 class TableOfContentsStory(StoryDecorator):
105 print "TableOfContents story"
106 self._data = [" ", " ", "Table Of Contents", ""]
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)
114 class SpaceStory(StoryDecorator):
118 self._story.storylist.append(eParagraph([" ", " "], style).para)
121 class TableStory(StoryDecorator):
127 self._story.storylist.append(eDataTable(self._data, style).table)
128 elif self._style == 2:
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)
150 class LinePlotStory(StoryDecorator):
158 data = eGraphicsTable([[eLinePlot(self._data, style).draw]]).table
160 self._story.storylist.append(data)
163 class LineChartStory(StoryDecorator):
166 print "LineChartStory: "
171 data = eGraphicsTable(
172 [[eHorizontalLineChart(self._data, style).draw]]).table
174 self._story.storylist.append(data)
177 class BarChartStory(StoryDecorator):
180 print "BarChartStory: "
186 data = eGraphicsTable(
187 [[eBarChartColumn(self._data, style).draw]]).table
189 self._story.storylist.append(data)
192 class ParagraphStory(StoryDecorator):
195 print "Paragraph Story"
200 data = eParagraph(self._data, style).para
202 self._story.storylist.append(data)
205 class TitleStory(StoryDecorator):
208 print "Paragraph Story"
209 if self._style - 1 in range(9):
210 style = eval("ps_head_lv" + "%d" % self._style)
216 self._story.storylist.append(eParagraph(self._data, style).para)