Returns a single string identifying the underlying platform with as much useful information as possible (but no more :). The output is intended to be human readable rather than machine parseable. It may look different on different platforms and this is intended.
(aliased=False, terse=False)
| 1315 | _platform_cache = {} |
| 1316 | |
| 1317 | def platform(aliased=False, terse=False): |
| 1318 | |
| 1319 | """ Returns a single string identifying the underlying platform |
| 1320 | with as much useful information as possible (but no more :). |
| 1321 | |
| 1322 | The output is intended to be human readable rather than |
| 1323 | machine parseable. It may look different on different |
| 1324 | platforms and this is intended. |
| 1325 | |
| 1326 | If "aliased" is true, the function will use aliases for |
| 1327 | various platforms that report system names which differ from |
| 1328 | their common names, e.g. SunOS will be reported as |
| 1329 | Solaris. The system_alias() function is used to implement |
| 1330 | this. |
| 1331 | |
| 1332 | Setting terse to true causes the function to return only the |
| 1333 | absolute minimum information needed to identify the platform. |
| 1334 | |
| 1335 | """ |
| 1336 | result = _platform_cache.get((aliased, terse), None) |
| 1337 | if result is not None: |
| 1338 | return result |
| 1339 | |
| 1340 | # Get uname information and then apply platform specific cosmetics |
| 1341 | # to it... |
| 1342 | system, node, release, version, machine, processor = uname() |
| 1343 | if machine == processor: |
| 1344 | processor = '' |
| 1345 | if aliased: |
| 1346 | system, release, version = system_alias(system, release, version) |
| 1347 | |
| 1348 | if system == 'Darwin': |
| 1349 | # macOS and iOS both report as a "Darwin" kernel |
| 1350 | if sys.platform == "ios": |
| 1351 | system, release, _, _ = ios_ver() |
| 1352 | else: |
| 1353 | macos_release = mac_ver()[0] |
| 1354 | if macos_release: |
| 1355 | system = 'macOS' |
| 1356 | release = macos_release |
| 1357 | |
| 1358 | if system == 'Windows': |
| 1359 | # MS platforms |
| 1360 | rel, vers, csd, ptype = win32_ver(version) |
| 1361 | if terse: |
| 1362 | platform = _platform(system, release) |
| 1363 | else: |
| 1364 | platform = _platform(system, release, version, csd) |
| 1365 | |
| 1366 | elif system == 'Linux': |
| 1367 | # check for libc vs. glibc |
| 1368 | libcname, libcversion = libc_ver() |
| 1369 | platform = _platform(system, release, machine, processor, |
| 1370 | 'with', |
| 1371 | libcname+libcversion) |
| 1372 | elif system == 'Java': |
| 1373 | # Java platforms |
| 1374 | r, v, vminfo, (os_name, os_version, os_arch) = java_ver() |
no test coverage detected