17
17
# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
22
from checkbox.lib.safe import safe_make_directory
23
from checkbox.properties import String
24
from checkbox.properties import Path
24
25
from checkbox.plugin import Plugin
25
26
from checkbox.reports.launchpad_report import LaunchpadReportManager
28
29
class LaunchpadReport(Plugin):
30
31
# Filename where submission information is cached.
31
filename = String(default="%(checkbox_data)s/submission.xml")
32
filename = Path(default="%(checkbox_data)s/submission.xml")
35
stylesheet = Path(default="%(checkbox_share)s/report/checkbox.xsl")
33
37
def register(self, manager):
34
38
super(LaunchpadReport, self).register(manager)
49
54
("report-client", self.report_client),
50
55
("report-datetime", self.report_datetime),
51
56
("report-distribution", self.report_distribution),
52
("report-dmi", self.report_dmi),
57
("report-dmi", self.report_context),
53
58
("report-hal", self.report_hal),
59
("report-modprobe", self.report_context),
60
("report-modules", self.report_context),
54
61
("report-packages", self.report_packages),
55
("report-pci", self.report_pci),
62
("report-pci", self.report_context),
56
63
("report-processors", self.report_processors),
64
("report-sysctl", self.report_context),
57
65
("report-system_id", self.report_system_id),
58
66
("report-results", self.report_results)]:
59
67
self._manager.reactor.call_on(rt, rh)
75
83
self._report["summary"]["distribution"] = distribution.distributor_id
76
84
self._report["summary"]["distroseries"] = distribution.release
78
def report_dmi(self, dmi):
79
self._report["hardware"]["dmi"] = dmi
81
86
def report_packages(self, packages):
82
87
self._report["software"]["packages"].extend(packages)
84
def report_pci(self, pci):
85
self._report["hardware"]["lspci"] = pci
87
89
def report_processors(self, processors):
88
90
self._report["hardware"]["processors"] = processors
100
102
question["result"] = dict(result.attributes)
101
103
self._report["questions"].append(question)
105
def report_context(self, sources):
106
# sources should be a list - make it so
107
if not isinstance(sources, list):
110
for source in sources:
111
if isinstance(source, tuple):
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)
103
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)
104
130
# Prepare the payload and attach it to the form
105
report_manager = LaunchpadReportManager("system", "1.0")
131
stylesheet = posixpath.abspath(stylesheet)
132
report_manager = LaunchpadReportManager("system", "1.0", stylesheet)
106
133
payload = report_manager.dumps(self._report).toprettyxml("")
108
135
directory = posixpath.dirname(self.filename)
109
136
safe_make_directory(directory)
111
open(self.filename, "w").write(payload)
138
file = open(self.filename, "w")
112
142
self._manager.reactor.fire("exchange-report", self.filename)