Add bytesToStr()
Automatically convert list into strings in appendRow() Add package information
This commit is contained in:
20
display.py
20
display.py
@@ -15,7 +15,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
|
||||
self.rows = []
|
||||
|
||||
def appendRow(self, row):
|
||||
self.rows.append(row)
|
||||
self.rows.append(listToStr(row))
|
||||
|
||||
def build(self, f):
|
||||
f.write('<table>')
|
||||
@@ -68,3 +68,21 @@ class DisplayHTMLBuild(object):
|
||||
def build(self, root):
|
||||
for page in self.pages:
|
||||
page.build(root)
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user