home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / CommandNotFound / util.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.1 KB  |  75 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import sys
  5.  
  6. def no_gettext_for_you(message):
  7.     '''This function is used instead of gettext when there are some locale problems'''
  8.     return message
  9.  
  10.  
  11. def setup_locale():
  12.     import locale
  13.     
  14.     try:
  15.         import gettext
  16.         locale.getpreferredencoding()
  17.         gettext.bindtextdomain('command-not-found', '/usr/share/locale')
  18.         gettext.textdomain('command-not-found')
  19.         gettext.install('command-not-found', unicode = True)
  20.         return gettext.lgettext
  21.     except locale.Error:
  22.         return no_gettext_for_you
  23.  
  24.  
  25. _ = gettext_wrapper = setup_locale()
  26.  
  27. def crash_guard(callback, bug_report_url, version):
  28.     ''' Calls callback and catches all exceptions.
  29.     When something bad happens prints a long error message
  30.     with bug report information and exits the program'''
  31.     
  32.     try:
  33.         callback()
  34.     except Exception:
  35.         ex = None
  36.         print >>sys.stderr, _('Sorry, command-not-found has crashed! Please file a bug report at:')
  37.         print >>sys.stderr, bug_report_url
  38.         print >>sys.stderr, _('Please include the following information with the report:')
  39.         print >>sys.stderr
  40.         print >>sys.stderr, _('command-not-found version: %s') % version
  41.         print >>sys.stderr, _('Python version: %d.%d.%d %s %d') % sys.version_info
  42.         
  43.         try:
  44.             import subprocess
  45.             subprocess.call([
  46.                 'lsb_release',
  47.                 '-i',
  48.                 '-d',
  49.                 '-r',
  50.                 '-c'], stdout = sys.stderr)
  51.         except (ImportError, OSError):
  52.             pass
  53.  
  54.         print >>sys.stderr, _('Exception information:')
  55.         print >>sys.stderr
  56.         print >>sys.stderr, ex
  57.         
  58.         try:
  59.             import traceback
  60.             traceback.print_exc()
  61.         except ImportError:
  62.             pass
  63.         except:
  64.             None<EXCEPTION MATCH>ImportError
  65.         
  66.  
  67.         None<EXCEPTION MATCH>ImportError
  68.     finally:
  69.         sys.exit(127)
  70.  
  71.  
  72. __all__ = [
  73.     'gettext_wrapper',
  74.     'crash_guard']
  75.