From 496b28c8a68f1b94c363bca95b10609a0e35c38d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Thu, 16 May 2019 16:22:56 -0600 Subject: [PATCH] Adjusted convert_to_bytes * Now supports bytes! * Now supports petabytes? --- .bin/Scripts/functions/common.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/.bin/Scripts/functions/common.py b/.bin/Scripts/functions/common.py index a457db16..81b3654e 100644 --- a/.bin/Scripts/functions/common.py +++ b/.bin/Scripts/functions/common.py @@ -173,18 +173,22 @@ def clear_screen(): def convert_to_bytes(size): """Convert human-readable size str to bytes and return an int.""" size = str(size) - tmp = re.search(r'(\d+\.?\d*)\s+([KMGT]B)', size.upper()) + tmp = re.search(r'(\d+\.?\d*)\s+([PTGMKB])B?', size.upper()) if tmp: size = float(tmp.group(1)) units = tmp.group(2) - if units == 'TB': - size *= 1099511627776 - elif units == 'GB': - size *= 1073741824 - elif units == 'MB': - size *= 1048576 - elif units == 'KB': - size *= 1024 + if units == 'P': + size *= 1024 ** 5 + if units == 'T': + size *= 1024 ** 4 + elif units == 'G': + size *= 1024 ** 3 + elif units == 'M': + size *= 1024 ** 2 + elif units == 'K': + size *= 1024 ** 1 + elif units == 'B': + size *= 1024 ** 0 size = int(size) else: return -1