summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/controller/reporters/report/pdf/story.py
blob: 3e56e185da1634a5ac0c073dc179ecbe67e43922 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/python
# -*- coding: utf8 -*-
__doc__ = """
Story Decorator contains ImageStory, HeaderStory, PageBreakStory,
TableStory, LinePlotStory, TitleStory, ParagraphStory
"""
import sys
import os
from reportlab.platypus import PageBreak
from reportlab.lib import colors
from reportlab.platypus.tableofcontents import TableOfContents
from styles import *
from element import *


class Story(object):
    def __init__(self):
        self._storylist = []

    @property
    def storylist(self):
        return self._storylist


class StoryDecorator(Story):
    def __init__(self, story, data=None, style=None):
        self._story = story
        self._data = data
        self._style = style
        print self._data
        self.new_story()

    #       print self._story.storylist
    @property
    def storylist(self):
        return self._story.storylist

    def new_story(self):
        raise NotImplementedError("abstract StoryDecorator")


class ImageStory(StoryDecorator):
    def new_story(self):
        print "Image Story"
        for filename in self._data:
            if os.path.exists(filename) == False:
                print "not find %s" % filename
                continue
            if 'Traffic-types' in filename:
                style = is_traffic
                image_height = style.image_height
                image_width = style.image_width
                image_hAlign = style.image_hAlign
                image_vAlign = style.image_vAlign
                self._story.storylist.append(
                    eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign))
            else:
                style = is_default
                image_height = style.image_height
                image_width = style.image_width
                image_hAlign = style.image_hAlign
                image_vAlign = style.image_vAlign
                #    self._story.storylist.append(eGraphicsTable([[' ' * 5, eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign)]], ts_left).table)
                self._story.storylist.append(
                    eImage(filename, image_width, image_height, hAlign=image_hAlign, vAlign=image_vAlign))


class HeaderStory(StoryDecorator):
    def new_story(self):
        print "header story"
        self._story.storylist.append(PageBreak())


class PageBreakStory(StoryDecorator):
    def new_story(self):
        print "PageBreak story"
        self._story.storylist.append(PageBreak())


class TableOfContentsStory(StoryDecorator):
    def new_story(self):
        print "TableOfContents story"
        self._data = [" ", " ", "Table Of Contents", ""]
        style = ps_head_lv4
        self._story.storylist.append(eParagraph(self._data, style).para)
        toc = TableOfContents()
        toc.levelStyles = [ps_head_lv7, ps_head_lv8, ps_head_lv9]
        self._story.storylist.append(toc)


class uTableStory(StoryDecorator):
    def new_story(self):
        print "utable story"
        style = ts_left
        if not self._data:
            print "data error "
            return
        self._story.storylist.append(eCommonTable(self._data, style).table)


class TableStory(StoryDecorator):
    def new_story(self):
        print "table story"
        style = ts_default
        self._story.storylist.append(eDataTable(self._data, style).table)


class SpaceStory(StoryDecorator):
    def new_story(self):
        style = ps_space
        self._story.storylist.append(eParagraph([" ", " "], style).para)


class cTableStory(StoryDecorator):
    def new_story(self):
        print "table story"
        style = ts_default
        if self._style == 0:
            self._story.storylist.append(eConfigTable(self._data, style).table)
        elif self._style == 1:
            self._story.storylist.append(eOptionsTable(self._data, style).table)
        elif self._style == 2:
            self._story.storylist.append(eProfileTable(self._data, style).table)
        elif self._style == 3:
            self._story.storylist.append(eSummaryTable(self._data, style).table)
        elif self._style == 4:
            self._story.storylist.append(eScenarioTable(self._data, style).table)
        elif self._style == 5:
            self._story.storylist.append(eGitInfoTable(self._data, style).table)


class LinePlotStory(StoryDecorator):
    def new_story(self):
        print "LinePlot"
        style = lps_default
        if not self._data:
            print "data error "
            return
        data = eGraphicsTable([[eLinePlot(self._data, style).draw]]).table
        if data:
            self._story.storylist.append(data)


class LineChartStory(StoryDecorator):
    def new_story(self):
        print "LineChartStory: "
        style = lcs_default
        if not self._data:
            print "data error "
            return
        data = eGraphicsTable([[eHorizontalLineChart(self._data, style).draw]]).table
        if data:
            self._story.storylist.append(data)


class BarChartStory(StoryDecorator):
    def new_story(self):
        print "BarChartStory: "
        style = bcs_default
        if not self._data:
            print "data error "
            return

        data = eGraphicsTable([[eBarChartColumn(self._data, style).draw]]).table
        if data:
            self._story.storylist.append(data)


class ParagraphStory(StoryDecorator):
    def new_story(self):
        print "Paragraph Story"
        style = ps_body
        if not self._data:
            print "data error "
            return
        data = eParagraph(self._data, style).para
        if data:
            self._story.storylist.append(data)


class TitleStory(StoryDecorator):
    def new_story(self):
        print "Paragraph Story"
        if self._style - 1 in range(9):
            style = eval("ps_head_lv" + "%d" % self._style)
        else:
            style = ps_body
        # print style
        # print self._data

        self._story.storylist.append(eParagraph(self._data, style).para)