summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/configdep.py7
-rw-r--r--python/vyos/system/grub.py16
2 files changed, 19 insertions, 4 deletions
diff --git a/python/vyos/configdep.py b/python/vyos/configdep.py
index 8a28811eb..64727d355 100644
--- a/python/vyos/configdep.py
+++ b/python/vyos/configdep.py
@@ -107,6 +107,13 @@ def call_dependents():
f = l.pop(0)
f()
+def called_as_dependent() -> bool:
+ st = stack()[1:]
+ for f in st:
+ if f.filename == __file__:
+ return True
+ return False
+
def graph_from_dependency_dict(d: dict) -> dict:
g = {}
for k in list(d):
diff --git a/python/vyos/system/grub.py b/python/vyos/system/grub.py
index 763ccf983..a94729964 100644
--- a/python/vyos/system/grub.py
+++ b/python/vyos/system/grub.py
@@ -21,7 +21,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
@@ -139,14 +139,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(reverse=True)
+ 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