home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / checkbox / plugins / launchpad_report.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  5.2 KB  |  146 lines

  1. #
  2. # This file is part of Checkbox.
  3. #
  4. # Copyright 2008 Canonical Ltd.
  5. #
  6. # Checkbox is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Checkbox is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import posixpath
  20. import shutil
  21.  
  22. from checkbox.lib.safe import safe_make_directory
  23.  
  24. from checkbox.properties import Path
  25. from checkbox.plugin import Plugin
  26. from checkbox.reports.launchpad_report import LaunchpadReportManager
  27.  
  28.  
  29. class LaunchpadReport(Plugin):
  30.  
  31.     # Filename where submission information is cached.
  32.     filename = Path(default="%(checkbox_data)s/submission.xml")
  33.  
  34.     # XSL Stylesheet
  35.     stylesheet = Path(default="%(checkbox_share)s/report/checkbox.xsl")
  36.  
  37.     def register(self, manager):
  38.         super(LaunchpadReport, self).register(manager)
  39.         self._report = {
  40.             "summary": {
  41.                 "private": False,
  42.                 "contactable": False,
  43.                 "live_cd": False},
  44.             "hardware": {},
  45.             "software": {
  46.                 "packages": []},
  47.             "questions": [],
  48.             "context": []}
  49.  
  50.         # Launchpad report should be generated last.
  51.         self._manager.reactor.call_on("report", self.report, 100)
  52.         for (rt, rh) in [
  53.              ("report-architecture", self.report_architecture),
  54.              ("report-client", self.report_client),
  55.              ("report-datetime", self.report_datetime),
  56.              ("report-distribution", self.report_distribution),
  57.              ("report-dmi", self.report_context),
  58.              ("report-hal", self.report_hal),
  59.              ("report-modprobe", self.report_context),
  60.              ("report-modules", self.report_context),
  61.              ("report-packages", self.report_packages),
  62.              ("report-pci", self.report_context),
  63.              ("report-processors", self.report_processors),
  64.              ("report-sysctl", self.report_context),
  65.              ("report-system_id", self.report_system_id),
  66.              ("report-results", self.report_results)]:
  67.             self._manager.reactor.call_on(rt, rh)
  68.  
  69.     def report_architecture(self, architecture):
  70.         self._report["summary"]["architecture"] = architecture
  71.  
  72.     def report_hal(self, hal):
  73.         self._report["hardware"]["hal"] = hal
  74.  
  75.     def report_client(self, client):
  76.         self._report["summary"]["client"] = client
  77.  
  78.     def report_datetime(self, datetime):
  79.         self._report["summary"]["date_created"] = datetime
  80.  
  81.     def report_distribution(self, distribution):
  82.         self._report["software"]["lsbrelease"] = dict(distribution)
  83.         self._report["summary"]["distribution"] = distribution.distributor_id
  84.         self._report["summary"]["distroseries"] = distribution.release
  85.  
  86.     def report_packages(self, packages):
  87.         self._report["software"]["packages"].extend(packages)
  88.  
  89.     def report_processors(self, processors):
  90.         self._report["hardware"]["processors"] = processors
  91.  
  92.     def report_system_id(self, system_id):
  93.         self._report["summary"]["system_id"] = system_id
  94.  
  95.     def report_results(self, results):
  96.         for result in results:
  97.             test = result.test
  98.             question = dict(test.attributes)
  99.             question["command"] = str(test.command)
  100.             question["description"] = str(test.description)
  101.             question["requires"] = str(test.requires)
  102.             question["result"] = dict(result.attributes)
  103.             self._report["questions"].append(question)
  104.  
  105.     def report_context(self, sources):
  106.         # sources should be a list - make it so
  107.         if not isinstance(sources, list):
  108.             sources = [sources]
  109.  
  110.         for source in sources:
  111.             if isinstance(source, tuple):
  112.                 source = source[1]
  113.             info = {}
  114.             if 'command' in dir(source):
  115.                 info["command"] = source.command
  116.             if 'filename' in dir(source):
  117.                 info["command"] = source.filename
  118.             if 'directory' in dir(source):
  119.                 info["command"] = source.directory
  120.             info["data"] = str(source)
  121.             self._report["context"].append(info)
  122.  
  123.     def report(self):
  124.         # Copy stylesheet to report directory
  125.         stylesheet = posixpath.join(
  126.             posixpath.dirname(self.filename),
  127.             posixpath.basename(self.stylesheet))
  128.         shutil.copy(self.stylesheet, stylesheet)
  129.  
  130.         # Prepare the payload and attach it to the form
  131.         stylesheet = posixpath.abspath(stylesheet)
  132.         report_manager = LaunchpadReportManager("system", "1.0", stylesheet)
  133.         payload = report_manager.dumps(self._report).toprettyxml("")
  134.  
  135.         directory = posixpath.dirname(self.filename)
  136.         safe_make_directory(directory)
  137.  
  138.         file = open(self.filename, "w")
  139.         file.write(payload)
  140.         file.close()
  141.  
  142.         self._manager.reactor.fire("exchange-report", self.filename)
  143.  
  144.  
  145. factory = LaunchpadReport
  146.