the binary size is human readable
bzr revid: christophe@tinyerp.com-20080902100928-nv9i9e1guq2qpeh2
This commit is contained in:
parent
c326e2317f
commit
ed7af4de69
|
@ -211,11 +211,6 @@ class binary(_column):
|
|||
if not values:
|
||||
values = []
|
||||
|
||||
def convert(b):
|
||||
if not b:
|
||||
return b
|
||||
return '%d bytes' % b
|
||||
|
||||
res = {}
|
||||
for i in ids:
|
||||
val = None
|
||||
|
@ -225,7 +220,7 @@ class binary(_column):
|
|||
break
|
||||
res.setdefault(i, val)
|
||||
if context.get('get_binary_size', True):
|
||||
res[i] = convert(val)
|
||||
res[i] = tools.human_size(val)
|
||||
|
||||
return res
|
||||
|
||||
|
|
|
@ -672,6 +672,18 @@ def mod10r(number):
|
|||
return result + str((10 - report) % 10)
|
||||
|
||||
|
||||
def human_size(sz):
|
||||
"""
|
||||
Return the size in a human readable format
|
||||
"""
|
||||
if not sz:
|
||||
return False
|
||||
units = ('bytes', 'Kb', 'Mb', 'Gb')
|
||||
s, i = float(sz), 0
|
||||
while s >= 1024 and i < len(units)-1:
|
||||
s = s / 1024
|
||||
i = i + 1
|
||||
return "%0.2f %s" % (s, units[i])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue