Merge ~jocave/plainbox-provider-checkbox:dmi-sys-deguac into plainbox-provider-checkbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 42cc6047e0a441908c25d8c1827d85cd5a15d236
Merged at revision: 4d86a1286815a7351f234107401abf0c65c7ee84
Proposed branch: ~jocave/plainbox-provider-checkbox:dmi-sys-deguac
Merge into: plainbox-provider-checkbox:master
Diff against target: 91 lines (+26/-29)
2 files modified
bin/dmi_sysfs_resource.py (+25/-28)
units/tpm/sysfs.pxu (+1/-1)
Reviewer Review Type Date Requested Status
Sheila Miguez (community) Approve
Review via email: mp+378737@code.launchpad.net

Description of the change

Continued effort to de-🥑 the provider, dmi-sysfs-resource.

To post a comment you must log in.
Revision history for this message
Sheila Miguez (codersquid) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/dmi-sysfs-resource b/bin/dmi_sysfs_resource.py
2similarity index 86%
3rename from bin/dmi-sysfs-resource
4rename to bin/dmi_sysfs_resource.py
5index 6741030..a098976 100755
6--- a/bin/dmi-sysfs-resource
7+++ b/bin/dmi_sysfs_resource.py
8@@ -1,46 +1,43 @@
9 #!/usr/bin/env python3
10-# Copyright 2015 Canonical Ltd.
11+# Copyright 2015-2020 Canonical Ltd.
12 # All rights reserved.
13 #
14 # Written by:
15 # Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
16+# Jonathan Cave <jonathan.cave@canonical.com>
17
18 """Collect information about all sysfs attributes related to DMI."""
19
20 import os
21
22-import guacamole
23+"""
24+Collect information about all sysfs attributes related to DMI.
25
26+This program reads all the readable files in /sys/class/dmi/id/ and
27+presents them a single RFC822 record.
28
29-class dmi_sysfs_resource(guacamole.Command):
30+@EPILOG@
31
32- """
33- Collect information about all sysfs attributes related to DMI.
34+Unreadable files (typically due to permissions) are silently skipped.
35+Please run this program as root if you wish to access various serial
36+numbers.
37+"""
38
39- This program reads all the readable files in /sys/class/dmi/id/ and
40- presents them a single RFC822 record.
41
42- @EPILOG@
43-
44- Unreadable files (typically due to permissions) are silently skipped.
45- Please run this program as root if you wish to access various serial
46- numbers.
47- """
48-
49- def invoked(self, ctx):
50- sysfs_root = '/sys/class/dmi/id/'
51- if not os.path.isdir(sysfs_root):
52- return
53- for dmi_attr in sorted(os.listdir(sysfs_root)):
54- dmi_filename = os.path.join(sysfs_root, dmi_attr)
55- if not os.path.isfile(dmi_filename):
56- continue
57- if not os.access(dmi_filename, os.R_OK):
58- continue
59- with open(dmi_filename, 'rt', encoding='utf-8') as stream:
60- dmi_data = stream.read().strip()
61- print("{}: {}".format(dmi_attr, dmi_data))
62+def main():
63+ sysfs_root = '/sys/class/dmi/id/'
64+ if not os.path.isdir(sysfs_root):
65+ return
66+ for dmi_attr in sorted(os.listdir(sysfs_root)):
67+ dmi_filename = os.path.join(sysfs_root, dmi_attr)
68+ if not os.path.isfile(dmi_filename):
69+ continue
70+ if not os.access(dmi_filename, os.R_OK):
71+ continue
72+ with open(dmi_filename, 'rt', encoding='utf-8') as stream:
73+ dmi_data = stream.read().strip()
74+ print("{}: {}".format(dmi_attr, dmi_data))
75
76
77 if __name__ == "__main__":
78- dmi_sysfs_resource().main()
79+ main()
80diff --git a/units/tpm/sysfs.pxu b/units/tpm/sysfs.pxu
81index fdbf390..a0c75dd 100644
82--- a/units/tpm/sysfs.pxu
83+++ b/units/tpm/sysfs.pxu
84@@ -76,6 +76,6 @@ _description:
85 This job collects all the available DMI information from /sys/class/dmi/id/*.
86 The main purpose of including this job is to allow the provider to include
87 vendor-specific quirks by looking at the sysfs_dmi.bios_vendor attribute.
88-command: dmi-sysfs-resource
89+command: dmi_sysfs_resource.py
90 estimated_duration: 1s
91 flags: preserve-locale

Subscribers

People subscribed via source and target branches