From f3e9082376f0ff4df5cdc4a5a2a647a700220824 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 21 Jun 2019 10:18:35 -0400 Subject: [PATCH] Simplify fromhuman byte formatting --- client-common/ceph.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/client-common/ceph.py b/client-common/ceph.py index 31dd00d7..bb6fc1c4 100644 --- a/client-common/ceph.py +++ b/client-common/ceph.py @@ -94,18 +94,11 @@ def format_bytes_tohuman(databytes): return datahuman def format_bytes_fromhuman(datahuman): - databytes = '' - for unit in sorted(unit_matrix, key=unit_matrix.get, reverse=True): - new_bytes = int(math.ceil(datahuman * unit_matrix[unit])) - # Round up if 5 or more digits - if new_bytes < 9999: - # We can jump down another level - continue - else: - # We're at the end, display with this size - databytes = '{}{}'.format(new_bytes, unit) - - return databytes + # Trim off human-readable character + dataunit = datahuman[-1] + datasize = int(datahuman[:-1]) + databytes = datasize * unit_matrix[dataunit] + return '{}B'.format(databytes) # # Cluster search functions