mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 09:35:54 +02:00
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 <jan@janware.com>
This commit is contained in:
parent
bdb6ae69b3
commit
26e739ca0d
2 changed files with 15 additions and 6 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue