summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-18 10:12:49 +0100
committerCédric Bosdonnat <cbosdonnat@suse.com>2017-07-18 17:43:14 +0200
commit5afb6c9b0728c7f5f0edd14a44e62ae91959194d (patch)
treef0dc835822f0d06f0af9aca66ecdf7e28f0250e9
parent5a0068ff2a9460b2fb872a5722eb61d508869e9e (diff)
downloadvirt-bootstrap.git-5afb6c9b0728c7f5f0edd14a44e62ae91959194d.tar.gz
virt-bootstrap.git-5afb6c9b0728c7f5f0edd14a44e62ae91959194d.tar.xz
virt-bootstrap.git-5afb6c9b0728c7f5f0edd14a44e62ae91959194d.zip
utils: size_to_bytes convert from int
When converting 0 KB with string input the result will be string with zeroes. >>> print(size_to_bytes('0', 'KB')) 000000... Instead convert the string input to integer and then perform the conversion. Rename the variable from "string" to "number" to avoid confusion.
-rw-r--r--src/virtBootstrap/utils.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index b7b626a..28a513c 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -124,12 +124,12 @@ def bytes_to_size(number):
return(fmt % (number or 0, symbols[depth]))
-def size_to_bytes(string, fmt):
+def size_to_bytes(number, fmt):
"""
Convert human readable formats to bytes.
"""
formats = {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3, 'TB': 4}
- return (string * pow(1024, formats[fmt.upper()]) if fmt in formats
+ return (int(number) * pow(1024, formats[fmt.upper()]) if fmt in formats
else False)