MCPcopy Create free account
hub / github.com/certbot/certbot / get_python_os_info

Function get_python_os_info

certbot/src/certbot/util.py:466–517  ·  view source on GitHub ↗

Get Operating System type/distribution and major version using python platform module :param bool pretty: If the returned OS name should be in longer (pretty) form :returns: (os_name, os_version) :rtype: `tuple` of `str`

(pretty: bool = False)

Source from the content-addressed store, hash-verified

464 return orig.replace('"', '').replace("'", "").strip()
465
466def get_python_os_info(pretty: bool = False) -> tuple[str, str]:
467 """
468 Get Operating System type/distribution and major version
469 using python platform module
470
471 :param bool pretty: If the returned OS name should be in longer (pretty) form
472
473 :returns: (os_name, os_version)
474 :rtype: `tuple` of `str`
475 """
476 info = platform.system_alias(
477 platform.system(),
478 platform.release(),
479 platform.version()
480 )
481 os_type, os_ver, _ = info
482 os_type = os_type.lower()
483 if os_type.startswith('linux') and _USE_DISTRO:
484 distro_name, distro_version = distro.name() if pretty else distro.id(), distro.version()
485 # On arch, these values are reportedly empty strings so handle it
486 # defensively
487 # so handle it defensively
488 if distro_name:
489 os_type = distro_name
490 if distro_version:
491 os_ver = distro_version
492 elif os_type.startswith('darwin'):
493 try:
494 proc = subprocess.run(
495 ["/usr/bin/sw_vers", "-productVersion"],
496 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
497 check=False, universal_newlines=True,
498 env=env_no_snap_for_external_calls(),
499 )
500 except OSError:
501 proc = subprocess.run(
502 ["sw_vers", "-productVersion"],
503 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
504 check=False, universal_newlines=True,
505 env=env_no_snap_for_external_calls(),
506 )
507 os_ver = proc.stdout.rstrip('\n')
508 elif os_type.startswith('freebsd'):
509 # eg "9.3-RC3-p1"
510 os_ver = os_ver.partition("-")[0]
511 os_ver = os_ver.partition(".")[0]
512 elif platform.win32_ver()[1]:
513 os_ver = platform.win32_ver()[1]
514 else:
515 # Cases known to fall here: Cygwin python
516 os_ver = ''
517 return os_type, os_ver
518
519# Just make sure we don't get pwned... Make sure that it also doesn't
520# start with a period or have two consecutive periods <- this needs to

Callers 2

get_os_infoFunction · 0.85
get_os_info_uaFunction · 0.85

Calls 4

versionMethod · 0.80
runMethod · 0.80
releaseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…