author | Edouard Tisserant |
Wed, 31 Jan 2018 15:25:30 +0100 | |
changeset 1918 | e7b6478b4ebc |
parent 1881 | 091005ec69c4 |
child 1941 | cde74a39df51 |
permissions | -rw-r--r-- |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
3 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
6 |
# |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
7 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
8 |
# Copyright (C) 2016-2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
9 |
# |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
11 |
# |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
16 |
# |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
20 |
# GNU General Public License for more details. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
21 |
# |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
25 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
26 |
|
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1792
diff
changeset
|
27 |
from __future__ import absolute_import |
1792
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
28 |
import os |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
29 |
import sys |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
30 |
import time |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
31 |
import tempfile |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
32 |
import platform |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
33 |
import traceback |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
34 |
import threading |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
35 |
import wx |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
36 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
37 |
Max_Traceback_List_Size = 20 |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
38 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
39 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
40 |
def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
41 |
trcbck_lst = [] |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
42 |
for i, line in enumerate(traceback.extract_tb(e_tb)): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
43 |
trcbck = " " + str(i+1) + ". " |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
44 |
if line[0].find(os.getcwd()) == -1: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
45 |
trcbck += "file : " + str(line[0]) + ", " |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
46 |
else: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
47 |
trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
48 |
trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
49 |
trcbck_lst.append(trcbck) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
50 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
51 |
# Allow clicking.... |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
52 |
cap = wx.Window_GetCapture() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
53 |
if cap: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
54 |
cap.ReleaseMouse() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
55 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
56 |
dlg = wx.SingleChoiceDialog( |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
57 |
None, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
58 |
_(""" |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
59 |
An unhandled exception (bug) occured. Bug report saved at : |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
60 |
(%s) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
61 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
62 |
Please be kind enough to send this file to: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
63 |
beremiz-devel@lists.sourceforge.net |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
64 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
65 |
You should now restart program. |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
66 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
67 |
Traceback: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
68 |
""") % bug_report_path + |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
69 |
repr(e_type) + " : " + repr(e_value), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
70 |
_("Error"), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
71 |
trcbck_lst) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
72 |
try: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
73 |
res = (dlg.ShowModal() == wx.ID_OK) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
74 |
finally: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
75 |
dlg.Destroy() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
76 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
77 |
return res |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
78 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
79 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
80 |
def get_last_traceback(tb): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
81 |
while tb.tb_next: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
82 |
tb = tb.tb_next |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
83 |
return tb |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
84 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
85 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
86 |
def format_namespace(d, indent=' '): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
87 |
return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
88 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
89 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
90 |
ignored_exceptions = [] # a problem with a line in a module is only reported once per session |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
91 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
92 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
93 |
def AddExceptHook(app_version='[No version]'): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
94 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
95 |
def save_bug_report(e_type, e_value, e_traceback, bug_report_path, date): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
96 |
info = { |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
97 |
'app-title': wx.GetApp().GetAppName(), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
98 |
'app-version': app_version, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
99 |
'wx-version': wx.VERSION_STRING, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
100 |
'wx-platform': wx.Platform, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
101 |
'python-version': platform.python_version(), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
102 |
'platform': platform.platform(), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
103 |
'e-type': e_type, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
104 |
'e-value': e_value, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
105 |
'date': date, |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
106 |
'cwd': os.getcwd(), |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
107 |
} |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
108 |
if e_traceback: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
109 |
info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
110 |
last_tb = get_last_traceback(e_traceback) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
111 |
exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
112 |
info['locals'] = format_namespace(exception_locals) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
113 |
if 'self' in exception_locals: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
114 |
try: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
115 |
info['self'] = format_namespace(exception_locals['self'].__dict__) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
116 |
except Exception: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
117 |
pass |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
118 |
path = os.path.dirname(bug_report_path) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
119 |
if not os.path.exists(path): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
120 |
os.mkdir(path) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
121 |
output = open(bug_report_path, 'w') |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
122 |
lst = info.keys() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
123 |
lst.sort() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
124 |
for a in lst: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
125 |
output.write(a + ":\n" + str(info[a]) + "\n\n") |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
126 |
output.close() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
127 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
128 |
def handle_exception(e_type, e_value, e_traceback): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
129 |
traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
130 |
last_tb = get_last_traceback(e_traceback) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
131 |
ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
132 |
if ex not in ignored_exceptions: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
133 |
ignored_exceptions.append(ex) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
134 |
date = time.ctime() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
135 |
path = tempfile.gettempdir()+os.sep+wx.GetApp().GetAppName() |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
136 |
bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt" |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
137 |
save_bug_report(e_type, e_value, e_traceback, bug_report_path, date) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
138 |
Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
139 |
# sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
140 |
sys.excepthook = handle_exception |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
141 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
142 |
init_old = threading.Thread.__init__ |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
143 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
144 |
def init(self, *args, **kwargs): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
145 |
init_old(self, *args, **kwargs) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
146 |
run_old = self.run |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
147 |
|
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
148 |
def run_with_except_hook(*args, **kw): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
149 |
try: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
150 |
run_old(*args, **kw) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
151 |
except (KeyboardInterrupt, SystemExit): |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
152 |
raise |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
153 |
except Exception: |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
154 |
sys.excepthook(*sys.exc_info()) |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
155 |
self.run = run_with_except_hook |
4d1de8b0183f
unify exception handling of Beremiz and PLCOpenEditor
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
diff
changeset
|
156 |
threading.Thread.__init__ = init |