1221 |
1221 |
1222 ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
1222 ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
1223 |
1223 |
1224 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
1224 def AddExceptHook(path, app_version='[No version]'):#, ignored_exceptions=[]): |
1225 |
1225 |
|
1226 def save_bug_report(e_type, e_value, e_traceback, bug_report_path,date): |
|
1227 info = { |
|
1228 'app-title': wx.GetApp().GetAppName(), # app_title |
|
1229 'app-version': app_version, |
|
1230 'wx-version': wx.VERSION_STRING, |
|
1231 'wx-platform': wx.Platform, |
|
1232 'python-version': platform.python_version(), # sys.version.split()[0], |
|
1233 'platform': platform.platform(), |
|
1234 'e-type': e_type, |
|
1235 'e-value': e_value, |
|
1236 'date': date, |
|
1237 'cwd': os.getcwd(), |
|
1238 } |
|
1239 if e_traceback: |
|
1240 info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
1241 last_tb = get_last_traceback(e_traceback) |
|
1242 exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
1243 info['locals'] = format_namespace(exception_locals) |
|
1244 if 'self' in exception_locals: |
|
1245 try: |
|
1246 info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1247 except: |
|
1248 pass |
|
1249 if not os.path.exists(path): |
|
1250 os.mkdir(path) |
|
1251 output = open(bug_report_path, 'w') |
|
1252 lst = info.keys() |
|
1253 lst.sort() |
|
1254 for a in lst: |
|
1255 output.write(a + ":\n" + str(info[a]) + "\n\n") |
|
1256 output.close() |
|
1257 |
1226 def handle_exception(e_type, e_value, e_traceback): |
1258 def handle_exception(e_type, e_value, e_traceback): |
1227 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
1259 traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
1228 last_tb = get_last_traceback(e_traceback) |
1260 last_tb = get_last_traceback(e_traceback) |
1229 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
1261 ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
1230 if ex not in ignored_exceptions: |
1262 if ex not in ignored_exceptions: |
|
1263 ignored_exceptions.append(ex) |
1231 date = time.ctime() |
1264 date = time.ctime() |
1232 try: |
1265 bug_report_path = path + os.sep + "bug_report_" + date.replace(':', '-').replace(' ', '_') + ".txt" |
1233 os.mkdir(path) |
1266 save_bug_report(e_type, e_value, e_traceback, bug_report_path, date) |
1234 except OSError: |
1267 Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path) |
1235 pass |
|
1236 bug_report_path = path+os.sep+"bug_report_"+date.replace(':','-').replace(' ','_')+".txt" |
|
1237 result = Display_Exception_Dialog(e_type,e_value,e_traceback,bug_report_path) |
|
1238 if result: |
|
1239 ignored_exceptions.append(ex) |
|
1240 info = { |
|
1241 'app-title' : wx.GetApp().GetAppName(), # app_title |
|
1242 'app-version' : app_version, |
|
1243 'wx-version' : wx.VERSION_STRING, |
|
1244 'wx-platform' : wx.Platform, |
|
1245 'python-version' : platform.python_version(), #sys.version.split()[0], |
|
1246 'platform' : platform.platform(), |
|
1247 'e-type' : e_type, |
|
1248 'e-value' : e_value, |
|
1249 'date' : date, |
|
1250 'cwd' : os.getcwd(), |
|
1251 } |
|
1252 if e_traceback: |
|
1253 info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
|
1254 last_tb = get_last_traceback(e_traceback) |
|
1255 exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
|
1256 info['locals'] = format_namespace(exception_locals) |
|
1257 if 'self' in exception_locals: |
|
1258 try : |
|
1259 info['self'] = format_namespace(exception_locals['self'].__dict__) |
|
1260 except : |
|
1261 pass |
|
1262 |
|
1263 output = open(bug_report_path,'w') |
|
1264 lst = info.keys() |
|
1265 lst.sort() |
|
1266 for a in lst: |
|
1267 output.write(a+":\n"+str(info[a])+"\n\n") |
|
1268 output.close() |
|
1269 |
|
1270 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
1268 #sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
1271 sys.excepthook = handle_exception |
1269 sys.excepthook = handle_exception |
1272 |
1270 |
1273 init_old = threading.Thread.__init__ |
1271 init_old = threading.Thread.__init__ |
1274 def init(self, *args, **kwargs): |
1272 def init(self, *args, **kwargs): |