Merge ~jocave/plainbox-provider-checkbox:fix-network-device-info into plainbox-provider-checkbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 16b6db9080236d8a2ed012f1d7834699dfb4561a
Merged at revision: 2446e00bd77666346cc30e710302633171c49565
Proposed branch: ~jocave/plainbox-provider-checkbox:fix-network-device-info
Merge into: plainbox-provider-checkbox:master
Diff against target: 107 lines (+20/-35)
3 files modified
bin/network_device_info.py (+4/-6)
bin/touchpad_confidence_bit.py (+4/-6)
bin/touchpad_driver_info.py (+12/-23)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+415628@code.launchpad.net

Description of the change

Further fixes in response to the UdevadmParser change in checkbox-support

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Thank you for getting rid of that unnecessary stateful thingy.
The code you modified calls for some touchups, but let's land what's here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/network_device_info.py b/bin/network_device_info.py
2index bba546b..bf9362c 100755
3--- a/bin/network_device_info.py
4+++ b/bin/network_device_info.py
5@@ -307,12 +307,10 @@ class UdevDevices():
6 sys.stderr.write(err)
7 return
8 udev = UdevadmParser(output)
9- udev.run(self)
10-
11- def addDevice(self, device):
12- """Callback for UdevadmParser"""
13- if device.category == self.category and device.interface != 'UNKNOWN':
14- self._devices.append(device)
15+ for device in udev.run():
16+ if (device.category == self.category and
17+ device.interface != 'UNKNOWN'):
18+ self._devices.append(device)
19
20 def devices(self):
21 """Convert to list of NetworkDevice with UDev derived attrs set"""
22diff --git a/bin/touchpad_confidence_bit.py b/bin/touchpad_confidence_bit.py
23index 5f94bb9..ff47e6d 100755
24--- a/bin/touchpad_confidence_bit.py
25+++ b/bin/touchpad_confidence_bit.py
26@@ -19,12 +19,10 @@ class TouchpadDevices:
27 sys.stderr.write(err)
28 return
29 udev = UdevadmParser(output)
30- udev.run(self)
31-
32- def addDevice(self, device):
33- if getattr(device, 'category') == 'TOUCHPAD':
34- self.devices[getattr(device, 'product_slug')
35- ] = getattr(device, 'path')
36+ for device in udev.run():
37+ if getattr(device, 'category') == 'TOUCHPAD':
38+ self.devices[getattr(device, 'product_slug')
39+ ] = getattr(device, 'path')
40
41
42 def main():
43diff --git a/bin/touchpad_driver_info.py b/bin/touchpad_driver_info.py
44index 9f6278f..c1c3459 100755
45--- a/bin/touchpad_driver_info.py
46+++ b/bin/touchpad_driver_info.py
47@@ -6,19 +6,6 @@ from subprocess import Popen, PIPE, check_output, STDOUT, CalledProcessError
48 from checkbox_support.parsers.udevadm import UdevadmParser
49 from checkbox_support.parsers.modinfo import ModinfoParser
50
51-# Command to retrieve udev information.
52-COMMAND = 'udevadm info --export-db'
53-
54-
55-class TouchResult:
56-
57- attributes = {}
58-
59- def addDevice(self, device):
60- if getattr(device, 'category') == 'TOUCHPAD':
61- self.attributes['driver'] = getattr(device, 'driver')
62- self.attributes['product'] = getattr(device, 'product')
63-
64
65 class TouchpadDriver():
66
67@@ -48,18 +35,20 @@ class TouchpadDriver():
68
69
70 def get_touch_attributes():
71- output, err = Popen(COMMAND, stdout=PIPE, shell=True).communicate()
72+ cmd = 'udevadm info --export-db'
73+ output, err = Popen(cmd, stdout=PIPE, shell=True).communicate()
74 if err:
75- print("Error running $s" % ' '.join(COMMAND))
76+ print("Error running $s" % ' '.join(cmd))
77 print(err)
78 return None
79
80 udev = UdevadmParser(StringIO(output.decode("unicode-escape")))
81-
82- result = TouchResult()
83- udev.run(result)
84-
85- return result.attributes
86+ attributes = {}
87+ for device in udev.run():
88+ if getattr(device, 'category') == 'TOUCHPAD':
89+ attributes['driver'] = getattr(device, 'driver')
90+ attributes['product'] = getattr(device, 'product')
91+ return attributes
92
93
94 def main():
95@@ -68,9 +57,9 @@ def main():
96 modinfo = TouchpadDriver(attributes['driver'])
97 attributes['version'] = modinfo.driver_version
98 print("%s: %s\n%s: %s\n%s: %s\n" % (
99- 'Device', attributes['product'],
100- 'Driver', attributes['driver'],
101- 'Driver Version', attributes['version']))
102+ 'Device', attributes['product'],
103+ 'Driver', attributes['driver'],
104+ 'Driver Version', attributes['version']))
105 else:
106 print("No Touchpad Detected")
107 return 1

Subscribers

People subscribed via source and target branches