-
Notifications
You must be signed in to change notification settings - Fork 0
/
operating_system.py
35 lines (33 loc) · 1.14 KB
/
operating_system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import os
def get_os():
if os.path.exists('/etc/debian_version'):
return "debian"
if os.path.exists('/etc/redhat-release'):
return "rhel"
if os.path.exists('/etc/SuSE-release'):
return "sles"
os_file = None
if os.path.exists('/etc/os-release'):
os_file = "/etc/os-release"
elif os.path.exists('/usr/lib/os-release'):
os_file = '/usr/lib/os-release'
if os_file:
with open('/etc/os-release') as operating_system:
for line in operating_system:
if "ID_LIKE" in line:
if "debian" in line:
return "debian"
if "rhel" in line:
return "rhel"
if "sles" in line:
return "sles"
if "ID" in line:
if "rhel" in line:
return "rhel"
if "debian" in line:
return "debian"
if "sles" in line:
return "sles"
raise NotImplemented("Unable to determine OS")
if __name__ == "__main__":
print get_os()