home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1715 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.3 KB  |  120 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import sys
  6. from pprint import pprint, pformat
  7. from IPython import Release
  8. from IPython import ultraTB
  9. from IPython.ColorANSI import ColorScheme, ColorSchemeTable
  10. from IPython.Itpl import Itpl, itpl, printpl
  11. from IPython.genutils import *
  12.  
  13. class CrashHandler:
  14.     
  15.     def __init__(self, IP, app_name, contact_name, contact_email, bug_tracker, crash_report_fname, show_crash_traceback = True):
  16.         self.IP = IP
  17.         self.app_name = app_name
  18.         self.contact_name = contact_name
  19.         self.contact_email = contact_email
  20.         self.bug_tracker = bug_tracker
  21.         self.crash_report_fname = crash_report_fname
  22.         self.show_crash_traceback = show_crash_traceback
  23.         self.user_message_template = "\nOops, $self.app_name crashed. We do our best to make it stable, but...\n\nA crash report was automatically generated with the following information:\n  - A verbatim copy of the crash traceback.\n  - A copy of your input history during this session.\n  - Data on your current $self.app_name configuration.\n\nIt was left in the file named:\n\t'$self.crash_report_fname'\nIf you can email this file to the developers, the information in it will help\nthem in understanding and correcting the problem.\n\nYou can mail it to: $self.contact_name at $self.contact_email\nwith the subject '$self.app_name Crash Report'.\n\nIf you want to do it now, the following command will work (under Unix):\nmail -s '$self.app_name Crash Report' $self.contact_email < $self.crash_report_fname\n\nTo ensure accurate tracking of this issue, please file a report about it at:\n$self.bug_tracker\n"
  24.  
  25.     
  26.     def __call__(self, etype, evalue, etb):
  27.         color_scheme = 'NoColor'
  28.         
  29.         try:
  30.             rptdir = self.IP.rc.ipythondir
  31.         except:
  32.             rptdir = os.getcwd()
  33.  
  34.         if not os.path.isdir(rptdir):
  35.             rptdir = os.getcwd()
  36.         
  37.         report_name = os.path.join(rptdir, self.crash_report_fname)
  38.         self.crash_report_fname = report_name
  39.         TBhandler = ultraTB.VerboseTB(color_scheme = color_scheme, long_header = 1)
  40.         traceback = TBhandler.text(etype, evalue, etb, context = 31)
  41.         if self.show_crash_traceback:
  42.             print >>sys.stderr, traceback
  43.         
  44.         
  45.         try:
  46.             report = open(report_name, 'w')
  47.         except:
  48.             print >>sys.stderr, 'Could not create crash report on disk.'
  49.             return None
  50.  
  51.         msg = itpl('\n' + '*' * 70 + '\n' + self.user_message_template)
  52.         print >>sys.stderr, msg
  53.         report.write(self.make_report(traceback))
  54.         report.close()
  55.         raw_input('Press enter to exit:')
  56.  
  57.     
  58.     def make_report(self, traceback):
  59.         sec_sep = '\n\n' + '*' * 75 + '\n\n'
  60.         report = []
  61.         rpt_add = report.append
  62.         rpt_add('*' * 75 + '\n\n' + 'IPython post-mortem report\n\n')
  63.         rpt_add('IPython version: %s \n\n' % Release.version)
  64.         rpt_add('BZR revision   : %s \n\n' % Release.revision)
  65.         rpt_add('Platform info  : os.name -> %s, sys.platform -> %s' % (os.name, sys.platform))
  66.         rpt_add(sec_sep + 'Current user configuration structure:\n\n')
  67.         rpt_add(pformat(self.IP.rc.dict()))
  68.         rpt_add(sec_sep + 'Crash traceback:\n\n' + traceback)
  69.         
  70.         try:
  71.             rpt_add(sec_sep + 'History of session input:')
  72.             for line in self.IP.user_ns['_ih']:
  73.                 rpt_add(line)
  74.             
  75.             rpt_add('\n*** Last line of input (may not be in above history):\n')
  76.             rpt_add(self.IP._last_input_line + '\n')
  77.         except:
  78.             pass
  79.  
  80.         return ''.join(report)
  81.  
  82.  
  83.  
  84. class IPythonCrashHandler(CrashHandler):
  85.     
  86.     def __init__(self, IP):
  87.         AUTHOR_CONTACT = 'Fernando'
  88.         app_name = 'IPython'
  89.         bug_tracker = 'https://bugs.launchpad.net/ipython/+filebug'
  90.         (contact_name, contact_email) = Release.authors[AUTHOR_CONTACT][:2]
  91.         crash_report_fname = 'IPython_crash_report.txt'
  92.         CrashHandler.__init__(self, IP, app_name, contact_name, contact_email, bug_tracker, crash_report_fname)
  93.  
  94.     
  95.     def make_report(self, traceback):
  96.         sec_sep = '\n\n' + '*' * 75 + '\n\n'
  97.         report = []
  98.         rpt_add = report.append
  99.         rpt_add('*' * 75 + '\n\n' + 'IPython post-mortem report\n\n')
  100.         rpt_add('IPython version: %s \n\n' % Release.version)
  101.         rpt_add('BZR revision   : %s \n\n' % Release.revision)
  102.         rpt_add('Platform info  : os.name -> %s, sys.platform -> %s' % (os.name, sys.platform))
  103.         rpt_add(sec_sep + 'Current user configuration structure:\n\n')
  104.         rpt_add(pformat(self.IP.rc.dict()))
  105.         rpt_add(sec_sep + 'Crash traceback:\n\n' + traceback)
  106.         
  107.         try:
  108.             rpt_add(sec_sep + 'History of session input:')
  109.             for line in self.IP.user_ns['_ih']:
  110.                 rpt_add(line)
  111.             
  112.             rpt_add('\n*** Last line of input (may not be in above history):\n')
  113.             rpt_add(self.IP._last_input_line + '\n')
  114.         except:
  115.             pass
  116.  
  117.         return ''.join(report)
  118.  
  119.  
  120.