blob: 67410307413ef4dad0eac48942cd3d0db22eb921 (
plain)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/usr/bin/env python3 # Copyright 2015 Canonical Ltd. # All rights reserved. # # Written by: # Zygmunt Krynicki <zygmunt.krynicki@canonical.com> """Collect information about all sysfs attributes related to DMI.""" import os import guacamole class dmi_sysfs_resource(guacamole.Command): """ Collect information about all sysfs attributes related to DMI. This program reads all the readable files in /sys/class/dmi/id/ and presents them a single RFC822 record. @EPILOG@ Unreadable files (typically due to permissions) are silently skipped. Please run this program as root if you wish to access various serial numbers. """ def invoked(self, ctx): sysfs_root = '/sys/class/dmi/id/' if not os.path.isdir(sysfs_root): return for dmi_attr in sorted(os.listdir(sysfs_root)): dmi_filename = os.path.join(sysfs_root, dmi_attr) if not os.path.isfile(dmi_filename): continue if not os.access(dmi_filename, os.R_OK): continue with open(dmi_filename, 'rt', encoding='utf-8') as stream: dmi_data = stream.read().strip() print("{}: {}".format(dmi_attr, dmi_data)) if __name__ == "__main__": dmi_sysfs_resource().main()
|