From 513a517b5054ce24946698e05c105e88bc089338 Mon Sep 17 00:00:00 2001 From: Nicolas KAROLAK <nicolas@karolak.fr> Date: Fri, 18 Oct 2019 15:30:25 +0000 Subject: [PATCH] split system utils functions --- utils_lib/os.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 utils_lib/os.py diff --git a/utils_lib/os.py b/utils_lib/os.py new file mode 100644 index 00000000..5cc6ee8d --- /dev/null +++ b/utils_lib/os.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +"""System utils.""" + +from configparser import ConfigParser + +SUPPORTED_PLATFORMS = (("debian", "10"), ("ubuntu", "18.04")) + + +def dist() -> tuple: + """Return distribution name and version). + + :return: Distribution name and version + :rtype: tuple + """ + + parser = ConfigParser() + with open("/etc/os-release") as os_release: + parser.read_string("[os]\n{}".format(os_release.read())) + + return (parser["os"]["ID"], parser["os"]["VERSION_ID"].strip('"')) + + +def supported_platform() -> bool: + """Let you know if the current platform is supported. + + :return: Wether the platform is supported or not + :rtype: bool + """ + + return dist() in SUPPORTED_PLATFORMS -- GitLab