File: bugbuddy.py

package info (click to toggle)
gnome-python-desktop 2.32.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,548 kB
  • sloc: sh: 10,214; xml: 8,851; ansic: 3,428; python: 1,457; makefile: 664
file content (40 lines) | stat: -rw-r--r-- 1,014 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys

_saved_except_hook = None
_appname = sys.argv[0]

def _bug_catcher(exctype, value, tb):
    import traceback
    import tempfile
    import os
    if exctype is not KeyboardInterrupt:
        msg = "".join(traceback.format_exception(exctype, value, tb))
        print >> sys.stderr, msg
        fd, name = tempfile.mkstemp()
        try:
            os.write(fd,msg)
            os.system("bug-buddy --include=\"%s\" --appname=\"%s\"" % (name, _appname))
        finally:
            os.unlink(name)
    raise SystemExit


def install(appname=None):
    global _saved_except_hook, _appname
    if appname is None:
        appname = sys.argv[0]
    _appname = appname
    if sys.excepthook is not _bug_catcher:
        _saved_except_hook = sys.excepthook
        sys.excepthook = _bug_catcher


def uninstall():
    global _saved_except_hook
    if sys.excepthook is _bug_catcher:
        sys.excepthook = _saved_except_hook
        _saved_except_hook = None


if not sys.stderr.isatty():
    install()