Return the OS X system version as a string
()
| 85 | _SYSTEM_VERSION = None |
| 86 | |
| 87 | def _get_system_version(): |
| 88 | """Return the OS X system version as a string""" |
| 89 | # Reading this plist is a documented way to get the system |
| 90 | # version (see the documentation for the Gestalt Manager) |
| 91 | # We avoid using platform.mac_ver to avoid possible bootstrap issues during |
| 92 | # the build of Python itself (distutils is used to build standard library |
| 93 | # extensions). |
| 94 | |
| 95 | global _SYSTEM_VERSION |
| 96 | |
| 97 | if _SYSTEM_VERSION is None: |
| 98 | _SYSTEM_VERSION = '' |
| 99 | try: |
| 100 | f = open('/System/Library/CoreServices/SystemVersion.plist', encoding="utf-8") |
| 101 | except OSError: |
| 102 | # We're on a plain darwin box, fall back to the default |
| 103 | # behaviour. |
| 104 | pass |
| 105 | else: |
| 106 | try: |
| 107 | m = re.search(r'<key>ProductUserVisibleVersion</key>\s*' |
| 108 | r'<string>(.*?)</string>', f.read()) |
| 109 | finally: |
| 110 | f.close() |
| 111 | if m is not None: |
| 112 | _SYSTEM_VERSION = '.'.join(m.group(1).split('.')[:2]) |
| 113 | # else: fall back to the default behaviour |
| 114 | |
| 115 | return _SYSTEM_VERSION |
| 116 | |
| 117 | _SYSTEM_VERSION_TUPLE = None |
| 118 | def _get_system_version_tuple(): |