"""SystemVersion — OS and platform detection. Ported from net.i2p.util.SystemVersion. """ import os import platform import struct import sys class SystemVersion: """Static utilities for detecting OS, architecture, and capabilities.""" @staticmethod def get_os() -> str: s = platform.system().lower() if s == "darwin": return "mac" if s.startswith("win"): return "windows" return s # "linux", "freebsd", etc. @staticmethod def get_arch() -> str: machine = platform.machine().lower() if machine in ("x86_64", "amd64"): return "amd64" if machine in ("aarch64", "arm64"): return "arm64" if machine.startswith("arm"): return "arm" if machine in ("i386", "i686", "x86"): return "386" return "unknown" @staticmethod def is_windows() -> bool: return platform.system().lower().startswith("win") @staticmethod def is_mac() -> bool: return platform.system().lower() == "darwin" @staticmethod def is_linux() -> bool: return platform.system().lower() == "linux" @staticmethod def is_android() -> bool: return False # Not applicable in CPython @staticmethod def is_arm() -> bool: return SystemVersion.get_arch() in ("arm", "arm64") @staticmethod def is_x86() -> bool: return SystemVersion.get_arch() in ("amd64", "386") @staticmethod def is_64bit() -> bool: return struct.calcsize("P") * 8 == 64 @staticmethod def get_cores() -> int: return os.cpu_count() or 1 @staticmethod def get_max_memory() -> int: """Approximate max memory in bytes.""" try: import resource soft, hard = resource.getrlimit(resource.RLIMIT_AS) if hard > 0: return hard except (ImportError, ValueError): pass return 2 * 1024 * 1024 * 1024 # Default 2GB @staticmethod def is_slow() -> bool: return SystemVersion.get_arch() in ("arm",) @staticmethod def python_version() -> str: return platform.python_version()