# Bazaar revision bundle v0.8 # # message: # Move binary scripts into bin directory and add apport namespace for apport.python_hook. # committer: Robert Collins # date: Thu 2006-11-09 10:55:07.457999945 +1100 === added directory apport // file-id:apport-20061108234839-1nvwon8hgbagfzvb-1 === added file apport/__init__.py // file-id:__init__.py-20061108234839-1nvwon8 ... hgbagfzvb-2 === added file apport/python_hook.py // file-id:python_hook.py-20061108234839-1 ... nvwon8hgbagfzvb-3 --- /dev/null +++ apport/python_hook.py @@ -0,0 +1,78 @@ +"""Python sys.excepthook hook to generate apport crash dumps. + +See https://wiki.ubuntu.com/AutomatedProblemReports for details. + +Copyright (c) 2006 Canonical Ltd. +Author: Robert Collins + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2 of the License, or (at your +option) any later version. See http://www.gnu.org/copyleft/gpl.html for +the full text of the license. +""" + +import os +import sys + + +def apport_excepthook(exc_type, exc_obj, exc_tb): + """Catch an uncaught exception and make a traceback.""" + # create and save a problem report. Note that exceptions in this code + # are bad, and we probably need a per-thread reentrancy guard to + # prevent that happening. However, on Ubuntu there should never be + # a reason for an exception here, other than [say] a read only var + # or some such. So what we do isuse a try - finally to ensure that + # the original excepthook is invoked, and until we get bug reports + # ignore the other issues. + + # import locally here so that there is no routine overhead on python + # startup time - only when a traceback occurs will this trigger. + try: + # ignore 'safe' exit types. + if exc_type in (KeyboardInterrupt, ): + return + from cStringIO import StringIO + import re + import tempfile + import traceback + + import apport_utils + import problem_report + pr = problem_report.ProblemReport() + # apport will look up the package from the executable path. + # if the module has mutated this, we're sunk, but it does not exist yet :(. + binary = os.path.normpath(os.path.join(os.getcwdu(), sys.argv[0])) + # append a basic traceback. In future we may want to include + # additional data such as the local variables, loaded modules etc. + tb_file = StringIO() + traceback.print_exception(exc_type, exc_obj, exc_tb, file=tb_file) + pr['Traceback'] = tb_file.getvalue() + apport_utils.report_add_proc_info(pr) + # override the ExecutablePath with the script that was actually running. + pr['ExecutablePath'] = binary + pr['PythonArgs'] = "%r" % sys.argv + # filter out binaries in user accessible paths: + # /home + # /tmp + if binary.startswith('/home') or binary.startswith('/tmp'): + return + mangled_program = re.sub('/', '_', binary) + # get the uid for now, user name later + user = os.getuid() + pr_filename = '/var/crash/%s-%s.crash' % (user, mangled_program) + report_file = file(pr_filename, 'wt') + try: + pr.write(report_file) + finally: + report_file.close() + + finally: + # resume original processing to get the default behaviour. + sys.__excepthook__(exc_type, exc_obj, exc_tb) + + +def install(): + """Install the python apport hook.""" + # install the apport exception handler + sys.excepthook = apport_excepthook === added directory bin // file-id:bin-20061108225810-0lazdzdj9zlxe5df-1 === added file debian/python-apport.install // file-id:pythonapport.install-200 ... 61108234848-tsj1g01wwnk670vl-1 --- /dev/null +++ debian/python-apport.install @@ -0,0 +1,1 @@ +usr/lib/python*/site-packages/apport/* === renamed file apport // bin/apport === renamed file apport-checkreports // bin/apport-checkreports === renamed file apport-retrace // bin/apport-retrace === renamed file apport-unpack // bin/apport-unpack === modified file debian/changelog --- debian/changelog +++ debian/changelog @@ -1,3 +1,11 @@ +apport (0.30) feisty; urgency=low + + * Non-maintainer upload. + * Add python excepthook hook module to generate apport crashdumps for python + programs. + + -- Robert Collins Thu, 9 Nov 2006 10:39:59 +1100 + apport (0.29) feisty; urgency=low * apport-retrace: Do not crash if a linked library is not a dependency. === modified file debian/control --- debian/control +++ debian/control @@ -46,6 +46,7 @@ These problem reports use standard Debian control format syntax (RFC822). + Package: python-apport-utils XB-Python-Version: ${python:Versions} Section: python @@ -58,3 +59,18 @@ * Query available and new reports. * Add OS, packaging, and process runtime information to a report. * Various frontend utility functions. + + +Package: python-apport +XB-Python-Version: ${python:Versions} +Section: python +Architecture: all +Depends: ${python:Depends}, python-problem-report (= ${Source-Version}), python-apport-utils (= ${Source-Version}) +Description: core apport library. + This python library provides apport problem report creation and management + facilities: + . + * Query available and new reports. + * Add OS, packaging, and process runtime information to a report. + * Various frontend utility functions. + * Python hook to generate crash dumps when python scripts fail. === modified file setup.py --- setup.py +++ setup.py @@ -23,5 +23,6 @@ description='read, write, and modify problem reports', py_modules=['problem_report', 'apport_utils'], data_files=[('share/apport', ['gtk/apport-gtk.glade', 'gtk/apport-gtk.png'])]+mo_files, - scripts=['apport', 'apport-checkreports', 'apport-retrace', 'apport-unpack', 'gtk/apport-gtk'], + scripts=['bin/apport', 'bin/apport-checkreports', 'bin/apport-retrace', 'bin/apport-unpack', 'gtk/apport-gtk'], + packages=['apport'], ) === modified directory // last-changed:robertc@robertcollins.net-2006110823550 ... 7-ece72897d3c25679 # revision id: robertc@robertcollins.net-20061108235507-ece72897d3c25679 # sha1: 8103cd39d2085be20e77abc3212470cfd3b9b8c8 # inventory sha1: 651722bbd071a5ff8ad833e4dd4ac8805464ba66 # parent ids: # robertc@robertcollins.net-20061108194726-77fae7be34d4e6df # base id: robertc@robertcollins.net-20061108194726-77fae7be34d4e6df # properties: # branch-nick: python-hook