JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / controller / reporters / report / html / html_base.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 os
12 import vstf.common.pyhtml as pyhtm
13
14
15 class HtmlBase(object):
16     def __init__(self, provider):
17         self._page = pyhtm.PyHtml('Html Text')
18         self._provider = provider
19
20     def save(self, ofile):
21         if ofile:
22             os.system('rm -rf %s' % ofile)
23             self._page.output(ofile)
24
25     def as_string(self):
26         return self._page.as_string()
27
28     def add_table(self, data):
29         if data and zip(*data):
30             self._page.add_table(data)
31
32     def add_style(self):
33         style = self._provider.get_style
34         self._page.add_style(style)
35
36     def create(self, ofile='text.html'):
37         self.add_style()
38         self.create_story()
39         self.save(ofile)
40         return self.as_string()
41
42     def create_story(self):
43         raise NotImplementedError("abstract HtmlBase")