Merge lp:~flimm/python-snippets/gtkcrashhandler into lp:~jonobacon/python-snippets/trunk

Proposed by David D Lowe
Status: Needs review
Proposed branch: lp:~flimm/python-snippets/gtkcrashhandler
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 115 lines (+29/-20)
1 file modified
pygtk/gtkcrashhandler.py (+29/-20)
To merge this branch: bzr merge lp:~flimm/python-snippets/gtkcrashhandler
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+33582@code.launchpad.net

Description of the change

I updated gtkcrashhandler.py to make it work with the versions of Apport on Ubuntu Lucid and Maverick.

To post a comment you must log in.

Unmerged revisions

100. By David D Lowe

Update gtkcrashhandler.py for Apport 1.13.3

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pygtk/gtkcrashhandler.py'
--- pygtk/gtkcrashhandler.py 2010-03-02 21:16:36 +0000
+++ pygtk/gtkcrashhandler.py 2010-08-24 20:25:00 +0000
@@ -47,7 +47,7 @@
47 import pango47 import pango
48 import gobject48 import gobject
49 _gtk_initialized = True49 _gtk_initialized = True
50except Exception:50except ImportError, AssertionError:
51 print >> sys.stderr, "gtkcrashhandler could not load GTK 2.0"51 print >> sys.stderr, "gtkcrashhandler could not load GTK 2.0"
52 _gtk_initialized = False52 _gtk_initialized = False
53import traceback53import traceback
@@ -55,12 +55,10 @@
55import threading55import threading
5656
57APP_NAME = None57APP_NAME = None
58MESSAGE = _("We're terribly sorry. Could you help us fix the problem by " \58MESSAGE = None
59 "reporting the crash?")
60USE_APPORT = False59USE_APPORT = False
6160
62_old_sys_excepthook = None # None means that initialize() has not been called61_old_sys_excepthook = None # None means that initialize() has not been called yet.
63 # yet.
6462
65def initialize(app_name=None, message=None, use_apport=False):63def initialize(app_name=None, message=None, use_apport=False):
66 """Initialize the except hook built on GTK.64 """Initialize the except hook built on GTK.
@@ -79,12 +77,9 @@
7977
80 """78 """
81 global APP_NAME, MESSAGE, USE_APPORT, _gtk_initialized, _old_sys_excepthook79 global APP_NAME, MESSAGE, USE_APPORT, _gtk_initialized, _old_sys_excepthook
82 if app_name:80 APP_NAME = app_name
83 APP_NAME = _(app_name)81 MESSAGE = message
84 if not message is None:82 USE_APPORT = use_apport
85 MESSAGE = _(message)
86 if use_apport:
87 USE_APPORT = use_apport
88 if _gtk_initialized == True and _old_sys_excepthook is None:83 if _gtk_initialized == True and _old_sys_excepthook is None:
89 # save sys.excepthook first, as it may not be sys.__excepthook__84 # save sys.excepthook first, as it may not be sys.__excepthook__
90 # (for example, it might be Apport's python hook)85 # (for example, it might be Apport's python hook)
@@ -106,16 +101,18 @@
106 add_apport_button = False101 add_apport_button = False
107 global USE_APPORT102 global USE_APPORT
108 if USE_APPORT:103 if USE_APPORT:
109 # see if this file is from a properly installed distribution package104 # see if this file is from a properly installed distribution package
110 try:105 try:
111 from apport.fileutils import likely_packaged106 from apport.fileutils import likely_packaged
107 # this bit borrowed from apport_python_hook.py
108 # apport will look up the package from the executable path.
112 try:109 try:
113 filename = os.path.realpath(os.path.join(os.getcwdu(),110 filename = os.path.realpath(os.path.join(os.getcwdu(),
114 sys.argv[0]))111 sys.argv[0]))
115 except:112 except (TypeError, AttributeError, IndexError):
116 filename = os.path.realpath("/proc/%i/exe" % os.getpid())113 filename = os.readlink('/proc/%i/exe' % os.getpid())
117 if not os.path.isfile(filename) or not os.access(filename, os.X_OK):114 if not os.access(filename, os.X_OK) or not os.path.isfile(filename):
118 raise Exception()115 raise
119 add_apport_button = likely_packaged(filename)116 add_apport_button = likely_packaged(filename)
120 except:117 except:
121 add_apport_button = False118 add_apport_button = False
@@ -125,6 +122,7 @@
125 if res == 3: # report button clicked122 if res == 3: # report button clicked
126 # enable apport, overriding preferences123 # enable apport, overriding preferences
127 try:124 try:
125 # This method works for old versions of Apport
128 # create new temporary configuration file, where enabled=1126 # create new temporary configuration file, where enabled=1
129 import re127 import re
130 from apport.packaging_impl import impl as apport_packaging128 from apport.packaging_impl import impl as apport_packaging
@@ -143,6 +141,13 @@
143141
144 # set apport to use this configuration file, temporarily142 # set apport to use this configuration file, temporarily
145 apport_packaging.configuration = tempfilename143 apport_packaging.configuration = tempfilename
144
145 # This method works for newer versions of Apport, tested with
146 # Apport version 1.13.3
147 import apport_python_hook
148 apport_python_hook.enabled = lambda: True
149
150
146 # override Apport's ignore settings for this app151 # override Apport's ignore settings for this app
147 from apport.report import Report152 from apport.report import Report
148 Report.check_ignored = lambda self: False153 Report.check_ignored = lambda self: False
@@ -169,7 +174,7 @@
169 title = _("An error has occurred")174 title = _("An error has occurred")
170 global APP_NAME175 global APP_NAME
171 if APP_NAME:176 if APP_NAME:
172 title = APP_NAME177 title = _(APP_NAME)
173 dialog = gtk.Dialog(title)178 dialog = gtk.Dialog(title)
174179
175 # title Label180 # title Label
@@ -180,9 +185,13 @@
180185
181 # message Label186 # message Label
182 global MESSAGE187 global MESSAGE
183 text_label = gtk.Label(MESSAGE)188 if MESSAGE:
189 text_label = gtk.Label(MESSAGE)
190 else:
191 text_label = gtk.Label(_("Unfortunately, we haven't yet found and "
192 "corrected this problem. You might want to "
193 "report the crash to the developers."))
184 text_label.set_alignment(0, 0.5)194 text_label.set_alignment(0, 0.5)
185
186 text_label.set_line_wrap(True)195 text_label.set_line_wrap(True)
187 def text_label_size_allocate(widget, rect):196 def text_label_size_allocate(widget, rect):
188 """Lets label resize correctly while wrapping text."""197 """Lets label resize correctly while wrapping text."""

Subscribers

People subscribed via source and target branches