Rewritten detectOSRelease() to pull values from dict
This commit is contained in:
parent
4eb3a00625
commit
e92a85e1c5
|
@ -28,6 +28,14 @@ logger = logging.getLogger('both')
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
logger.setLevel(logging.ERROR)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
|
OS_RELEASE = {
|
||||||
|
"fedora": "Fedora",
|
||||||
|
"opensuse": "openSUSE",
|
||||||
|
"ubuntu": "Ubuntu",
|
||||||
|
"gentoo": "Gentoo",
|
||||||
|
"calculate": "Gentoo"
|
||||||
|
}
|
||||||
|
|
||||||
PACKAGE_MANAGER = {
|
PACKAGE_MANAGER = {
|
||||||
"OpenBSD": "pkg_add",
|
"OpenBSD": "pkg_add",
|
||||||
"FreeBSD": "pkg install",
|
"FreeBSD": "pkg install",
|
||||||
|
@ -128,20 +136,9 @@ def detectOSRelease():
|
||||||
version = None
|
version = None
|
||||||
for line in osRelease:
|
for line in osRelease:
|
||||||
if line.startswith("NAME="):
|
if line.startswith("NAME="):
|
||||||
line = line.lower()
|
detectOS.result = OS_RELEASE.get(
|
||||||
if "fedora" in line:
|
line.split("=")[-1].strip().lower())
|
||||||
detectOS.result = "Fedora"
|
elif line.startswith("VERSION_ID="):
|
||||||
elif "opensuse" in line:
|
|
||||||
detectOS.result = "openSUSE"
|
|
||||||
elif "ubuntu" in line:
|
|
||||||
detectOS.result = "Ubuntu"
|
|
||||||
elif "debian" in line:
|
|
||||||
detectOS.result = "Debian"
|
|
||||||
elif "gentoo" in line or "calculate" in line:
|
|
||||||
detectOS.result = "Gentoo"
|
|
||||||
else:
|
|
||||||
detectOS.result = None
|
|
||||||
if line.startswith("VERSION_ID="):
|
|
||||||
try:
|
try:
|
||||||
version = float(line.split("=")[1].replace("\"", ""))
|
version = float(line.split("=")[1].replace("\"", ""))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user