--- a/Beremiz.py Fri Aug 25 12:23:45 2017 +0300
+++ b/Beremiz.py Fri Aug 25 14:01:44 2017 +0300
@@ -175,9 +175,8 @@
def InstallExceptionHandler(self):
- logpath = tempfile.gettempdir()+os.sep+'Beremiz'
- BeremizIDE.AddExceptHook(logpath, version.app_version)
+ import util.ExceptionHandler + util.ExceptionHandler.AddExceptHook(version.app_version) self.frame = BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath)
--- a/BeremizIDE.py Fri Aug 25 12:23:45 2017 +0300
+++ b/BeremizIDE.py Fri Aug 25 14:01:44 2017 +0300
@@ -41,11 +41,8 @@
from threading import Lock, Timer, currentThread
from time import time as gettime
@@ -1106,127 +1103,3 @@
viewer.AddHighlight(infos[1:], start, end, highlight_type)
IDEFrame.ShowHighlight(self, infos, start, end, highlight_type)
-# -------------------------------------------------------------------------------
-# -------------------------------------------------------------------------------
-Max_Traceback_List_Size = 20
-def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path):
- for i, line in enumerate(traceback.extract_tb(e_tb)):
- trcbck = " " + str(i+1) + ". "
- if line[0].find(os.getcwd()) == -1:
- trcbck += "file : " + str(line[0]) + ", "
- trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", "
- trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2])
- trcbck_lst.append(trcbck)
- cap = wx.Window_GetCapture()
- dlg = wx.SingleChoiceDialog(
-An unhandled exception (bug) occured. Bug report saved at :
-Please be kind enough to send this file to:
-beremiz-devel@lists.sourceforge.net
-You should now restart program.
-""") % bug_report_path +
- repr(e_type) + " : " + repr(e_value),
- res = (dlg.ShowModal() == wx.ID_OK)
-def get_last_traceback(tb):
-def format_namespace(d, indent=' '):
- return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
-ignored_exceptions = [] # a problem with a line in a module is only reported once per session
-def AddExceptHook(path, app_version='[No version]'):
- def save_bug_report(e_type, e_value, e_traceback, bug_report_path, date):
- 'app-title': wx.GetApp().GetAppName(),
- 'app-version': app_version,
- 'wx-version': wx.VERSION_STRING,
- 'wx-platform': wx.Platform,
- 'python-version': platform.python_version(),
- 'platform': platform.platform(),
- info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
- last_tb = get_last_traceback(e_traceback)
- exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
- info['locals'] = format_namespace(exception_locals)
- if 'self' in exception_locals:
- info['self'] = format_namespace(exception_locals['self'].__dict__)
- if not os.path.exists(path):
- output = open(bug_report_path, 'w')
- output.write(a + ":\n" + str(info[a]) + "\n\n")
- def handle_exception(e_type, e_value, e_traceback):
- traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
- last_tb = get_last_traceback(e_traceback)
- ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
- if ex not in ignored_exceptions:
- ignored_exceptions.append(ex)
- bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt"
- save_bug_report(e_type, e_value, e_traceback, bug_report_path, date)
- Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path)
- # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
- sys.excepthook = handle_exception
- init_old = threading.Thread.__init__
- def init(self, *args, **kwargs):
- init_old(self, *args, **kwargs)
- def run_with_except_hook(*args, **kw):
- except (KeyboardInterrupt, SystemExit):
- sys.excepthook(*sys.exc_info())
- self.run = run_with_except_hook
- threading.Thread.__init__ = init
--- a/PLCOpenEditor.py Fri Aug 25 12:23:45 2017 +0300
+++ b/PLCOpenEditor.py Fri Aug 25 14:01:44 2017 +0300
@@ -26,17 +26,15 @@
import util.paths as paths
+import util.ExceptionHandler beremiz_dir = paths.AbsDir(__file__)
-__version__ = "$Revision: 1.130 $"
if __name__ == '__main__':
# Usage message displayed when help request or when error detected in
@@ -79,7 +77,7 @@
# these imports require wx.GetApp to return
# a valid application instance
from IDEFrame import IDEFrame, AppendMenu
@@ -415,121 +413,13 @@
self._Refresh(TITLE, FILEMENU, PAGETITLES)
-# -------------------------------------------------------------------------------
-# -------------------------------------------------------------------------------
-Max_Traceback_List_Size = 20
-def Display_Exception_Dialog(e_type, e_value, e_tb):
- for i, line in enumerate(traceback.extract_tb(e_tb)):
- trcbck = " " + str(i+1) + _(". ")
- if line[0].find(os.getcwd()) == -1:
- trcbck += _("file : ") + str(line[0]) + _(", ")
- trcbck += _("file : ") + str(line[0][len(os.getcwd()):]) + _(", ")
- trcbck += _("line : ") + str(line[1]) + _(", ") + _("function : ") + str(line[2])
- trcbck_lst.append(trcbck)
- cap = wx.Window_GetCapture()
- dlg = wx.SingleChoiceDialog(
-An unhandled exception (bug) occured. Bug report saved at :
-Please be kind enough to send this file to:
-beremiz-devel@lists.sourceforge.net
-You should now restart program.
-""") % bug_report_path +
- repr(e_type) + " : " + repr(e_value),
- res = (dlg.ShowModal() == wx.ID_OK)
-def Display_Error_Dialog(e_value):
- message = wx.MessageDialog(None, str(e_value), _("Error"), wx.OK | wx.ICON_ERROR)
-def get_last_traceback(tb):
-def format_namespace(d, indent=' '):
- return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()])
-ignored_exceptions = [] # a problem with a line in a module is only reported once per session
-def AddExceptHook(path, app_version='[No version]'):
- def handle_exception(e_type, e_value, e_traceback):
- traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func
- last_tb = get_last_traceback(e_traceback)
- ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno)
- if str(e_value).startswith("!!!"):
- Display_Error_Dialog(e_value)
- elif ex not in ignored_exceptions:
- result = Display_Exception_Dialog(e_type, e_value, e_traceback)
- ignored_exceptions.append(ex)
- 'app-title': wx.GetApp().GetAppName(),
- 'app-version': app_version,
- 'wx-version': wx.VERSION_STRING,
- 'wx-platform': wx.Platform,
- 'python-version': platform.python_version(),
- 'platform': platform.platform(),
- info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value)
- last_tb = get_last_traceback(e_traceback)
- exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred
- info['locals'] = format_namespace(exception_locals)
- if 'self' in exception_locals:
- info['self'] = format_namespace(exception_locals['self'].__dict__)
- output = open(path+os.sep+"bug_report_"+time.strftime("%Y_%m_%d__%H-%M-%S")+".txt", 'w')
- output.write(a+":\n"+str(info[a])+"\n\n")
- # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args)
- sys.excepthook = handle_exception
if __name__ == '__main__':
if wx.VERSION < (3, 0, 0):
wx.InitAllImageHandlers()
# Install a exception handle for bug reports
- AddExceptHook(os.getcwd(), version.app_version)
+ util.ExceptionHandler.AddExceptHook(version.app_version) frame = PLCOpenEditor(None, fileOpen=fileOpen)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/ExceptionHandler.py Fri Aug 25 14:01:44 2017 +0300
@@ -0,0 +1,154 @@
+# This file is part of Beremiz, a Integrated Development Environment for +# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. +# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD +# Copyright (C) 2016-2017: Andrey Skvortsov <andrej.skvortzov@gmail.com> +# See COPYING file for copyrights details. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +Max_Traceback_List_Size = 20 +def Display_Exception_Dialog(e_type, e_value, e_tb, bug_report_path): + for i, line in enumerate(traceback.extract_tb(e_tb)): + trcbck = " " + str(i+1) + ". " + if line[0].find(os.getcwd()) == -1: + trcbck += "file : " + str(line[0]) + ", " + trcbck += "file : " + str(line[0][len(os.getcwd()):]) + ", " + trcbck += "line : " + str(line[1]) + ", " + "function : " + str(line[2]) + trcbck_lst.append(trcbck) + cap = wx.Window_GetCapture() + dlg = wx.SingleChoiceDialog( +An unhandled exception (bug) occured. Bug report saved at : +Please be kind enough to send this file to: +beremiz-devel@lists.sourceforge.net +You should now restart program. +""") % bug_report_path + + repr(e_type) + " : " + repr(e_value), + res = (dlg.ShowModal() == wx.ID_OK) +def get_last_traceback(tb): +def format_namespace(d, indent=' '): + return '\n'.join(['%s%s: %s' % (indent, k, repr(v)[:10000]) for k, v in d.iteritems()]) +ignored_exceptions = [] # a problem with a line in a module is only reported once per session +def AddExceptHook(app_version='[No version]'): + def save_bug_report(e_type, e_value, e_traceback, bug_report_path, date): + 'app-title': wx.GetApp().GetAppName(), + 'app-version': app_version, + 'wx-version': wx.VERSION_STRING, + 'wx-platform': wx.Platform, + 'python-version': platform.python_version(), + 'platform': platform.platform(), + info['traceback'] = ''.join(traceback.format_tb(e_traceback)) + '%s: %s' % (e_type, e_value) + last_tb = get_last_traceback(e_traceback) + exception_locals = last_tb.tb_frame.f_locals # the locals at the level of the stack trace where the exception actually occurred + info['locals'] = format_namespace(exception_locals) + if 'self' in exception_locals: + info['self'] = format_namespace(exception_locals['self'].__dict__) + path = os.path.dirname(bug_report_path) + if not os.path.exists(path): + output = open(bug_report_path, 'w') + output.write(a + ":\n" + str(info[a]) + "\n\n") + def handle_exception(e_type, e_value, e_traceback): + traceback.print_exception(e_type, e_value, e_traceback) # this is very helpful when there's an exception in the rest of this func + last_tb = get_last_traceback(e_traceback) + ex = (last_tb.tb_frame.f_code.co_filename, last_tb.tb_frame.f_lineno) + if ex not in ignored_exceptions: + ignored_exceptions.append(ex) + path = tempfile.gettempdir()+os.sep+wx.GetApp().GetAppName() + bug_report_path = path + os.sep + "bug_report_" + time.strftime("%Y_%m_%d__%H-%M-%S") + ".txt" + save_bug_report(e_type, e_value, e_traceback, bug_report_path, date) + Display_Exception_Dialog(e_type, e_value, e_traceback, bug_report_path) + # sys.excepthook = lambda *args: wx.CallAfter(handle_exception, *args) + sys.excepthook = handle_exception + init_old = threading.Thread.__init__ + def init(self, *args, **kwargs): + init_old(self, *args, **kwargs) + def run_with_except_hook(*args, **kw): + except (KeyboardInterrupt, SystemExit): + sys.excepthook(*sys.exc_info()) + self.run = run_with_except_hook + threading.Thread.__init__ = init