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
=== 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-22 09:13:14 +0000
@@ -503,6 +503,7 @@
503 devices = []503 devices = []
504 device = None504 device = None
505 line_number = 0505 line_number = 0
506 device_id = 0
506507
507 for line_number, line in enumerate(udev_data):508 for line_number, line in enumerate(udev_data):
508 if len(line) == 0:509 if len(line) == 0:
@@ -518,9 +519,11 @@
518519
519 key, value = record520 key, value = record
520 if device is None:521 if device is None:
522 device_id += 1
521 device = {523 device = {
522 'E': {},524 'E': {},
523 'S': [],525 'S': [],
526 'id': device_id,
524 }527 }
525 devices.append(device)528 devices.append(device)
526 # Some attribute lines have a space character after the529 # Some attribute lines have a space character after the
@@ -2776,6 +2779,11 @@
2776 return None2779 return None
2777 return controller2780 return controller
27782781
2782 @property
2783 def id(self):
2784 return self.udev['id']
2785
2786
2779class ProcessingLoop(object):2787class ProcessingLoop(object):
2780 """An `ITunableLoop` for processing HWDB submissions."""2788 """An `ITunableLoop` for processing HWDB submissions."""
27812789
27822790
=== 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-22 09:13:14 +0000
@@ -635,6 +635,7 @@
635 'MODALIAS': 'acpi:LNXSYSTM:',635 'MODALIAS': 'acpi:LNXSYSTM:',
636 },636 },
637 'S': [],637 'S': [],
638 'id': 1,
638 },639 },
639 {640 {
640 'P': '/devices/pci0000:00/0000:00:1a.0',641 'P': '/devices/pci0000:00/0000:00:1a.0',
@@ -643,6 +644,7 @@
643 'DEVPATH': '/devices/pci0000:00/0000:00:1a.0',644 'DEVPATH': '/devices/pci0000:00/0000:00:1a.0',
644 },645 },
645 'S': ['char/189:256'],646 'S': ['char/189:256'],
647 'id': 2,
646 },648 },
647 ],649 ],
648 result,650 result,
@@ -704,6 +706,7 @@
704 'E': {},706 'E': {},
705 'S': [],707 'S': [],
706 'W': '2',708 'W': '2',
709 'id': 1,
707 },710 },
708 ],711 ],
709 result,712 result,
710713
=== 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:13:14 +0000
@@ -3036,7 +3036,8 @@
3036 'DEVPATH': '/devices/LNXSYSTM:00',3036 'DEVPATH': '/devices/LNXSYSTM:00',
3037 'MODALIAS': 'acpi:LNXSYSTM:',3037 'MODALIAS': 'acpi:LNXSYSTM:',
3038 'SUBSYSTEM': 'acpi',3038 'SUBSYSTEM': 'acpi',
3039 }3039 },
3040 'id': 1,
3040 }3041 }
30413042
3042 self.root_device_dmi_data = {3043 self.root_device_dmi_data = {
@@ -3520,7 +3521,7 @@
3520 },3521 },
3521 }3522 }
35223523
3523 def test_device_id(self):3524 def test_device_device_id(self):
3524 """Test of UdevDevice.device_id."""3525 """Test of UdevDevice.device_id."""
3525 device = UdevDevice(None, self.pci_sata_controller)3526 device = UdevDevice(None, self.pci_sata_controller)
3526 self.assertEqual(3527 self.assertEqual(
@@ -4185,6 +4186,11 @@
4185 'provide bus, vendor ID, product ID or product name: None None '4186 'provide bus, vendor ID, product ID or product name: None None '
4186 'None None /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0')4187 'None None /devices/pci0000:00/0000:00:1d.7/usb1/1-1/1-1:1.0')
41874188
4189 def test_device_id(self):
4190 """Each UdevDevice has a property 'id'."""
4191 device = UdevDevice(None, self.root_device)
4192 self.assertEqual(1, device.id)
4193
41884194
4189class TestHWDBSubmissionTablePopulation(TestCaseHWDB):4195class TestHWDBSubmissionTablePopulation(TestCaseHWDB):
4190 """Tests of the HWDB popoluation with submitted data."""4196 """Tests of the HWDB popoluation with submitted data."""

Subscribers

People subscribed via source and target branches

to status/vote changes: