[modules/memory] Simplify and use util methods

This commit is contained in:
Tobias Witek 2020-03-06 14:52:16 +01:00
parent 13e512d1f1
commit 56a6173282
3 changed files with 16 additions and 13 deletions

View file

@ -23,4 +23,11 @@ def aslist(val):
return val
return str(val).replace(' ', '').split(',')
def byte(val, fmt='{:.2f}'):
for unit in ['', 'Ki', 'Mi', 'Gi']:
if val < 1024.0:
return '{}{}B'.format(fmt, unit).format(val)
val /= 1024.0
return '{}GiB'.format(fmt).format(val*1024.0)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4