diff options
author | Christian Berendt <berendt@b1-systems.de> | 2012-11-07 19:39:43 +0100 |
---|---|---|
committer | Brian Waldon <bcwaldon@gmail.com> | 2012-11-19 10:15:19 -0800 |
commit | b24832c22aa44d2f8b5ecddaf12e7878653af28f (patch) | |
tree | 97607a7157024b913b87fe50f0246f232d887fee /glanceclient/common/utils.py | |
parent | 16aafa728e4b8309b16bcc120b10bc20372883f4 (diff) | |
download | python-glanceclient-b24832c22aa44d2f8b5ecddaf12e7878653af28f.tar.gz |
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
Diffstat (limited to 'glanceclient/common/utils.py')
-rw-r--r-- | glanceclient/common/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 31b8530..628225d 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -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]) |