I want to make a python script that checks a user's machine form factor (laptop or desktop), and then I would be able to use conditions like that:
chassis_type = some_module.get_chassis_type()
if chassis_type == 'laptop':
print("You are out of luck, because you are using laptop.")
if chassis_type == 'desktop':
print("You are good to go, because you are using desktop.")
I do not want to check if battery is presented, but I want to use more generic way. Is there a way how can I achieve that using python?
There are several ways you can do this.
You can read this information from firmware using dmidecode module, but this requires permissions. Also, you can read
/sys/class/dmi/id/chassis_typefile directly and translate a number to a specified chassis string.But I currently use the following way:
This method relies on a standard systemd specification, which checks a firmware and also
/etc/machine-id.