home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-gnome2-desktop / gtk-2.0 / bugbuddy.py
Encoding:
Python Source  |  2009-03-30  |  1014 b   |  41 lines

  1. import sys
  2.  
  3. _saved_except_hook = None
  4. _appname = sys.argv[0]
  5.  
  6. def _bug_catcher(exctype, value, tb):
  7.     import traceback
  8.     import tempfile
  9.     import os
  10.     if exctype is not KeyboardInterrupt:
  11.         msg = "".join(traceback.format_exception(exctype, value, tb))
  12.         print >> sys.stderr, msg
  13.         fd, name = tempfile.mkstemp()
  14.         try:
  15.             os.write(fd,msg)
  16.             os.system("bug-buddy --include=\"%s\" --appname=\"%s\"" % (name, _appname))
  17.         finally:
  18.             os.unlink(name)
  19.     raise SystemExit
  20.  
  21.  
  22. def install(appname=None):
  23.     global _saved_except_hook, _appname
  24.     if appname is None:
  25.         appname = sys.argv[0]
  26.     _appname = appname
  27.     if sys.excepthook is not _bug_catcher:
  28.         _saved_except_hook = sys.excepthook
  29.         sys.excepthook = _bug_catcher
  30.  
  31.  
  32. def uninstall():
  33.     global _saved_except_hook
  34.     if sys.excepthook is _bug_catcher:
  35.         sys.excepthook = _saved_except_hook
  36.         _saved_except_hook = None
  37.  
  38.  
  39. if not sys.stderr.isatty():
  40.     install()
  41.