summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2023-08-16 13:56:14 +0200
committerJose M. Guisado <jguisado@soleta.eu>2023-09-13 11:19:12 +0200
commita49988a22229e08eca600bf8ef06d04a9e7afa41 (patch)
tree222e11c7f65da3148822504d11bd761ea76321aa /src
parent8296ba9a518b0ce50002061c5f4746e081cea3fe (diff)
probe: add basic os family detection
Add a basic OS family enumeration: OSFamily. Add utility function that probes for an installed Linux or Windows system, returns the corresponding enum value, OSFamily.UNKNOWN otherwise.
Diffstat (limited to 'src')
-rw-r--r--src/utils/probe.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/probe.py b/src/utils/probe.py
index 796bf55..8c77bf9 100644
--- a/src/utils/probe.py
+++ b/src/utils/probe.py
@@ -10,10 +10,13 @@ import os
import subprocess
import platform
+from enum import Enum
from subprocess import PIPE
from src.utils.fs import find_mountpoint
+OSFamily = Enum('OSFamily', ['LINUX', 'WINDOWS', 'UNKNOWN'])
+
def getlinuxversion(osrelease):
"""
Parses a os-release file to fetch 'PRETTY_NAME' key.
@@ -115,6 +118,19 @@ def cache_probe():
stdout = proc_blkid.stdout.decode().strip()
return stdout
+
+def get_os_family(mountpoint):
+ winreghives = f'{mountpoint}/Windows/System32/'
+ osrelease = f'{mountpoint}/etc/os-release'
+
+ if os.path.exists(osrelease):
+ return OSFamily.LINUX
+ elif os.path.exists(winreghives):
+ return OSFamily.WINDOWS
+ else:
+ return OSFamily.UNKNOWN
+
+
def os_probe(mountpoint):
"""
Probes mountpoint for typical OS dependant files.