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
29 return self._storylist
32 class StoryDecorator(Story):
33 def __init__(self, story, data=None, style=None):
40 # print self._story.storylist
43 return self._story.storylist
46 raise NotImplementedError("abstract StoryDecorator")
49 class ImageStory(StoryDecorator):
52 for filename in self._data:
53 if os.path.exists(filename) == False:
54 print "not find %s" % filename
56 if 'Traffic-types' in filename:
58 image_height = style.image_height
59 image_width = style.image_width
60 image_hAlign = style.image_hAlign
61 image_vAlign = style.image_vAlign
62 self._story.storylist.append(
63 eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign))
66 image_height = style.image_height
67 image_width = style.image_width
68 image_hAlign = style.image_hAlign
69 image_vAlign = style.image_vAlign
70 # self._story.storylist.append(eGraphicsTable([[' ' * 5, eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign)]], ts_left).table)
71 self._story.storylist.append(
72 eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign))
75 class HeaderStory(StoryDecorator):
78 self._story.storylist.append(PageBreak())
81 class PageBreakStory(StoryDecorator):
83 print "PageBreak story"
84 self._story.storylist.append(PageBreak())
87 class TableOfContentsStory(StoryDecorator):
89 print "TableOfContents story"
90 self._data = [" ", " ", "Table Of Contents", ""]
92 self._story.storylist.append(eParagraph(self._data, style).para)
93 toc = TableOfContents()
94 toc.levelStyles = [ps_head_lv7, ps_head_lv8, ps_head_lv9]
95 self._story.storylist.append(toc)
98 class SpaceStory(StoryDecorator):
101 self._story.storylist.append(eParagraph([" ", " "], style).para)
104 class TableStory(StoryDecorator):
109 self._story.storylist.append(eDataTable(self._data, style).table)
110 elif self._style ==2:
112 self._story.storylist.append(eCommonTable(self._data, style).table)
113 elif self._style == 3:
114 self._story.storylist.append(eConfigTable(self._data, style).table)
115 elif self._style == 4:
116 self._story.storylist.append(eOptionsTable(self._data, style).table)
117 elif self._style == 5:
118 self._story.storylist.append(eProfileTable(self._data, style).table)
119 elif self._style == 6:
120 self._story.storylist.append(eSummaryTable(self._data, style).table)
121 elif self._style == 7:
122 self._story.storylist.append(eScenarioTable(self._data, style).table)
123 elif self._style == 8:
124 self._story.storylist.append(eGitInfoTable(self._data, style).table)
127 class LinePlotStory(StoryDecorator):
134 data = eGraphicsTable([[eLinePlot(self._data, style).draw]]).table
136 self._story.storylist.append(data)
139 class LineChartStory(StoryDecorator):
141 print "LineChartStory: "
146 data = eGraphicsTable([[eHorizontalLineChart(self._data, style).draw]]).table
148 self._story.storylist.append(data)
151 class BarChartStory(StoryDecorator):
153 print "BarChartStory: "
159 data = eGraphicsTable([[eBarChartColumn(self._data, style).draw]]).table
161 self._story.storylist.append(data)
164 class ParagraphStory(StoryDecorator):
166 print "Paragraph Story"
171 data = eParagraph(self._data, style).para
173 self._story.storylist.append(data)
176 class TitleStory(StoryDecorator):
178 print "Paragraph Story"
179 if self._style - 1 in range(9):
180 style = eval("ps_head_lv" + "%d" % self._style)
186 self._story.storylist.append(eParagraph(self._data, style).para)