summaryrefslogtreecommitdiff
path: root/python/vyos/system
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2023-12-18 12:33:27 -0600
committerGitHub <noreply@github.com>2023-12-18 12:33:27 -0600
commit33225eebde7ebcde84517f14077f5e61578f7231 (patch)
tree2490dbf2777b1aaad7a1ca443d1df3872e384661 /python/vyos/system
parentd3f0d65c54e95e0fba3c11083f3bd80bf6df5c53 (diff)
parent4ab72043bc0bf91e6c3e7c4d7c51950872bae677 (diff)
downloadvyos-1x-33225eebde7ebcde84517f14077f5e61578f7231.tar.gz
vyos-1x-33225eebde7ebcde84517f14077f5e61578f7231.zip
Merge pull request #2654 from vyos/mergify/bp/sagitta/pr-2649
image-tools: T5831: show system image reverse ordered by date (backport #2649)
Diffstat (limited to 'python/vyos/system')
-rw-r--r--python/vyos/system/grub.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/python/vyos/system/grub.py b/python/vyos/system/grub.py
index 4ebf229a0..61a9c7749 100644
--- a/python/vyos/system/grub.py
+++ b/python/vyos/system/grub.py
@@ -19,7 +19,7 @@ from typing import Union
from uuid import uuid5, NAMESPACE_URL, UUID
from vyos.template import render
-from vyos.utils.process import cmd
+from vyos.utils.process import cmd, rc_cmd
from vyos.system import disk
# Define variables
@@ -131,14 +131,22 @@ def version_list(root_dir: str = '') -> list[str]:
Returns:
list: A list with versions names
+
+ N.B. coreutils stat reports st_birthtime, but not available in
+ Path.stat()/os.stat()
"""
if not root_dir:
root_dir = disk.find_persistence()
versions_files = Path(f'{root_dir}/{GRUB_DIR_VYOS_VERS}').glob('*.cfg')
- versions_list: list[str] = []
+ versions_order: dict[str, int] = {}
for file in versions_files:
- versions_list.append(file.stem)
- versions_list.sort()
+ p = Path(root_dir).joinpath('boot').joinpath(file.stem)
+ command = f'stat -c %W {p.as_posix()}'
+ rc, out = rc_cmd(command)
+ if rc == 0:
+ versions_order[file.stem] = int(out)
+ versions_order = sorted(versions_order, key=versions_order.get, reverse=True)
+ versions_list: list[str] = list(versions_order)
return versions_list