diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-03-07 10:25:55 +0100 |
---|---|---|
committer | lupoDharkael <izhe@hotmail.es> | 2024-03-08 13:03:33 +0100 |
commit | f5501aac91704da4e9b6d7a67633b9e52b48bef7 (patch) | |
tree | 37971800428cdb4360fca06e12dd9c89dd5798cc /src/utils/probe.py | |
parent | 4d4171e45958a50f4317a5add8fdba297e0f3a83 (diff) |
utils: implement linux distro id detection
The OS probe logic must be able to check a distro programmatically,
add get_linux_distro_id to return an id whitout versioning.
Ensure the availability of 'ubuntu' when we need to ensure certain
features are only used with a supported system.
Diffstat (limited to 'src/utils/probe.py')
-rw-r--r-- | src/utils/probe.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/probe.py b/src/utils/probe.py index c6e3680..8c0e39a 100644 --- a/src/utils/probe.py +++ b/src/utils/probe.py @@ -112,6 +112,28 @@ def linux_is64bit(mountpoint): return True if bits == '64bit' else False return os.path.exists(lib64_path) +def get_linux_distro_id(mountpoint): + """ + Parses a os-release file and fetches the 'ID' key. + Check repository documentation at ./ogclient/os-release-ids.txt + for a list of the potential strings it might return. + If file or key are not found, then returns generic 'linux' string. + """ + osrelease = f'{mountpoint}/etc/os-release' + + try: + with open(osrelease, 'r') as f: + for line in f: + if line.find('=') == -1: + continue + key, value = line.split('=') + if key == 'ID': + value = value.replace('\n', '') + value = value.strip('"') + return value + except FileNotFoundError as e: + logging.error(f'os-release file not found at "{osrelease}"') + return 'linux' def cache_probe(): """ |