%PDF- %PDF-
| Direktori : /proc/self/root/usr/share/lve/modlscapi/user/ |
| Current File : //proc/self/root/usr/share/lve/modlscapi/user/common.py |
import configparser
def get_os_version():
"""
Detect system name and version
:return: tuple (os_name, os_ver)
"""
# # cat /etc/os-release | grep -E '^NAME|^VERSION_ID'
# NAME="Ubuntu"
# VERSION_ID="20.04"
# # cat /etc/os-release | grep -E '^NAME|^VERSION_ID'
# NAME="CloudLinux"
# VERSION_ID="7.9"
try:
os_release_filename = '/etc/os-release'
section_name = 'top'
config = configparser.ConfigParser()
# config.read('/etc/os-release')
with open(os_release_filename) as stream:
config.read_string(f"[{section_name}]\n" + stream.read())
os_name = config.get(section_name, 'NAME').strip('"')
os_ver = config.get(section_name, 'VERSION_ID').strip('"')
return os_name, os_ver
except (OSError, IOError, configparser.Error):
pass
return None, None
def is_ubuntu() -> bool:
"""
Detertmines is this system Ubuntu
:return: bool flag is_ubuntu
"""
os_name, _ = get_os_version()
return os_name == 'Ubuntu'