Make image sizes more readable for humans

By introducing the parameter --human-readable for several functions
(image-list, image-show, image-update, image-create) it's possible
to convert the size in bytes to something more readable like
9.309MB or 1.375GB.

Change-Id: I4e2654994361dcf330ed6d681dbed73388f159cb
This commit is contained in:
Christian Berendt
2012-11-07 19:39:43 +01:00
committed by Brian Waldon
parent 16aafa728e
commit b24832c22a
3 changed files with 39 additions and 4 deletions
+12
View File
@@ -168,3 +168,15 @@ def integrity_iter(iter, checksum):
raise IOError(errno.EPIPE,
'Corrupt image download. Checksum was %s expected %s' %
(md5sum, checksum))
def make_size_human_readable(size):
suffix = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']
base = 1024.0
index = 0
while size > base:
index = index + 1
size = size / base
return "%.3f%s" % (size, suffix[index])