Skip to content

Commit

Permalink
Merge pull request #52 from OpenAstroTech/feature/js/macos-platform-d…
Browse files Browse the repository at this point in the history
…etection

MacOS platform detection
  • Loading branch information
julianneswinoga authored Jul 1, 2024
2 parents 09623d9 + bc35439 commit 8435efe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions OATFWGUI/anon_usage_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions OATFWGUI/platform_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class PlatformEnum(enum.Enum):
LINUX = enum.auto()
WINDOWS = enum.auto()
MACOS = enum.auto()
UNKNOWN = enum.auto()


Expand All @@ -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
Expand Down

0 comments on commit 8435efe

Please sign in to comment.