PLCOpenEditor.py
changeset 1737 a39c2918c015
parent 1736 7e61baa047f0
child 1739 ec153828ded2
equal deleted inserted replaced
1736:7e61baa047f0 1737:a39c2918c015
   458 
   458 
   459 def format_namespace(d, indent='    '):
   459 def format_namespace(d, indent='    '):
   460     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
   460     return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
   461 
   461 
   462 
   462 
   463 ignored_exceptions = [] # a problem with a line in a module is only reported once per session
   463 ignored_exceptions = []  # a problem with a line in a module is only reported once per session
   464 
   464 
   465 
   465 
   466 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]):
   466 def AddExceptHook(path, app_version='[No version]'):  #, ignored_exceptions=[]):
   467 
   467 
   468     def handle_exception(e_type, e_value, e_traceback):
   468     def handle_exception(e_type, e_value, e_traceback):
   469         traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
   469         traceback.print_exception(e_type, e_value, e_traceback)  # this is very helpful when there's an exception in the rest of this func
   470         last_tb = get_last_traceback(e_traceback)
   470         last_tb = get_last_traceback(e_traceback)
   471         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
   471         ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
   472         if str(e_value).startswith("!!!"):
   472         if str(e_value).startswith("!!!"):
   473             Display_Error_Dialog(e_value)
   473             Display_Error_Dialog(e_value)
   474         elif ex not in ignored_exceptions:
   474         elif ex not in ignored_exceptions:
   475             result = Display_Exception_Dialog(e_type,e_value,e_traceback)
   475             result = Display_Exception_Dialog(e_type,e_value,e_traceback)
   476             if result:
   476             if result:
   477                 ignored_exceptions.append(ex)
   477                 ignored_exceptions.append(ex)
   478                 info = {
   478                 info = {
   479                     'app-title' : wx.GetApp().GetAppName(), # app_title
   479                     'app-title' : wx.GetApp().GetAppName(),  # app_title
   480                     'app-version' : app_version,
   480                     'app-version' : app_version,
   481                     'wx-version' : wx.VERSION_STRING,
   481                     'wx-version' : wx.VERSION_STRING,
   482                     'wx-platform' : wx.Platform,
   482                     'wx-platform' : wx.Platform,
   483                     'python-version' : platform.python_version(), #sys.version.split()[0],
   483                     'python-version' : platform.python_version(),  #sys.version.split()[0],
   484                     'platform' : platform.platform(),
   484                     'platform' : platform.platform(),
   485                     'e-type' : e_type,
   485                     'e-type' : e_type,
   486                     'e-value' : e_value,
   486                     'e-value' : e_value,
   487                     'date' : time.ctime(),
   487                     'date' : time.ctime(),
   488                     'cwd' : os.getcwd(),
   488                     'cwd' : os.getcwd(),
   489                     }
   489                     }
   490                 if e_traceback:
   490                 if e_traceback:
   491                     info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
   491                     info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
   492                     last_tb = get_last_traceback(e_traceback)
   492                     last_tb = get_last_traceback(e_traceback)
   493                     exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
   493                     exception_locals = last_tb.tb_frame.f_locals  # the locals at the level of the stack trace where the exception actually occurred
   494                     info['locals'] = format_namespace(exception_locals)
   494                     info['locals'] = format_namespace(exception_locals)
   495                     if 'self' in exception_locals:
   495                     if 'self' in exception_locals:
   496                         info['self'] = format_namespace(exception_locals['self'].__dict__)
   496                         info['self'] = format_namespace(exception_locals['self'].__dict__)
   497 
   497 
   498                 output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt",'w')
   498                 output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt",'w')