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
=== modified file 'lib/canonical/launchpad/scripts/hwdbsubmissions.py'
--- lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-09-15 17:05:32 +0000
+++ lib/canonical/launchpad/scripts/hwdbsubmissions.py 2009-09-28 12:39:17 +0000
@@ -538,12 +538,31 @@
538 device[key] = value538 device[key] = value
539 return devices539 return devices
540540
541 def _parseDmi(self, dmi_node):
542 """Parse the <dmi> node.
543
544 :return: A dictionary containing the key:value pairs of the DMI data.
545 """
546 dmi_data = {}
547 dmi_text = dmi_node.text.strip().split('\n')
548 for line_number, line in enumerate(dmi_text):
549 record = line.split(':', 1)
550 if len(record) != 2:
551 self._logError(
552 'Line %i in <dmi>: No valid key:value data: %r'
553 % (line_number, line),
554 self.submission_key)
555 return None
556 dmi_data[record[0]] = record[1]
557 return dmi_data
558
541 def _setHardwareSectionParsers(self):559 def _setHardwareSectionParsers(self):
542 self._parse_hardware_section = {560 self._parse_hardware_section = {
543 'hal': self._parseHAL,561 'hal': self._parseHAL,
544 'processors': self._parseProcessors,562 'processors': self._parseProcessors,
545 'aliases': self._parseAliases,563 'aliases': self._parseAliases,
546 'udev': self._parseUdev,564 'udev': self._parseUdev,
565 'dmi': self._parseDmi,
547 }566 }
548567
549 def _parseHardware(self, hardware_node):568 def _parseHardware(self, hardware_node):
550569
=== modified file 'lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py'
--- lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-09-15 17:05:32 +0000
+++ lib/canonical/launchpad/scripts/tests/test_hwdb_submission_parser.py 2009-09-28 12:39:17 +0000
@@ -615,6 +615,40 @@
615 parser.submission_key,615 parser.submission_key,
616 "Line 2 in <udev>: Duplicate attribute key: 'W:2'")616 "Line 2 in <udev>: Duplicate attribute key: 'W:2'")
617617
618 def testDmi(self):
619 """The content of the <udev> node is converted into a dictionary."""
620 parser = SubmissionParser(self.log)
621 node = etree.fromstring("""<dmi>/sys/class/dmi/id/bios_vendor:LENOVO
622/sys/class/dmi/id/bios_version:7LETB9WW (2.19 )
623/sys/class/dmi/id/sys_vendor:LENOVO
624/sys/class/dmi/id/modalias:dmi:bvnLENOVO:bvr7LETB9WW
625</dmi>""")
626 result = parser._parseDmi(node)
627 self.assertEqual(
628 {
629 '/sys/class/dmi/id/bios_vendor': 'LENOVO',
630 '/sys/class/dmi/id/bios_version': '7LETB9WW (2.19 )',
631 '/sys/class/dmi/id/sys_vendor': 'LENOVO',
632 '/sys/class/dmi/id/modalias': 'dmi:bvnLENOVO:bvr7LETB9WW',
633 },
634 result,
635 'Invalid parsing result for <dmi>.')
636
637 def testDmiInvalidData(self):
638 """<dmi> nodes with lines not in key:value format are rejected."""
639 parser = SubmissionParser(self.log)
640 parser.submission_key = 'Invalid DMI data'
641 node = etree.fromstring("""<dmi>/sys/class/dmi/id/bios_vendor:LENOVO
642invalid line
643</dmi>""")
644 result = parser._parseDmi(node)
645 self.assertEqual(
646 None, result,
647 '<dmi> node with invalid data not deteced.')
648 self.assertErrorMessage(
649 parser.submission_key,
650 "Line 1 in <dmi>: No valid key:value data: 'invalid line'")
651
618 def testHardware(self):652 def testHardware(self):
619 """The <hardware> tag is converted into a dictionary."""653 """The <hardware> tag is converted into a dictionary."""
620 test = self654 test = self