Merge lp:~adeuring/launchpad/bug-438024-parse-dmi-data into lp:launchpad

Proposed by Abel Deuring
Status: Merged
Merged at revision: not available
Proposed branch: lp:~adeuring/launchpad/bug-438024-parse-dmi-data
Merge into: lp:launchpad
Diff against target: 80 lines
2 files modified
lib/canonical/launchpad/scripts/hwdbsubmissions.py (+19/-0)
lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py (+34/-0)
To merge this branch: bzr merge lp:~adeuring/launchpad/bug-438024-parse-dmi-data
Reviewer Review Type Date Requested Status
Eleanor Berger (community) Approve
Review via email: mp+12518@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Abel Deuring (adeuring) wrote :

This branch adds a method SubmissionParser._parseDmi().

The HWDB client in Karmic will no longer submit data containing HAL data; instead it will send data from udev, some DMI data and devices properties stored in sysfs files.

SubmissionParser._parseDmi() converts the text data from the <dmi> node as provided by the HWDB client into a simple dicitionary.

test:

./bin/test -t test_hwdb_submission_parser

= Launchpad lint =

Checking for conflicts. and issues in doctests and templates.
Running jslint, xmllint, pyflakes, and pylint.
Using normal rules.

Linting changed files:
  lib/canonical/launchpad/scripts/hwdbsubmissions.py
  lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py

== Pyflakes notices ==

lib/canonical/launchpad/scripts/hwdbsubmissions.py
    22: redefinition of unused 'etree' from line 20

lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py
    10: redefinition of unused 'etree' from line 8

== Pylint notices ==

lib/canonical/launchpad/scripts/hwdbsubmissions.py
    20: [F0401] Unable to import 'xml.etree.cElementTree' (No module named etree)

This message is not related to my changes; it was introduced by a branch that prepares the transistion to Python 2.5.

Revision history for this message
Eleanor Berger (intellectronica) wrote :

s/ndes/nodes other than that everything looks great. r=me

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-09-15 17:05:32 +0000
3+++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-09-28 12:39:17 +0000
4@@ -538,12 +538,31 @@
5 device[key] = value
6 return devices
7
8+ def _parseDmi(self, dmi_node):
9+ """Parse the <dmi> node.
10+
11+ :return: A dictionary containing the key:value pairs of the DMI data.
12+ """
13+ dmi_data = {}
14+ dmi_text = dmi_node.text.strip().split('\n')
15+ for line_number, line in enumerate(dmi_text):
16+ record = line.split(':', 1)
17+ if len(record) != 2:
18+ self._logError(
19+ 'Line %i in <dmi>: No valid key:value data: %r'
20+ % (line_number, line),
21+ self.submission_key)
22+ return None
23+ dmi_data[record[0]] = record[1]
24+ return dmi_data
25+
26 def _setHardwareSectionParsers(self):
27 self._parse_hardware_section = {
28 'hal': self._parseHAL,
29 'processors': self._parseProcessors,
30 'aliases': self._parseAliases,
31 'udev': self._parseUdev,
32+ 'dmi': self._parseDmi,
33 }
34
35 def _parseHardware(self, hardware_node):
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-09-15 17:05:32 +0000
39+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-09-28 12:39:17 +0000
40@@ -615,6 +615,40 @@
41 parser.submission_key,
42 "Line 2 in <udev>: Duplicate attribute key: 'W:2'")
43
44+ def testDmi(self):
45+ """The content of the <udev> node is converted into a dictionary."""
46+ parser = SubmissionParser(self.log)
47+ node = etree.fromstring("""<dmi>/sys/class/dmi/id/bios_vendor:LENOVO
48+/sys/class/dmi/id/bios_version:7LETB9WW (2.19 )
49+/sys/class/dmi/id/sys_vendor:LENOVO
50+/sys/class/dmi/id/modalias:dmi:bvnLENOVO:bvr7LETB9WW
51+</dmi>""")
52+ result = parser._parseDmi(node)
53+ self.assertEqual(
54+ {
55+ '/sys/class/dmi/id/bios_vendor': 'LENOVO',
56+ '/sys/class/dmi/id/bios_version': '7LETB9WW (2.19 )',
57+ '/sys/class/dmi/id/sys_vendor': 'LENOVO',
58+ '/sys/class/dmi/id/modalias': 'dmi:bvnLENOVO:bvr7LETB9WW',
59+ },
60+ result,
61+ 'Invalid parsing result for <dmi>.')
62+
63+ def testDmiInvalidData(self):
64+ """<dmi> nodes with lines not in key:value format are rejected."""
65+ parser = SubmissionParser(self.log)
66+ parser.submission_key = 'Invalid DMI data'
67+ node = etree.fromstring("""<dmi>/sys/class/dmi/id/bios_vendor:LENOVO
68+invalid line
69+</dmi>""")
70+ result = parser._parseDmi(node)
71+ self.assertEqual(
72+ None, result,
73+ '<dmi> node with invalid data not deteced.')
74+ self.assertErrorMessage(
75+ parser.submission_key,
76+ "Line 1 in <dmi>: No valid key:value data: 'invalid line'")
77+
78 def testHardware(self):
79 """The <hardware> tag is converted into a dictionary."""
80 test = self