summaryrefslogtreecommitdiff
path: root/python/vyos/utils/convert.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-12-17 08:23:24 +0100
committerGitHub <noreply@github.com>2023-12-17 08:23:24 +0100
commitf991faab2c0d95cbec5d46996b154145955572d7 (patch)
tree7b6157e73946826cdb4128cf5100ba627934136d /python/vyos/utils/convert.py
parentd5375ce02376a91c07ec68f8d410a08dcdc57ef9 (diff)
parent8809d2e799ae1130b3328b081466b7d772a3da23 (diff)
downloadvyos-1x-f991faab2c0d95cbec5d46996b154145955572d7.tar.gz
vyos-1x-f991faab2c0d95cbec5d46996b154145955572d7.zip
Merge pull request #2648 from jestabro/sagitta-image-tools
image-tools: T4516: revise system image tools
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