From 5afb6c9b0728c7f5f0edd14a44e62ae91959194d Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Tue, 18 Jul 2017 10:12:49 +0100 Subject: 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. --- src/virtBootstrap/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/virtBootstrap/utils.py') 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) -- cgit