mirror of
https://github.com/certbot/certbot.git
synced 2026-06-13 18:50:20 -04:00
os-release parsing WIP
This commit is contained in:
parent
b347e9fba1
commit
c82a551e77
1 changed files with 48 additions and 0 deletions
|
|
@ -210,8 +210,56 @@ def safely_remove(path):
|
|||
|
||||
|
||||
def get_os_info():
|
||||
"""
|
||||
Get OS name and version
|
||||
|
||||
:returns: (os_name, os_version)
|
||||
:rtype: `tuple` of `str`
|
||||
"""
|
||||
|
||||
|
||||
def get_systemd_os_info():
|
||||
"""
|
||||
Parse systemd /etc/os-release for distribution information
|
||||
|
||||
:returns: (os_name, os_version)
|
||||
:rtype: `tuple` of `str`
|
||||
"""
|
||||
|
||||
os_name = _get_systemd_os_release_var("ID")
|
||||
os_version = _get_systemd_os_release_var("VERSION_ID")
|
||||
|
||||
return (os_name, os_version)
|
||||
|
||||
|
||||
def _get_systemd_os_release_var(varname):
|
||||
|
||||
OS_RELEASE_FILEPATH = "/etc/os-release"
|
||||
var_string = varname+"="
|
||||
if not os.path.isfile(OS_RELEASE_FILEPATH):
|
||||
return ""
|
||||
with open(OS_RELEASE_FILEPATH, 'r') as fh:
|
||||
contents = fh.readlines()
|
||||
|
||||
for line in contents:
|
||||
if line.strip().startswith(var_string):
|
||||
# Return the value of var, normalized
|
||||
return _normalize_string(line.strip()[len(var_string):])
|
||||
return ""
|
||||
|
||||
|
||||
def _normalize_string(orig):
|
||||
"""
|
||||
Helper function for _get_systemd_os_release_var() to remove quotes
|
||||
and whitespaces
|
||||
"""
|
||||
return orig.replace('"', '').replace("'", "").strip()
|
||||
|
||||
|
||||
def get_python_os_info():
|
||||
"""
|
||||
Get Operating System type/distribution and major version
|
||||
using python platform module
|
||||
|
||||
:returns: (os_name, os_version)
|
||||
:rtype: `tuple` of `str`
|
||||
|
|
|
|||
Loading…
Reference in a new issue