~ubuntu-branches/ubuntu/precise/checkbox/precise

« back to all changes in this revision

Viewing changes to plugins/launchpad_report.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Tardif
  • Date: 2009-01-20 16:46:15 UTC
  • Revision ID: james.westby@ubuntu.com-20090120164615-7iz6nmlef41h4vx2
Tags: 0.4
* Setup bzr-builddeb in native mode.
* Removed LGPL notice from the copyright file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (c) 2008 Canonical
 
3
#
 
4
# Written by Marc Tardif <marc@interunion.ca>
 
5
#
 
6
# This file is part of Checkbox.
 
7
#
 
8
# Checkbox is free software: you can redistribute it and/or modify
 
9
# it under the terms of the GNU General Public License as published by
 
10
# the Free Software Foundation, either version 3 of the License, or
 
11
# (at your option) any later version.
 
12
#
 
13
# Checkbox is distributed in the hope that it will be useful,
 
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
# GNU General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with Checkbox.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
import posixpath
 
22
 
 
23
from checkbox.lib.safe import safe_make_directory
 
24
 
 
25
from checkbox.plugin import Plugin
 
26
from checkbox.reports.launchpad_report import LaunchpadReportManager
 
27
 
 
28
 
 
29
class LaunchpadReport(Plugin):
 
30
 
 
31
    required_attributes = ["filename"]
 
32
 
 
33
    def register(self, manager):
 
34
        super(LaunchpadReport, self).register(manager)
 
35
        self._report = {
 
36
            "summary": {
 
37
                "private": False,
 
38
                "contactable": False,
 
39
                "live_cd": False},
 
40
            "hardware": {},
 
41
            "software": {
 
42
                "packages": []},
 
43
            "questions": []}
 
44
 
 
45
        # Launchpad report should be generated last.
 
46
        self._manager.reactor.call_on("report", self.report, 100)
 
47
        for (rt, rh) in [
 
48
             ("report-architecture", self.report_architecture),
 
49
             ("report-client", self.report_client),
 
50
             ("report-datetime", self.report_datetime),
 
51
             ("report-distribution", self.report_distribution),
 
52
             ("report-hal", self.report_hal),
 
53
             ("report-packages", self.report_packages),
 
54
             ("report-processors", self.report_processors),
 
55
             ("report-system_id", self.report_system_id),
 
56
             ("report-results", self.report_results)]:
 
57
            self._manager.reactor.call_on(rt, rh)
 
58
 
 
59
    def report_architecture(self, architecture):
 
60
        self._report["summary"]["architecture"] = architecture
 
61
 
 
62
    def report_hal(self, hal):
 
63
        self._report["hardware"]["hal"] = hal
 
64
 
 
65
    def report_client(self, client):
 
66
        self._report["summary"]["client"] = client
 
67
 
 
68
    def report_datetime(self, datetime):
 
69
        self._report["summary"]["date_created"] = datetime
 
70
 
 
71
    def report_distribution(self, distribution):
 
72
        self._report["software"]["lsbrelease"] = dict(distribution)
 
73
        self._report["summary"]["distribution"] = distribution.distributor_id
 
74
        self._report["summary"]["distroseries"] = distribution.release
 
75
 
 
76
    def report_packages(self, packages):
 
77
        self._report["software"]["packages"].extend(packages)
 
78
 
 
79
    def report_processors(self, processors):
 
80
        self._report["hardware"]["processors"] = processors
 
81
 
 
82
    def report_system_id(self, system_id):
 
83
        self._report["summary"]["system_id"] = system_id
 
84
 
 
85
    def report_results(self, results):
 
86
        for result in results:
 
87
            test = result.test
 
88
            question = dict(test.attributes)
 
89
            question["command"] = str(test.command)
 
90
            question["description"] = str(test.description)
 
91
            question["requires"] = str(test.requires)
 
92
            question["result"] = dict(result.attributes)
 
93
            self._report["questions"].append(question)
 
94
 
 
95
    def report(self):
 
96
        # Prepare the payload and attach it to the form
 
97
        report_manager = LaunchpadReportManager("system", "1.0")
 
98
        payload = report_manager.dumps(self._report).toprettyxml("")
 
99
 
 
100
        filename = self._config.filename
 
101
        directory = posixpath.dirname(filename)
 
102
        safe_make_directory(directory)
 
103
 
 
104
        open(filename, "w").write(payload)
 
105
        self._manager.reactor.fire("exchange-report", filename)
 
106
 
 
107
 
 
108
factory = LaunchpadReport