2014-11-21 10:41:29 +01:00
|
|
|
|
2014-11-21 16:56:58 +01:00
|
|
|
class DisplayHTMLBlock(object):
|
|
|
|
|
2014-11-25 16:59:29 +01:00
|
|
|
def __init__(self, title=''):
|
2014-11-21 16:56:58 +01:00
|
|
|
self.title = title
|
|
|
|
|
|
|
|
def build(self, f):
|
|
|
|
pass
|
|
|
|
|
2014-11-25 16:59:29 +01:00
|
|
|
class DisplayHTMLRawBlock(DisplayHTMLBlock):
|
|
|
|
|
|
|
|
def __init__(self, title=''):
|
|
|
|
super(DisplayHTMLRawBlock, self).__init__(title)
|
|
|
|
self.html = ''
|
|
|
|
|
|
|
|
def setRawHTML(self, html):
|
|
|
|
self.html = html
|
|
|
|
|
|
|
|
def build(self, f):
|
|
|
|
f.write(self.html)
|
|
|
|
|
2014-11-21 16:56:58 +01:00
|
|
|
class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
|
|
|
|
|
|
|
def __init__(self, title, cols):
|
|
|
|
super(DisplayHTMLBlockTable, self).__init__(title)
|
|
|
|
self.cols = cols
|
|
|
|
self.rows = []
|
|
|
|
|
|
|
|
def appendRow(self, row):
|
2014-11-24 13:44:04 +01:00
|
|
|
self.rows.append(listToStr(row))
|
2014-11-21 16:56:58 +01:00
|
|
|
|
|
|
|
def build(self, f):
|
|
|
|
f.write('<table>')
|
2014-11-21 10:41:29 +01:00
|
|
|
f.write('<tr>')
|
2014-11-21 16:56:58 +01:00
|
|
|
for title in self.cols:
|
|
|
|
f.write('<th>%s</th>' % (title))
|
2014-11-21 10:41:29 +01:00
|
|
|
f.write('</tr>')
|
2014-11-21 16:56:58 +01:00
|
|
|
for row in self.rows:
|
|
|
|
f.write('<tr>')
|
|
|
|
for v in row:
|
|
|
|
f.write('<td>%s</td>' % (v))
|
|
|
|
f.write('</tr>')
|
|
|
|
f.write('</table>')
|
|
|
|
|
|
|
|
class DisplayHTMLPage(object):
|
|
|
|
|
|
|
|
def __init__(self, title, filename):
|
|
|
|
self.title = title
|
|
|
|
self.filename = filename
|
|
|
|
self.blocks = []
|
|
|
|
|
|
|
|
def getFilename(self):
|
|
|
|
return self.filename;
|
|
|
|
|
|
|
|
def appendBlock(self, block):
|
|
|
|
self.blocks.append(block)
|
|
|
|
|
|
|
|
def build(self, root):
|
|
|
|
f = open(root + self.filename, 'w')
|
|
|
|
f.write('<html><title>%s</title><body>' % (self.title))
|
|
|
|
for block in self.blocks:
|
|
|
|
block.build(f)
|
|
|
|
f.write('</body></html>')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
class DisplayHTMLBuild(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.pages = []
|
|
|
|
|
|
|
|
def getPage(self, filename):
|
|
|
|
for page in self.pages:
|
|
|
|
if page.getFilename() == filename:
|
|
|
|
return page
|
|
|
|
return None
|
|
|
|
|
|
|
|
def addPage(self, page):
|
|
|
|
self.pages.append(page)
|
|
|
|
|
|
|
|
def build(self, root):
|
|
|
|
for page in self.pages:
|
|
|
|
page.build(root)
|
2014-11-24 13:44:04 +01:00
|
|
|
|
|
|
|
def bytesToStr(bytes):
|
|
|
|
suffixes = ['', ' kB', ' MB', ' GB', ' TB']
|
|
|
|
|
|
|
|
for i in range(0, len(suffixes)):
|
|
|
|
if bytes < 1024: break
|
|
|
|
bytes /= 1024.0
|
|
|
|
|
|
|
|
if i:
|
|
|
|
return '%.02f%s' % (bytes, suffixes[i])
|
|
|
|
else:
|
|
|
|
return '%d%s' % (bytes, suffixes[i])
|
|
|
|
|
|
|
|
def _toStr(v):
|
|
|
|
if type(v) != str: return str(v)
|
|
|
|
else: return v
|
|
|
|
|
|
|
|
def listToStr(l): return map(lambda(v) : _toStr(v), l)
|