Merge lp:~adeuring/launchpad/bug-457475-udev-device-id into lp:launchpad/db-devel

Proposed by Abel Deuring
Status: Merged
Approved by: Muharem Hrnjadovic
Approved revision: no longer in the source branch.
Merge reported by: Abel Deuring
Merged at revision: not available
Proposed branch: lp:~adeuring/launchpad/bug-457475-udev-device-id
Merge into: lp:launchpad/db-devel
Diff against target: 98 lines
3 files modified
lib/canonical/launchpad/scripts/hwdbsubmissions.py (+8/-0)
lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py (+3/-0)
lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py (+8/-2)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-457475-udev-device-id
Reviewer Review Type Date Requested Status
Muharem Hrnjadovic (community) Approve
Review via email: mp+13771@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

This branch adds a missing property "id" to class UdevDevice.

Class UdevDevice represents a device from a HWDB report containing udev data. Such reports are submitted by the HWDB client in Karmic, while oder client version send reports containig HAL data instead.

The XML structure for the HAL data is much more fine-grained than the XML structure for udev data: The HAL data contains one XML node for each HAL device, and each node has an attribute "id" with a unique integer value. This value is used to set the value HALDevice.id (class HALDevice is a "sibling" of class UdevDevice). The HWDB submission processing script takes/expectes the value HALDevice.id or UdevDevice.id, respectively and uses it to as the value of the column hal_device_id of new records of the table HWSubmissionDevice. (this table tells us that a given device appears in a given submission). Only problem is that a property UdevDevice.id did not exist yet...

The udev data is simply the output from running "udevadm info --export-db" and hence does not provide any simple integer ID for the devices. But it is easy to increment a counter when SubmissionParser._parserUdev() detects a new device and to store this number in the dictionary where _parseUdev() stores the data of a device.

This dictionary item can then be used as the value of the the property UdevDevice.id.

tests: ./bin/test --test=test_hwdb_submission_parser

Revision history for this message
Abel Deuring (adeuring) wrote :
Download full text (3.2 KiB)

Sorry, forgot to write a test for UdevDevice.id. Now added.

The diff of the complete changes is now:

=== modified file 'lib/canonical/launchpad/scripts/hwdbsubmissions.py'
--- lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-21 10:06:31 +0000
+++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-21 16:43:31 +0000
@@ -503,6 +503,7 @@
         devices = []
         device = None
         line_number = 0
+ device_id = 0

         for line_number, line in enumerate(udev_data):
             if len(line) == 0:
@@ -518,9 +519,11 @@

             key, value = record
             if device is None:
+ device_id += 1
                 device = {
                     'E': {},
                     'S': [],
+ 'id': device_id,
                     }
                 devices.append(device)
             # Some attribute lines have a space character after the
@@ -2776,6 +2779,11 @@
             return None
         return controller

+ @property
+ def id(self):
+ return self.udev['id']
+
+
 class ProcessingLoop(object):
     """An `ITunableLoop` for processing HWDB submissions."""

=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py'
--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-12 14:50:22 +0000
+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-21 16:47:04 +0000
@@ -635,6 +635,7 @@
                         'MODALIAS': 'acpi:LNXSYSTM:',
                         },
                     'S': [],
+ 'id': 1,
                     },
                 {
                     'P': '/devices/pci0000:00/0000:00:1a.0',
@@ -643,6 +644,7 @@
                         'DEVPATH': '/devices/pci0000:00/0000:00:1a.0',
                         },
                     'S': ['char/189:256'],
+ 'id': 2,
                     },
                 ],
             result,
@@ -704,6 +706,7 @@
                     'E': {},
                     'S': [],
                     'W': '2',
+ 'id': 1,
                     },
                 ],
             result,

=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py'
--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-21 10:06:31 +0000
+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-22 09:00:19 +0000
@@ -3036,7 +3036,8 @@
                 'DEVPATH': '/devices/LNXSYSTM:00',
                 'MODALIAS': 'acpi:LNXSYSTM:',
                 'SUBSYSTEM': 'acpi',
- }
+ },
+ 'id': 1,
             }

         self.root_device_dmi_data = {
@@ -4185,6 +4186,11 @@
             'provide bus, vendor ID, product ID or product name: None None '
             'None None /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0')

+ def test_device_id(self):
+ """Each UdevDevice has a property 'id'."""
+ device = UdevDevice(None, self.root_device)
+ self.assertEqual(1, device.id)
+

 class TestHWDBSubmissionTablePopulation(TestCaseHWDB):
     """Tests of the HWDB pop...

Read more...

Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

Looks good. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/scripts/hwdbsubmissions.py'
2--- lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-21 10:06:31 +0000
3+++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-22 09:13:14 +0000
4@@ -503,6 +503,7 @@
5 devices = []
6 device = None
7 line_number = 0
8+ device_id = 0
9
10 for line_number, line in enumerate(udev_data):
11 if len(line) == 0:
12@@ -518,9 +519,11 @@
13
14 key, value = record
15 if device is None:
16+ device_id += 1
17 device = {
18 'E': {},
19 'S': [],
20+ 'id': device_id,
21 }
22 devices.append(device)
23 # Some attribute lines have a space character after the
24@@ -2776,6 +2779,11 @@
25 return None
26 return controller
27
28+ @property
29+ def id(self):
30+ return self.udev['id']
31+
32+
33 class ProcessingLoop(object):
34 """An `ITunableLoop` for processing HWDB submissions."""
35
36
37=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py'
38--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-12 14:50:22 +0000
39+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-10-22 09:13:14 +0000
40@@ -635,6 +635,7 @@
41 'MODALIAS': 'acpi:LNXSYSTM:',
42 },
43 'S': [],
44+ 'id': 1,
45 },
46 {
47 'P': '/devices/pci0000:00/0000:00:1a.0',
48@@ -643,6 +644,7 @@
49 'DEVPATH': '/devices/pci0000:00/0000:00:1a.0',
50 },
51 'S': ['char/189:256'],
52+ 'id': 2,
53 },
54 ],
55 result,
56@@ -704,6 +706,7 @@
57 'E': {},
58 'S': [],
59 'W': '2',
60+ 'id': 1,
61 },
62 ],
63 result,
64
65=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py'
66--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-21 10:06:31 +0000
67+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-22 09:13:14 +0000
68@@ -3036,7 +3036,8 @@
69 'DEVPATH': '/devices/LNXSYSTM:00',
70 'MODALIAS': 'acpi:LNXSYSTM:',
71 'SUBSYSTEM': 'acpi',
72- }
73+ },
74+ 'id': 1,
75 }
76
77 self.root_device_dmi_data = {
78@@ -3520,7 +3521,7 @@
79 },
80 }
81
82- def test_device_id(self):
83+ def test_device_device_id(self):
84 """Test of UdevDevice.device_id."""
85 device = UdevDevice(None, self.pci_sata_controller)
86 self.assertEqual(
87@@ -4185,6 +4186,11 @@
88 'provide bus, vendor ID, product ID or product name: None None '
89 'None None /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0')
90
91+ def test_device_id(self):
92+ """Each UdevDevice has a property 'id'."""
93+ device = UdevDevice(None, self.root_device)
94+ self.assertEqual(1, device.id)
95+
96
97 class TestHWDBSubmissionTablePopulation(TestCaseHWDB):
98 """Tests of the HWDB popoluation with submitted data."""

Subscribers

People subscribed via source and target branches

to status/vote changes: