gracefully return "undefined" if DMI is not in sysfs (#3771)

* gracefully return "undefined" if DMI is not in sysfs

fixes #3770, in theory

* None works too and is consistent with other behaviour

* None doesn't *just* work
This commit is contained in:
Dee 2025-09-08 13:51:28 +03:00 committed by GitHub
parent bca3f4b660
commit 1ef52f56cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 6 deletions

View File

@ -239,14 +239,20 @@ class SysInfo:
return _sys_info.cpu_info.get('model name', None)
@staticmethod
def sys_vendor() -> str:
with open('/sys/devices/virtual/dmi/id/sys_vendor') as vendor:
return vendor.read().strip()
def sys_vendor() -> str | None:
try:
with open('/sys/devices/virtual/dmi/id/sys_vendor') as vendor:
return vendor.read().strip()
except FileNotFoundError:
return None
@staticmethod
def product_name() -> str:
with open('/sys/devices/virtual/dmi/id/product_name') as product:
return product.read().strip()
def product_name() -> str | None:
try:
with open('/sys/devices/virtual/dmi/id/product_name') as product:
return product.read().strip()
except FileNotFoundError:
return None
@staticmethod
def mem_available() -> int: