|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
1 |
"""Apport integration to provide better problem reports."""
|
|
971
by Martin Pitt
Fix PEP-8: E265 block comment should start with '# ' |
2 |
# Copyright (C) 2010 Sebastian Heinlein <devel@glatzor.de>
|
3 |
#
|
|
4 |
# Licensed under the GNU General Public License Version 2
|
|
5 |
#
|
|
6 |
# This program 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 2 of the License, or
|
|
9 |
# (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program 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 this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
19 |
|
20 |
__author__ = "Sebastian Heinlein <devel@glatzor.de>" |
|
21 |
||
22 |
__all__ = ("create_report") |
|
23 |
||
24 |
import os |
|
25 |
||
26 |
import apport |
|
27 |
import apport.fileutils |
|
28 |
import apt_pkg |
|
29 |
||
|
764
by sebi at glatzor
Apply print and import fixes of 2to3 |
30 |
from . import enums |
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
31 |
|
|
883.1.9
by Sebastian Heinlein
PEP8 fixes |
32 |
|
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
33 |
def create_report(error, traceback, trans=None): |
34 |
"""Create an apport problem report for a given crash.
|
|
35 |
||
36 |
:param error: The summary of the error.
|
|
37 |
:param traceback: The traceback of the exception.
|
|
38 |
:param trans: The optional transaction in which the crash occured.
|
|
39 |
"""
|
|
|
680
by sebi at glatzor
Only create an apport crash report if we are running as a system service with / as the working directory. This helps as to avoid crash reports if we are running in a test environment |
40 |
if not apport.packaging.enabled() or os.getcwd() != "/": |
|
661
by Martin Pitt
aptdaemon/crash.py: only create crash reports if apport is enabled; also fix the __main__ test to actually work |
41 |
return
|
42 |
||
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
43 |
uid = 0 |
|
515
by sebi at glatzor
Use the Crash type |
44 |
report = apport.Report("Crash") |
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
45 |
report["Title"] = error |
|
966.1.2
by Brian Murray
include package version in crash reports |
46 |
package = "aptdaemon" |
47 |
try: |
|
48 |
package_version = apport.packaging.get_version(package) |
|
49 |
except ValueError as e: |
|
50 |
if 'does not exist' in e.message: |
|
51 |
package_version = 'unknown' |
|
52 |
report['Package'] = '%s %s' % (package, package_version) |
|
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
53 |
report["SourcePackage"] = "aptdaemon" |
|
659.1.1
by Brian Murray
aptdaemon/crash.py: title attachments Traceback to be consistent with apport |
54 |
report["Traceback"] = traceback |
|
516
by sebi at glatzor
Add a desktop file to show a nicer error message in apport |
55 |
report["ExecutablePath"] = "/usr/sbin/aptd" |
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
56 |
report.add_os_info() |
57 |
||
58 |
# Attach information about the transaction
|
|
59 |
if trans: |
|
60 |
report["Annotation"] = enums.get_role_error_from_enum(trans.role) |
|
61 |
report["TransactionRole"] = trans.role |
|
62 |
report["TransactionPackages"] = str([list(l) for l in trans.packages]) |
|
63 |
report["TransactionDepends"] = str([list(l) for l in trans.depends]) |
|
64 |
report["TransactionKwargs"] = str(trans.kwargs) |
|
65 |
report["TransactionLocale"] = trans.locale |
|
|
554.1.2
by sebi at glatzor
Store the output of all progresses in the transaction. Add the output to the apport crash report. Furthermore raise an PACKAGE_MANAGER_FAILED error instead of an unknown error if the dpkg call failed. |
66 |
report["TransactionOutput"] = trans.output |
|
562.1.7
by sebi at glatzor
Add the transaction error to apport report |
67 |
report["TransactionErrorCode"] = trans._error_property[0] |
68 |
report["TransactionErrorDetails"] = trans._error_property[1] |
|
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
69 |
uid = os.path.basename(trans.tid) |
70 |
||
71 |
# Write report
|
|
72 |
report_path = apport.fileutils.make_report_path(report, uid) |
|
73 |
if not os.path.exists(report_path): |
|
|
861.1.1
by Steve Langasek
Open our crash report for writing in binary mode |
74 |
report.write(open(report_path, 'wb')) |
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
75 |
|
76 |
if __name__ == "__main__": |
|
77 |
apt_pkg.init_config() |
|
|
661
by Martin Pitt
aptdaemon/crash.py: only create crash reports if apport is enabled; also fix the __main__ test to actually work |
78 |
create_report('test', 'testtrace') |
|
513
by sebi at glatzor
Send custom error reports to Launchpad with additional information about the transaction and the apt configuration. |
79 |
|
80 |
# vim:ts=4:sw=4:et
|