From bc354396e19331fd8ff9b18d5f42d796db687f76 Mon Sep 17 00:00:00 2001 From: Julianne Swinoga Date: Mon, 1 Jul 2024 11:00:50 -0400 Subject: [PATCH] MacOS platform detection --- OATFWGUI/anon_usage_data.py | 15 +++++++++++++++ OATFWGUI/platform_check.py | 3 +++ 2 files changed, 18 insertions(+) diff --git a/OATFWGUI/anon_usage_data.py b/OATFWGUI/anon_usage_data.py index 494bb57..cfbc66e 100644 --- a/OATFWGUI/anon_usage_data.py +++ b/OATFWGUI/anon_usage_data.py @@ -143,6 +143,7 @@ def get_computer_uuid() -> str: machine_id_fn = { PlatformEnum.WINDOWS: get_uuid_windows, PlatformEnum.LINUX: get_uuid_linux, + PlatformEnum.MACOS: get_uuid_macos, PlatformEnum.UNKNOWN: lambda: 'unknown platform', }.get(get_platform(), lambda: 'unknown, unhandled platform') machine_id_str = machine_id_fn() @@ -178,6 +179,20 @@ def get_uuid_linux() -> str: return machine_id_contents +def get_uuid_macos() -> str: + sub_proc = subprocess.run( + ['ioreg', + '-rd1', + '-c', + 'IOPlatformExpertDevice', + ], + capture_output=True) + if sub_proc.returncode != 0: + return 'unknown-macos' + ioreg_output = sub_proc.stdout.decode('UTF-8') + return windows_uuid + + def to_nearest_half(num: float) -> float: return round(num * 2, 0) / 2 diff --git a/OATFWGUI/platform_check.py b/OATFWGUI/platform_check.py index 8049c7e..2b7eb4a 100644 --- a/OATFWGUI/platform_check.py +++ b/OATFWGUI/platform_check.py @@ -9,6 +9,7 @@ class PlatformEnum(enum.Enum): LINUX = enum.auto() WINDOWS = enum.auto() + MACOS = enum.auto() UNKNOWN = enum.auto() @@ -25,6 +26,8 @@ def get_platform() -> PlatformEnum: platform_lookup = PlatformEnum.WINDOWS elif 'linux' in platform_str: platform_lookup = PlatformEnum.LINUX + elif 'darwin' in platform_str: + platform_lookup = PlatformEnum.MACOS else: platform_lookup = PlatformEnum.UNKNOWN platform_lookup_cache = platform_lookup # Cache return