Add support for terabytes

This commit is contained in:
Matt Mackall 2011-05-26 09:17:28 -05:00
commit f9a60fbe2e

5
smem
View file

@ -176,7 +176,7 @@ def units(x):
s = '' s = ''
if x == 0: if x == 0:
return '0' return '0'
for s in ('', 'K', 'M', 'G'): for s in ('', 'K', 'M', 'G', 'T'):
if x < 1024: if x < 1024:
break break
x /= 1024.0 x /= 1024.0
@ -184,7 +184,8 @@ def units(x):
def fromunits(x): def fromunits(x):
s = dict(k=2**10, K=2**10, kB=2**10, KB=2**10, s = dict(k=2**10, K=2**10, kB=2**10, KB=2**10,
M=2**20, MB=2**20, G=2**30, GB=2**30) M=2**20, MB=2**20, G=2**30, GB=2**30,
T=2**40, TB=2**40)
for k,v in s.items(): for k,v in s.items():
if x.endswith(k): if x.endswith(k):
return int(float(x[:-len(k)])*v) return int(float(x[:-len(k)])*v)