summaryrefslogtreecommitdiff
path: root/python/vyos/utils/convert.py
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-10-20 23:47:20 -0500
committerJohn Estabrook <jestabro@vyos.io>2023-12-16 20:37:10 -0600
commit06832e3cc962eb4f94afe5319e7416d68756dba9 (patch)
tree94f4ae62796c6ff011c687ee902d7ee8fa9f2949 /python/vyos/utils/convert.py
parentc3d2e02898259190d107127d867f9e16a2b84f1f (diff)
downloadvyos-1x-06832e3cc962eb4f94afe5319e7416d68756dba9.tar.gz
vyos-1x-06832e3cc962eb4f94afe5319e7416d68756dba9.zip
image: T4516: improve format of 'show system image details'
(cherry picked from commit 8efab9ee8cdb0e65dddb9d3ba97de8ddcf3666dc)
Diffstat (limited to 'python/vyos/utils/convert.py')
-rw-r--r--python/vyos/utils/convert.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/python/vyos/utils/convert.py b/python/vyos/utils/convert.py
index 9a8a1ff7d..c02f0071e 100644
--- a/python/vyos/utils/convert.py
+++ b/python/vyos/utils/convert.py
@@ -52,7 +52,8 @@ def seconds_to_human(s, separator=""):
return result
-def bytes_to_human(bytes, initial_exponent=0, precision=2):
+def bytes_to_human(bytes, initial_exponent=0, precision=2,
+ int_below_exponent=0):
""" Converts a value in bytes to a human-readable size string like 640 KB
The initial_exponent parameter is the exponent of 2,
@@ -68,6 +69,8 @@ def bytes_to_human(bytes, initial_exponent=0, precision=2):
# log2 is a float, while range checking requires an int
exponent = int(log2(bytes))
+ if exponent < int_below_exponent:
+ precision = 0
if exponent < 10:
value = bytes