mirror of
https://github.com//cppla/ServerStatus
synced 2026-06-22 05:36:09 +08:00
linux尝试从os中获取信息
This commit is contained in:
@@ -521,13 +521,16 @@ if __name__ == '__main__':
|
|||||||
elif 'bsd' in sysname:
|
elif 'bsd' in sysname:
|
||||||
os_name = 'bsd'
|
os_name = 'bsd'
|
||||||
elif sysname.startswith('linux'):
|
elif sysname.startswith('linux'):
|
||||||
# try distro if available
|
# try distro from os-release
|
||||||
os_name = 'linux'
|
|
||||||
try:
|
try:
|
||||||
import distro # optional
|
with open('/etc/os-release') as f:
|
||||||
os_name = distro.id() or 'linux'
|
for line in f:
|
||||||
|
if line.startswith('ID='):
|
||||||
|
val = line.strip().split('=',1)[1].strip().strip('"')
|
||||||
|
if val: os_name = val
|
||||||
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
os_name = 'linux'
|
||||||
else:
|
else:
|
||||||
os_name = sysname or 'unknown'
|
os_name = sysname or 'unknown'
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user