summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-10-20 23:47:20 -0500
committerJohn Estabrook <jestabro@vyos.io>2023-11-15 11:29:04 -0600
commit8efab9ee8cdb0e65dddb9d3ba97de8ddcf3666dc (patch)
tree955d57ceef4fb18ff8028bf54652361817d77b4c
parentfcded7930b5426193e8490c6df2a70e300a60e31 (diff)
downloadvyos-1x-8efab9ee8cdb0e65dddb9d3ba97de8ddcf3666dc.tar.gz
vyos-1x-8efab9ee8cdb0e65dddb9d3ba97de8ddcf3666dc.zip
image: T4516: improve format of 'show system image details'
-rw-r--r--python/vyos/utils/convert.py5
-rwxr-xr-xsrc/op_mode/image_info.py14
2 files changed, 13 insertions, 6 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
diff --git a/src/op_mode/image_info.py b/src/op_mode/image_info.py
index ae0677196..14dca7476 100755
--- a/src/op_mode/image_info.py
+++ b/src/op_mode/image_info.py
@@ -20,11 +20,11 @@
import sys
from typing import List, Union
-from hurry.filesize import size
from tabulate import tabulate
from vyos import opmode
from vyos.system import disk, grub, image
+from vyos.utils.convert import bytes_to_human
def _format_show_images_summary(images_summary: image.BootDetails) -> str:
@@ -58,11 +58,15 @@ def _format_show_images_details(
for image_item in images_details:
name: str = image_item.get('name')
version: str = image_item.get('version')
- disk_ro: int = size(image_item.get('disk_ro'))
- disk_rw: int = size(image_item.get('disk_rw'))
- disk_total: int = size(image_item.get('disk_total'))
+ disk_ro: str = bytes_to_human(image_item.get('disk_ro'),
+ precision=1, int_below_exponent=30)
+ disk_rw: str = bytes_to_human(image_item.get('disk_rw'),
+ precision=1, int_below_exponent=30)
+ disk_total: str = bytes_to_human(image_item.get('disk_total'),
+ precision=1, int_below_exponent=30)
table_data.append([name, version, disk_ro, disk_rw, disk_total])
- tabulated: str = tabulate(table_data, headers)
+ tabulated: str = tabulate(table_data, headers,
+ colalign=('left', 'left', 'right', 'right', 'right'))
return tabulated