From e446e2765b9848dee9b7c39e1dcbfe4a2f601d6f Mon Sep 17 00:00:00 2001 From: Ty Fiero Date: Sat, 10 Feb 2024 21:34:25 -0800 Subject: [PATCH] Added a get system message function to determine if its a raspberry pi --- OS/01/utils/get_system_info.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 OS/01/utils/get_system_info.py diff --git a/OS/01/utils/get_system_info.py b/OS/01/utils/get_system_info.py new file mode 100644 index 0000000..eeca56a --- /dev/null +++ b/OS/01/utils/get_system_info.py @@ -0,0 +1,38 @@ +import os +import platform + + +def get_system_info(): + system = platform.system() + + if system == "Linux": + # Attempt to identify specific Linux distribution + distro = "linux" # Default to generic 'linux' + try: + with open("/etc/os-release") as f: + os_release_info = f.read().lower() + if "ubuntu" in os_release_info: + return "raspberry-pi-ubuntu" + elif "raspbian" in os_release_info: + return "raspberry-pi-os" + except FileNotFoundError: + pass + + # Check for Raspberry Pi hardware + try: + with open("/proc/device-tree/model") as f: + model_info = f.read() + if "Raspberry Pi" in model_info: + if distro == "ubuntu": + return "raspberry-pi-ubuntu" + return "raspberry-pi" + except FileNotFoundError: + pass + + return distro + elif system == "Darwin": + return "darwin" + elif system == "Windows": + return "windows" + else: + return "unknown"