feat: add machine management and resolved device identity

This commit is contained in:
way
2026-09-27 21:20:44 +08:00
parent f0bef66651
commit 7befb325fb
3 changed files with 41 additions and 16 deletions
+16
View File
@@ -53,6 +53,22 @@ def device_details():
except Exception: pass
try: info["model"]=Path("/proc/device-tree/model").read_bytes().rstrip(b"\0").decode()
except Exception: pass
# Device tree identifies ARM boards; DMI covers PCs and many other vendors.
for key,files in {
"manufacturer":["/sys/class/dmi/id/sys_vendor"],
"model":["/sys/firmware/devicetree/base/model","/sys/class/dmi/id/product_name"],
"revision":["/sys/class/dmi/id/product_version","/sys/class/dmi/id/board_version"],
"serial":["/sys/class/dmi/id/product_serial"],
}.items():
if info.get(key):continue
for filename in files:
try:value=Path(filename).read_text().strip().strip("\0")
except (OSError,UnicodeError):continue
if value and value.lower() not in ("none","unknown","default string","to be filled by o.e.m."):
info[key]=value;break
if not info.get("manufacturer"):
try:info["manufacturer"]=Path("/sys/firmware/devicetree/base/compatible").read_bytes().split(b"\0")[0].decode().split(',')[0]
except (OSError,UnicodeError):pass
try:
os_release={}
for line in Path("/etc/os-release").read_text().splitlines():