Merge lp:~adeuring/launchpad/hwdb-refactor-haldevice-2 into lp:launchpad
- hwdb-refactor-haldevice-2
- Merge into devel
Proposed by
Abel Deuring
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~adeuring/launchpad/hwdb-refactor-haldevice-2 |
Merge into: | lp:launchpad |
Diff against target: |
435 lines 2 files modified
lib/canonical/launchpad/scripts/hwdbsubmissions.py (+140/-83) lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py (+82/-0) |
To merge this branch: | bzr merge lp:~adeuring/launchpad/hwdb-refactor-haldevice-2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Nelson (community) | code | Approve | |
Review via email: mp+12713@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote : | # |
Revision history for this message
Michael Nelson (michael.nelson) wrote : | # |
<noodles775> adeuring: gee, that's an unfortunate diff...
<adeuring> noodles775: why?
<noodles775> adeuring: Nothing wrong with your code, I jut meant the huge segment of HALDevice that diff has assumed has been deleted and added.
<adeuring> noodles775: Ah, OK.
<noodles775> adeuring: r=me
<adeuring> noodles775: thanks!
<noodles775> adeuring: did you try using the revision spec '-r x..y' with bzr send so that the colour-coded diff on the mp is just the revisions you want? If not, might be good for the third installment :)
review:
Approve
(code)
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-09-29 15:05:09 +0000 | |||
3 | +++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-10-01 11:20:32 +0000 | |||
4 | @@ -7,7 +7,7 @@ | |||
5 | 7 | data and for the community test submissions. | 7 | data and for the community test submissions. |
6 | 8 | """ | 8 | """ |
7 | 9 | 9 | ||
9 | 10 | 10 | __metaclass__ = type | |
10 | 11 | __all__ = [ | 11 | __all__ = [ |
11 | 12 | 'SubmissionParser', | 12 | 'SubmissionParser', |
12 | 13 | 'process_pending_submissions', | 13 | 'process_pending_submissions', |
13 | @@ -1235,59 +1235,30 @@ | |||
14 | 1235 | root_device.createDBData(submission, None) | 1235 | root_device.createDBData(submission, None) |
15 | 1236 | return True | 1236 | return True |
16 | 1237 | 1237 | ||
36 | 1238 | class HALDevice: | 1238 | |
37 | 1239 | """The representation of a HAL device node.""" | 1239 | class BaseDevice: |
38 | 1240 | 1240 | """A base class to represent device data from HAL and udev.""" | |
39 | 1241 | def __init__(self, id, udi, properties, parser): | 1241 | |
40 | 1242 | """HALDevice constructor. | 1242 | def __init__(self, parser): |
22 | 1243 | |||
23 | 1244 | :param id: The ID of the HAL device in the submission data as | ||
24 | 1245 | specified in <device id=...>. | ||
25 | 1246 | :type id: int | ||
26 | 1247 | :param udi: The UDI of the HAL device. | ||
27 | 1248 | :type udi: string | ||
28 | 1249 | :param properties: The HAL properties of the device. | ||
29 | 1250 | :type properties: dict | ||
30 | 1251 | :param parser: The parser processing a submission. | ||
31 | 1252 | :type parser: SubmissionParser | ||
32 | 1253 | """ | ||
33 | 1254 | self.id = id | ||
34 | 1255 | self.udi = udi | ||
35 | 1256 | self.properties = properties | ||
41 | 1257 | self.children = [] | 1243 | self.children = [] |
42 | 1258 | self.parser = parser | 1244 | self.parser = parser |
43 | 1259 | self.parent = None | 1245 | self.parent = None |
44 | 1260 | 1246 | ||
45 | 1247 | # Translation of the HAL info.bus/info.subsystem property and the | ||
46 | 1248 | # udev property SUBSYSTEM to HWBus enumerated buses. | ||
47 | 1249 | subsystem_hwbus = { | ||
48 | 1250 | 'pcmcia': HWBus.PCMCIA, | ||
49 | 1251 | 'usb_device': HWBus.USB, | ||
50 | 1252 | 'ide': HWBus.IDE, | ||
51 | 1253 | 'serio': HWBus.SERIAL, | ||
52 | 1254 | } | ||
53 | 1255 | |||
54 | 1261 | def addChild(self, child): | 1256 | def addChild(self, child): |
55 | 1262 | """Add a child device and set the child's parent.""" | 1257 | """Add a child device and set the child's parent.""" |
56 | 1263 | assert type(child) == type(self) | 1258 | assert type(child) == type(self) |
57 | 1264 | self.children.append(child) | 1259 | self.children.append(child) |
58 | 1265 | child.parent = self | 1260 | child.parent = self |
59 | 1266 | 1261 | ||
60 | 1267 | def getProperty(self, property_name): | ||
61 | 1268 | """Return the property property_name. | ||
62 | 1269 | |||
63 | 1270 | Note that there is no check of the property type. | ||
64 | 1271 | """ | ||
65 | 1272 | if property_name not in self.properties: | ||
66 | 1273 | return None | ||
67 | 1274 | name, type_ = self.properties[property_name] | ||
68 | 1275 | return name | ||
69 | 1276 | |||
70 | 1277 | @property | ||
71 | 1278 | def parent_udi(self): | ||
72 | 1279 | """The UDI of the parent device.""" | ||
73 | 1280 | return self.getProperty('info.parent') | ||
74 | 1281 | |||
75 | 1282 | # Translation of the HAL info.bus/info.subsystem property to HWBus | ||
76 | 1283 | # enumerated buses. | ||
77 | 1284 | hal_bus_hwbus = { | ||
78 | 1285 | 'pcmcia': HWBus.PCMCIA, | ||
79 | 1286 | 'usb_device': HWBus.USB, | ||
80 | 1287 | 'ide': HWBus.IDE, | ||
81 | 1288 | 'serio': HWBus.SERIAL, | ||
82 | 1289 | } | ||
83 | 1290 | |||
84 | 1291 | # Translation of subclasses of the PCI class storage to HWBus | 1262 | # Translation of subclasses of the PCI class storage to HWBus |
85 | 1292 | # enumerated buses. The Linux kernel accesses IDE and SATA disks | 1263 | # enumerated buses. The Linux kernel accesses IDE and SATA disks |
86 | 1293 | # and CDROM drives via the SCSI system; we want to know the real bus | 1264 | # and CDROM drives via the SCSI system; we want to know the real bus |
87 | @@ -1307,6 +1278,32 @@ | |||
88 | 1307 | 7: HWBus.SAS, | 1278 | 7: HWBus.SAS, |
89 | 1308 | } | 1279 | } |
90 | 1309 | 1280 | ||
91 | 1281 | @property | ||
92 | 1282 | def device_id(self): | ||
93 | 1283 | """A unique ID for this device.""" | ||
94 | 1284 | raise NotImplementedError() | ||
95 | 1285 | |||
96 | 1286 | @property | ||
97 | 1287 | def pci_class(self): | ||
98 | 1288 | """The PCI device class of the device or None for Non-PCI devices.""" | ||
99 | 1289 | raise NotImplementedError() | ||
100 | 1290 | |||
101 | 1291 | @property | ||
102 | 1292 | def pci_subclass(self): | ||
103 | 1293 | """The PCI device sub-class of the device or None for Non-PCI devices. | ||
104 | 1294 | """ | ||
105 | 1295 | raise NotImplementedError() | ||
106 | 1296 | |||
107 | 1297 | @property | ||
108 | 1298 | def usb_vendor_id(self): | ||
109 | 1299 | """The USB vendor ID of the device or None for Non-USB devices.""" | ||
110 | 1300 | raise NotImplementedError() | ||
111 | 1301 | |||
112 | 1302 | @property | ||
113 | 1303 | def usb_product_id(self): | ||
114 | 1304 | """The USB product ID of the device or None for Non-USB devices.""" | ||
115 | 1305 | raise NotImplementedError() | ||
116 | 1306 | |||
117 | 1310 | def translateScsiBus(self): | 1307 | def translateScsiBus(self): |
118 | 1311 | """Return the real bus of a device where raw_bus=='scsi'. | 1308 | """Return the real bus of a device where raw_bus=='scsi'. |
119 | 1312 | 1309 | ||
120 | @@ -1321,29 +1318,29 @@ | |||
121 | 1321 | parent = self.parent | 1318 | parent = self.parent |
122 | 1322 | if parent is None: | 1319 | if parent is None: |
123 | 1323 | self.parser._logWarning( | 1320 | self.parser._logWarning( |
125 | 1324 | 'Found SCSI device without a parent: %s.' % self.udi) | 1321 | 'Found SCSI device without a parent: %s.' % self.device_id) |
126 | 1325 | return None | 1322 | return None |
127 | 1326 | grandparent = parent.parent | 1323 | grandparent = parent.parent |
128 | 1327 | if grandparent is None: | 1324 | if grandparent is None: |
129 | 1328 | self.parser._logWarning( | 1325 | self.parser._logWarning( |
131 | 1329 | 'Found SCSI device without a grandparent: %s.' % self.udi) | 1326 | 'Found SCSI device without a grandparent: %s.' |
132 | 1327 | % self.device_id) | ||
133 | 1330 | return None | 1328 | return None |
134 | 1331 | 1329 | ||
135 | 1332 | grandparent_bus = grandparent.raw_bus | 1330 | grandparent_bus = grandparent.raw_bus |
136 | 1333 | if grandparent_bus == 'pci': | 1331 | if grandparent_bus == 'pci': |
139 | 1334 | if (grandparent.getProperty('pci.device_class') | 1332 | if (grandparent.pci_class != PCI_CLASS_STORAGE): |
138 | 1335 | != PCI_CLASS_STORAGE): | ||
140 | 1336 | # This is not a storage class PCI device? This | 1333 | # This is not a storage class PCI device? This |
141 | 1337 | # indicates a bug somewhere in HAL or in the hwdb | 1334 | # indicates a bug somewhere in HAL or in the hwdb |
142 | 1338 | # client, or a fake submission. | 1335 | # client, or a fake submission. |
144 | 1339 | device_class = grandparent.getProperty('pci.device_class') | 1336 | device_class = grandparent.pci_class |
145 | 1340 | self.parser._logWarning( | 1337 | self.parser._logWarning( |
146 | 1341 | 'A (possibly fake) SCSI device %s is connected to ' | 1338 | 'A (possibly fake) SCSI device %s is connected to ' |
147 | 1342 | 'PCI device %s that has the PCI device class %s; ' | 1339 | 'PCI device %s that has the PCI device class %s; ' |
148 | 1343 | 'expected class 1 (storage).' | 1340 | 'expected class 1 (storage).' |
150 | 1344 | % (self.udi, grandparent.udi, device_class)) | 1341 | % (self.device_id, grandparent.device_id, device_class)) |
151 | 1345 | return None | 1342 | return None |
153 | 1346 | pci_subclass = grandparent.getProperty('pci.device_subclass') | 1343 | pci_subclass = grandparent.pci_subclass |
154 | 1347 | return self.pci_storage_subclass_hwbus.get(pci_subclass) | 1344 | return self.pci_storage_subclass_hwbus.get(pci_subclass) |
155 | 1348 | elif grandparent_bus == 'usb': | 1345 | elif grandparent_bus == 'usb': |
156 | 1349 | # USB storage devices have the following HAL device hierarchy: | 1346 | # USB storage devices have the following HAL device hierarchy: |
157 | @@ -1395,38 +1392,18 @@ | |||
158 | 1395 | # subclass 7). | 1392 | # subclass 7). |
159 | 1396 | # XXX Abel Deuring 2005-05-14 How can we detect ExpressCards? | 1393 | # XXX Abel Deuring 2005-05-14 How can we detect ExpressCards? |
160 | 1397 | # I do not have any such card at present... | 1394 | # I do not have any such card at present... |
163 | 1398 | parent_class = self.parent.getProperty('pci.device_class') | 1395 | parent_class = self.parent.pci_class |
164 | 1399 | parent_subclass = self.parent.getProperty('pci.device_subclass') | 1396 | parent_subclass = self.parent.pci_subclass |
165 | 1400 | if (parent_class == PCI_CLASS_BRIDGE | 1397 | if (parent_class == PCI_CLASS_BRIDGE |
166 | 1401 | and parent_subclass == PCI_SUBCLASS_BRIDGE_CARDBUS): | 1398 | and parent_subclass == PCI_SUBCLASS_BRIDGE_CARDBUS): |
167 | 1402 | return HWBus.PCCARD | 1399 | return HWBus.PCCARD |
168 | 1403 | else: | 1400 | else: |
169 | 1404 | return HWBus.PCI | 1401 | return HWBus.PCI |
170 | 1405 | 1402 | ||
171 | 1406 | translate_bus_name = { | ||
172 | 1407 | 'pci': translatePciBus, | ||
173 | 1408 | 'scsi': translateScsiBus, | ||
174 | 1409 | } | ||
175 | 1410 | |||
176 | 1411 | @property | 1403 | @property |
177 | 1412 | def raw_bus(self): | 1404 | def raw_bus(self): |
195 | 1413 | """Return the device bus as specified by HAL. | 1405 | """Return the device bus as specified by HAL or udev.""" |
196 | 1414 | 1406 | raise NotImplementedError() | |
180 | 1415 | Older versions of HAL stored this value in the property | ||
181 | 1416 | info.bus; newer versions store it in info.subsystem. | ||
182 | 1417 | """ | ||
183 | 1418 | # Note that info.bus is gone for all devices except the | ||
184 | 1419 | # USB bus. For USB devices, the property info.bus returns more | ||
185 | 1420 | # detailed data: info.subsystem has the value 'usb' for all | ||
186 | 1421 | # HAL nodes belonging to USB devices, while info.bus has the | ||
187 | 1422 | # value 'usb_device' for the root node of a USB device, and the | ||
188 | 1423 | # value 'usb' for sub-nodes of a USB device. We use these | ||
189 | 1424 | # different value to to find the root USB device node, hence | ||
190 | 1425 | # try to read info.bus first. | ||
191 | 1426 | result = self.getProperty('info.bus') | ||
192 | 1427 | if result is not None: | ||
193 | 1428 | return result | ||
194 | 1429 | return self.getProperty('info.subsystem') | ||
197 | 1430 | 1407 | ||
198 | 1431 | @property | 1408 | @property |
199 | 1432 | def real_bus(self): | 1409 | def real_bus(self): |
200 | @@ -1436,7 +1413,7 @@ | |||
201 | 1436 | cannot be determined. | 1413 | cannot be determined. |
202 | 1437 | """ | 1414 | """ |
203 | 1438 | device_bus = self.raw_bus | 1415 | device_bus = self.raw_bus |
205 | 1439 | result = self.hal_bus_hwbus.get(device_bus) | 1416 | result = self.subsystem_hwbus.get(device_bus) |
206 | 1440 | if result is not None: | 1417 | if result is not None: |
207 | 1441 | return result | 1418 | return result |
208 | 1442 | 1419 | ||
209 | @@ -1588,7 +1565,7 @@ | |||
210 | 1588 | info.bus == 'usb' is used for end points of USB devices; | 1565 | info.bus == 'usb' is used for end points of USB devices; |
211 | 1589 | the root node of a USB device has info.bus == 'usb_device'. | 1566 | the root node of a USB device has info.bus == 'usb_device'. |
212 | 1590 | 1567 | ||
214 | 1591 | info.bus == 'viedo4linux' is used for the "input aspect" | 1568 | info.bus == 'video4linux' is used for the "input aspect" |
215 | 1592 | of video devices. | 1569 | of video devices. |
216 | 1593 | """ | 1570 | """ |
217 | 1594 | bus = self.raw_bus | 1571 | bus = self.raw_bus |
218 | @@ -1603,8 +1580,8 @@ | |||
219 | 1603 | # info.bus property that we treat as a real device. | 1580 | # info.bus property that we treat as a real device. |
220 | 1604 | return self.udi == ROOT_UDI | 1581 | return self.udi == ROOT_UDI |
221 | 1605 | elif bus == 'usb_device': | 1582 | elif bus == 'usb_device': |
224 | 1606 | vendor_id = self.getProperty('usb_device.vendor_id') | 1583 | vendor_id = self.usb_vendor_id |
225 | 1607 | product_id = self.getProperty('usb_device.product_id') | 1584 | product_id = self.usb_product_id |
226 | 1608 | if vendor_id == 0 and product_id == 0: | 1585 | if vendor_id == 0 and product_id == 0: |
227 | 1609 | # double-check: The parent device should be a PCI host | 1586 | # double-check: The parent device should be a PCI host |
228 | 1610 | # controller, identifiable by its device class and subclass. | 1587 | # controller, identifiable by its device class and subclass. |
229 | @@ -1612,8 +1589,8 @@ | |||
230 | 1612 | # possible bridges, like ISA->USB.. | 1589 | # possible bridges, like ISA->USB.. |
231 | 1613 | parent = self.parent | 1590 | parent = self.parent |
232 | 1614 | parent_bus = parent.raw_bus | 1591 | parent_bus = parent.raw_bus |
235 | 1615 | parent_class = parent.getProperty('pci.device_class') | 1592 | parent_class = parent.pci_class |
236 | 1616 | parent_subclass = parent.getProperty('pci.device_subclass') | 1593 | parent_subclass = parent.pci_subclass |
237 | 1617 | if (parent_bus == 'pci' | 1594 | if (parent_bus == 'pci' |
238 | 1618 | and parent_class == PCI_CLASS_SERIALBUS_CONTROLLER | 1595 | and parent_class == PCI_CLASS_SERIALBUS_CONTROLLER |
239 | 1619 | and parent_subclass == PCI_SUBCLASS_SERIALBUS_USB): | 1596 | and parent_subclass == PCI_SUBCLASS_SERIALBUS_USB): |
240 | @@ -1757,6 +1734,88 @@ | |||
241 | 1757 | return False | 1734 | return False |
242 | 1758 | return True | 1735 | return True |
243 | 1759 | 1736 | ||
244 | 1737 | |||
245 | 1738 | class HALDevice(BaseDevice): | ||
246 | 1739 | """The representation of a HAL device node.""" | ||
247 | 1740 | |||
248 | 1741 | def __init__(self, id, udi, properties, parser): | ||
249 | 1742 | """HALDevice constructor. | ||
250 | 1743 | |||
251 | 1744 | :param id: The ID of the HAL device in the submission data as | ||
252 | 1745 | specified in <device id=...>. | ||
253 | 1746 | :type id: int | ||
254 | 1747 | :param udi: The UDI of the HAL device. | ||
255 | 1748 | :type udi: string | ||
256 | 1749 | :param properties: The HAL properties of the device. | ||
257 | 1750 | :type properties: dict | ||
258 | 1751 | :param parser: The parser processing a submission. | ||
259 | 1752 | :type parser: SubmissionParser | ||
260 | 1753 | """ | ||
261 | 1754 | super(HALDevice, self).__init__(parser) | ||
262 | 1755 | self.id = id | ||
263 | 1756 | self.udi = udi | ||
264 | 1757 | self.properties = properties | ||
265 | 1758 | |||
266 | 1759 | def getProperty(self, property_name): | ||
267 | 1760 | """Return the HAL property property_name. | ||
268 | 1761 | |||
269 | 1762 | Note that there is no check of the property type. | ||
270 | 1763 | """ | ||
271 | 1764 | if property_name not in self.properties: | ||
272 | 1765 | return None | ||
273 | 1766 | name, type_ = self.properties[property_name] | ||
274 | 1767 | return name | ||
275 | 1768 | |||
276 | 1769 | @property | ||
277 | 1770 | def parent_udi(self): | ||
278 | 1771 | """The UDI of the parent device.""" | ||
279 | 1772 | return self.getProperty('info.parent') | ||
280 | 1773 | |||
281 | 1774 | @property | ||
282 | 1775 | def device_id(self): | ||
283 | 1776 | """See `BaseDevice`.""" | ||
284 | 1777 | return self.udi | ||
285 | 1778 | |||
286 | 1779 | @property | ||
287 | 1780 | def pci_class(self): | ||
288 | 1781 | """See `BaseDevice`.""" | ||
289 | 1782 | return self.getProperty('pci.device_class') | ||
290 | 1783 | |||
291 | 1784 | @property | ||
292 | 1785 | def pci_subclass(self): | ||
293 | 1786 | """The PCI device sub-class of the device or None for Non-PCI devices. | ||
294 | 1787 | """ | ||
295 | 1788 | return self.getProperty('pci.device_subclass') | ||
296 | 1789 | |||
297 | 1790 | @property | ||
298 | 1791 | def usb_vendor_id(self): | ||
299 | 1792 | """See `BaseDevice`.""" | ||
300 | 1793 | return self.getProperty('usb_device.vendor_id') | ||
301 | 1794 | |||
302 | 1795 | @property | ||
303 | 1796 | def usb_product_id(self): | ||
304 | 1797 | """See `BaseDevice`.""" | ||
305 | 1798 | return self.getProperty('usb_device.product_id') | ||
306 | 1799 | |||
307 | 1800 | @property | ||
308 | 1801 | def raw_bus(self): | ||
309 | 1802 | """See `BaseDevice`.""" | ||
310 | 1803 | # Older versions of HAL stored this value in the property | ||
311 | 1804 | # info.bus; newer versions store it in info.subsystem. | ||
312 | 1805 | # | ||
313 | 1806 | # Note that info.bus is gone for all devices except the | ||
314 | 1807 | # USB bus. For USB devices, the property info.bus returns more | ||
315 | 1808 | # detailed data: info.subsystem has the value 'usb' for all | ||
316 | 1809 | # HAL nodes belonging to USB devices, while info.bus has the | ||
317 | 1810 | # value 'usb_device' for the root node of a USB device, and the | ||
318 | 1811 | # value 'usb' for sub-nodes of a USB device. We use these | ||
319 | 1812 | # different value to to find the root USB device node, hence | ||
320 | 1813 | # try to read info.bus first. | ||
321 | 1814 | result = self.getProperty('info.bus') | ||
322 | 1815 | if result is not None: | ||
323 | 1816 | return result | ||
324 | 1817 | return self.getProperty('info.subsystem') | ||
325 | 1818 | |||
326 | 1760 | def getScsiVendorAndModelName(self): | 1819 | def getScsiVendorAndModelName(self): |
327 | 1761 | """Separate vendor and model name of SCSI decvices. | 1820 | """Separate vendor and model name of SCSI decvices. |
328 | 1762 | 1821 | ||
329 | @@ -1830,13 +1889,11 @@ | |||
330 | 1830 | """The vendor of this device.""" | 1889 | """The vendor of this device.""" |
331 | 1831 | return self.getVendorOrProduct('vendor') | 1890 | return self.getVendorOrProduct('vendor') |
332 | 1832 | 1891 | ||
333 | 1833 | |||
334 | 1834 | @property | 1892 | @property |
335 | 1835 | def product(self): | 1893 | def product(self): |
336 | 1836 | """The vendor of this device.""" | 1894 | """The vendor of this device.""" |
337 | 1837 | return self.getVendorOrProduct('product') | 1895 | return self.getVendorOrProduct('product') |
338 | 1838 | 1896 | ||
339 | 1839 | |||
340 | 1840 | def getVendorOrProductID(self, type_): | 1897 | def getVendorOrProductID(self, type_): |
341 | 1841 | """Return the vendor or product ID for this device. | 1898 | """Return the vendor or product ID for this device. |
342 | 1842 | 1899 | ||
343 | 1843 | 1900 | ||
344 | === modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py' | |||
345 | --- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-06-25 05:30:52 +0000 | |||
346 | +++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_processing.py 2009-10-01 11:20:32 +0000 | |||
347 | @@ -380,6 +380,88 @@ | |||
348 | 380 | 'Unexpected value of HALDevice.parent_udi, ' | 380 | 'Unexpected value of HALDevice.parent_udi, ' |
349 | 381 | 'when no parent information available.') | 381 | 'when no parent information available.') |
350 | 382 | 382 | ||
351 | 383 | def testHALDeviceDeviceId(self): | ||
352 | 384 | """Test of HALDevice.device_id.""" | ||
353 | 385 | properties = {} | ||
354 | 386 | parser = SubmissionParser(self.log) | ||
355 | 387 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
356 | 388 | self.assertEqual( | ||
357 | 389 | '/some/udi/path', device.device_id, | ||
358 | 390 | 'Unexpected value of HALDevice.device_id') | ||
359 | 391 | |||
360 | 392 | def testHALDevicePciClass(self): | ||
361 | 393 | """Test of HALDevice.pci_class.""" | ||
362 | 394 | properties = { | ||
363 | 395 | 'pci.device_class': (1, 'int'), | ||
364 | 396 | } | ||
365 | 397 | parser = SubmissionParser(self.log) | ||
366 | 398 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
367 | 399 | self.assertEqual( | ||
368 | 400 | 1, device.pci_class, | ||
369 | 401 | 'Unexpected value of HALDevice.pci_class.') | ||
370 | 402 | |||
371 | 403 | properties = {} | ||
372 | 404 | parser = SubmissionParser(self.log) | ||
373 | 405 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
374 | 406 | self.assertEqual( | ||
375 | 407 | None, device.pci_class, | ||
376 | 408 | 'Unexpected value of HALDevice.pci_class for Non-PCI device.') | ||
377 | 409 | |||
378 | 410 | def testHALDevicePciSubClass(self): | ||
379 | 411 | """Test of HALDevice.pci_subclass.""" | ||
380 | 412 | properties = { | ||
381 | 413 | 'pci.device_subclass': (1, 'int'), | ||
382 | 414 | } | ||
383 | 415 | parser = SubmissionParser(self.log) | ||
384 | 416 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
385 | 417 | self.assertEqual( | ||
386 | 418 | 1, device.pci_subclass, | ||
387 | 419 | 'Unexpected value of HALDevice.pci_subclass.') | ||
388 | 420 | |||
389 | 421 | properties = {} | ||
390 | 422 | parser = SubmissionParser(self.log) | ||
391 | 423 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
392 | 424 | self.assertEqual( | ||
393 | 425 | None, device.pci_subclass, | ||
394 | 426 | 'Unexpected value of HALDevice.pci_sub_class for Non-PCI device.') | ||
395 | 427 | |||
396 | 428 | def testHALDeviceUsbVendorId(self): | ||
397 | 429 | """Test of HALDevice.usb_vendor_id.""" | ||
398 | 430 | properties = { | ||
399 | 431 | 'usb_device.vendor_id': (1, 'int'), | ||
400 | 432 | } | ||
401 | 433 | parser = SubmissionParser(self.log) | ||
402 | 434 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
403 | 435 | self.assertEqual( | ||
404 | 436 | 1, device.usb_vendor_id, | ||
405 | 437 | 'Unexpected value of HALDevice.usb_vendor_id.') | ||
406 | 438 | |||
407 | 439 | properties = {} | ||
408 | 440 | parser = SubmissionParser(self.log) | ||
409 | 441 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
410 | 442 | self.assertEqual( | ||
411 | 443 | None, device.usb_vendor_id, | ||
412 | 444 | 'Unexpected value of HALDevice.usb_vendor_id for Non-USB device.') | ||
413 | 445 | |||
414 | 446 | def testHALDeviceUsbProductId(self): | ||
415 | 447 | """Test of HALDevice.usb_product_id.""" | ||
416 | 448 | properties = { | ||
417 | 449 | 'usb_device.product_id': (1, 'int'), | ||
418 | 450 | } | ||
419 | 451 | parser = SubmissionParser(self.log) | ||
420 | 452 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
421 | 453 | self.assertEqual( | ||
422 | 454 | 1, device.usb_product_id, | ||
423 | 455 | 'Unexpected value of HALDevice.usb_product_id.') | ||
424 | 456 | |||
425 | 457 | properties = {} | ||
426 | 458 | parser = SubmissionParser(self.log) | ||
427 | 459 | device = HALDevice(1, '/some/udi/path', properties, parser) | ||
428 | 460 | self.assertEqual( | ||
429 | 461 | None, device.usb_product_id, | ||
430 | 462 | 'Unexpected value of HALDevice.usb_product_id for Non-USB ' | ||
431 | 463 | 'device.') | ||
432 | 464 | |||
433 | 383 | def testHalDeviceRawBus(self): | 465 | def testHalDeviceRawBus(self): |
434 | 384 | """test of HALDevice.raw_bus.""" | 466 | """test of HALDevice.raw_bus.""" |
435 | 385 | properties = { | 467 | properties = { |
This branch continues the refactoring of class HALDevice in l/c/l/scrpits/ hwdbsubmissons. py
(see https:/ /code.edge. launchpad. net/~adeuring/ launchpad/ hwdb-refactor- haldevice/ +merge/ 12669)
It moves the properties real_bus and is_real_device into the new base class BaseDevice. The latter property needs access to the USB vendor/product IDs, which were retrieved by the HAL-specific mmethod getProperty(). These calls are replaced by the new properties usb_vendor_id and usb_product_id.
test: ./bin/test -t test_hwdb_ submission_ processing
= Launchpad lint =
Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.
Linting changed files: /launchpad/ scripts/ hwdbsubmissions .py /launchpad/ scripts/ tests/test_ hwdb_submission _processing. py
lib/canonical
lib/canonical
== Pyflakes notices ==
lib/canonical/ launchpad/ scripts/ hwdbsubmissions .py
22: redefinition of unused 'etree' from line 20
== Pylint notices ==
lib/canonical/ launchpad/ scripts/ hwdbsubmissions .py cElementTree' (No module named etree)
20: [F0401] Unable to import 'xml.etree.
These complaints are caused by another, unrelated, branch that prepares the transition to Python 2.5
diff against the base branch (still in ec2test):
=== modified file 'lib/canonical/ launchpad/ scripts/ hwdbsubmissions .py' launchpad/ scripts/ hwdbsubmissions .py 2009-10-01 09:06:59 +0000 launchpad/ scripts/ hwdbsubmissions .py 2009-10-01 11:13:38 +0000 rror()
--- lib/canonical/
+++ lib/canonical/
@@ -1294,6 +1294,16 @@
"""
raise NotImplementedE
+ @property id(self) : rror() id(self) : rror() s(self) :
+ def usb_vendor_
+ """The USB vendor ID of the device or None for Non-USB devices."""
+ raise NotImplementedE
+
+ @property
+ def usb_product_
+ """The USB product ID of the device or None for Non-USB devices."""
+ raise NotImplementedE
+
def translateScsiBu
"""Return the real bus of a device where raw_bus=='scsi'.
@@ -1395,78 +1405,6 @@ rror()
"""Return the device bus as specified by HAL or udev."""
raise NotImplementedE
- BaseDevice) : _init__ (parser) [property_ name]
-class HALDevice(
- """The representation of a HAL device node."""
-
- def __init__(self, id, udi, properties, parser):
- """HALDevice constructor.
-
- :param id: The ID of the HAL device in the submission data as
- specified in <device id=...>.
- :type id: int
- :param udi: The UDI of the HAL device.
- :type udi: string
- :param properties: The HAL properties of the device.
- :type properties: dict
- :param parser: The parser processing a submission.
- :type parser: SubmissionParser
- """
- super(HALDevice, self)._
- self.id = id
- self.udi = udi
- self.properties = properties
-
- def getProperty(self, property_name):
- """Return the HAL property property_name.
-
- Note that there is no check of the property type.
- """
- if property_name not in self.properties:
- return None
- name, type_ = self.properties
- return name
-
- @p...