linux尝试从os中获取信息

This commit is contained in:
cppla
2026-02-28 14:10:35 +08:00
parent e903200d66
commit 23a620274d
+8 -5
View File
@@ -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: