diff options
author | Jonathan Cave <jonathan.cave@canonical.com> | 2019-08-20 13:40:40 +0100 |
---|---|---|
committer | Jonathan Cave <jonathan.cave@canonical.com> | 2019-08-20 13:40:40 +0100 |
commit | fd5b40c5aed8b91efc936a3b64a57f870e630ac1 (patch) | |
tree | ceb823fd9ca471fc2768475bb4e294e8e5afb7c9 /bin/dmi-sysfs-resource | |
parent | 138395d1929d606737168fd11182ec3cab717f66 (diff) |
bin: import all p-p-snappy scripts
Diffstat (limited to 'bin/dmi-sysfs-resource')
-rwxr-xr-x | bin/dmi-sysfs-resource | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/dmi-sysfs-resource b/bin/dmi-sysfs-resource new file mode 100755 index 0000000..6741030 --- /dev/null +++ b/bin/dmi-sysfs-resource @@ -0,0 +1,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() |