diff --git a/utils_lib/os.py b/utils_lib/os.py new file mode 100644 index 0000000000000000000000000000000000000000..5cc6ee8dd071615d5a5fc05e8a73f33a0b008fad --- /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