From 26e739ca0d778b6170fa6b8211b31200a8df426a Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 15 Feb 2026 11:38:07 +0000 Subject: [PATCH] src.python.jw.pkg.App: Add property distro_id Add @property App.distro_id, returning the ID field of /etc/os-release. It is supposed to be the most specific part of the OS cascade. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/App.py | 12 ++++++++++++ src/python/jw/pkg/cmds/CmdDistro.py | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/python/jw/pkg/App.py b/src/python/jw/pkg/App.py index 4ede8d0a..6023b48f 100644 --- a/src/python/jw/pkg/App.py +++ b/src/python/jw/pkg/App.py @@ -210,6 +210,7 @@ class App(Base): # -- Members without default values self.__opt_os: str|None = None self.__top_name: str|None = None + self.__distro_id: str|None = None self.__os_cascade: list[str]|None = None self.__res_cache = ResultCache() self.__topdir: str|None = None @@ -251,6 +252,17 @@ class App(Base): def projs_root(self): return self.__projs_root + @property + def distro_id(self): + if self.__distro_id is None: + os_release = '/etc/os-release' + with open(os_release, 'r') as file: + m = re.search(r'^\s*ID\s*=\s*("?)([^"\n]+)\1\s*$', file.read(), re.MULTILINE) + if m is None: + raise Exception(f'Could not read "ID=" from "{os_release}"') + self.__distro_id = m.group(2) + return self.__distro_id + def find_dir(self, name: str, search_subdirs: list[str]=[], search_absdirs: list[str]=[], pretty: bool=True): return self.__find_dir(name, search_subdirs, search_absdirs, pretty) diff --git a/src/python/jw/pkg/cmds/CmdDistro.py b/src/python/jw/pkg/cmds/CmdDistro.py index c471ea20..6184c244 100644 --- a/src/python/jw/pkg/cmds/CmdDistro.py +++ b/src/python/jw/pkg/cmds/CmdDistro.py @@ -18,14 +18,11 @@ class CmdDistro(CmdBase): # export def distro_id(self): if self.__id is None: if self.app.args.id is not None: + # The distribution ID requested by the command line self.__id = self.app.args.id else: - os_release = '/etc/os-release' - with open(os_release, 'r') as file: - m = re.search(r'^\s*ID\s*=\s*("?)([^"\n]+)\1\s*$', file.read(), re.MULTILINE) - if m is None: - raise Exception(f'Could not read "ID=" from "{os_release}"') - self.__id = m.group(2) + # The ID of the distribution we run on + self.__id = self.app.distro_id return self.__id def add_arguments(self, p: ArgumentParser) -> None: