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
1=== modified file 'pygtk/gtkcrashhandler.py'
2--- pygtk/gtkcrashhandler.py 2010-03-02 21:16:36 +0000
3+++ pygtk/gtkcrashhandler.py 2010-08-24 20:25:00 +0000
4@@ -47,7 +47,7 @@
5 import pango
6 import gobject
7 _gtk_initialized = True
8-except Exception:
9+except ImportError, AssertionError:
10 print >> sys.stderr, "gtkcrashhandler could not load GTK 2.0"
11 _gtk_initialized = False
12 import traceback
13@@ -55,12 +55,10 @@
14 import threading
15
16 APP_NAME = None
17-MESSAGE = _("We're terribly sorry. Could you help us fix the problem by " \
18- "reporting the crash?")
19+MESSAGE = None
20 USE_APPORT = False
21
22-_old_sys_excepthook = None # None means that initialize() has not been called
23- # yet.
24+_old_sys_excepthook = None # None means that initialize() has not been called yet.
25
26 def initialize(app_name=None, message=None, use_apport=False):
27 """Initialize the except hook built on GTK.
28@@ -79,12 +77,9 @@
29
30 """
31 global APP_NAME, MESSAGE, USE_APPORT, _gtk_initialized, _old_sys_excepthook
32- if app_name:
33- APP_NAME = _(app_name)
34- if not message is None:
35- MESSAGE = _(message)
36- if use_apport:
37- USE_APPORT = use_apport
38+ APP_NAME = app_name
39+ MESSAGE = message
40+ USE_APPORT = use_apport
41 if _gtk_initialized == True and _old_sys_excepthook is None:
42 # save sys.excepthook first, as it may not be sys.__excepthook__
43 # (for example, it might be Apport's python hook)
44@@ -106,16 +101,18 @@
45 add_apport_button = False
46 global USE_APPORT
47 if USE_APPORT:
48- # see if this file is from a properly installed distribution package
49+ # see if this file is from a properly installed distribution package
50 try:
51 from apport.fileutils import likely_packaged
52+ # this bit borrowed from apport_python_hook.py
53+ # apport will look up the package from the executable path.
54 try:
55 filename = os.path.realpath(os.path.join(os.getcwdu(),
56- sys.argv[0]))
57- except:
58- filename = os.path.realpath("/proc/%i/exe" % os.getpid())
59- if not os.path.isfile(filename) or not os.access(filename, os.X_OK):
60- raise Exception()
61+ sys.argv[0]))
62+ except (TypeError, AttributeError, IndexError):
63+ filename = os.readlink('/proc/%i/exe' % os.getpid())
64+ if not os.access(filename, os.X_OK) or not os.path.isfile(filename):
65+ raise
66 add_apport_button = likely_packaged(filename)
67 except:
68 add_apport_button = False
69@@ -125,6 +122,7 @@
70 if res == 3: # report button clicked
71 # enable apport, overriding preferences
72 try:
73+ # This method works for old versions of Apport
74 # create new temporary configuration file, where enabled=1
75 import re
76 from apport.packaging_impl import impl as apport_packaging
77@@ -143,6 +141,13 @@
78
79 # set apport to use this configuration file, temporarily
80 apport_packaging.configuration = tempfilename
81+
82+ # This method works for newer versions of Apport, tested with
83+ # Apport version 1.13.3
84+ import apport_python_hook
85+ apport_python_hook.enabled = lambda: True
86+
87+
88 # override Apport's ignore settings for this app
89 from apport.report import Report
90 Report.check_ignored = lambda self: False
91@@ -169,7 +174,7 @@
92 title = _("An error has occurred")
93 global APP_NAME
94 if APP_NAME:
95- title = APP_NAME
96+ title = _(APP_NAME)
97 dialog = gtk.Dialog(title)
98
99 # title Label
100@@ -180,9 +185,13 @@
101
102 # message Label
103 global MESSAGE
104- text_label = gtk.Label(MESSAGE)
105+ if MESSAGE:
106+ text_label = gtk.Label(MESSAGE)
107+ else:
108+ text_label = gtk.Label(_("Unfortunately, we haven't yet found and "
109+ "corrected this problem. You might want to "
110+ "report the crash to the developers."))
111 text_label.set_alignment(0, 0.5)
112-
113 text_label.set_line_wrap(True)
114 def text_label_size_allocate(widget, rect):
115 """Lets label resize correctly while wrapping text."""

Subscribers

People subscribed via source and target branches