--- a/Beremiz_service.py Mon Jan 29 12:56:49 2018 +0100
+++ b/Beremiz_service.py Mon Jan 29 13:31:14 2018 +0100
@@ -110,7 +110,9 @@
elif o == "-s":
wampsecret = None if a == "off" else a
elif o == "-e":
- extensions.append(a)
+ l = list(os.path.split(os.path.realpath(a)))
+ l.reverse()
+ extensions.append(l)
else:
usage()
sys.exit()
@@ -536,12 +538,18 @@
# Exception hooks s
+
+def LogMessageAndException(msg, exp=None):
+ if exp is None:
+ exp = sys.exc_info()
+ if pyroserver.plcobj is not None:
+ pyroserver.plcobj.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp)))
+ else:
+ print(msg)
+ traceback.print_exception(*exp)
+
def LogException(*exp):
- if pyroserver.plcobj is not None:
- pyroserver.plcobj.LogMessage(0, '\n'.join(traceback.format_exception(*exp)))
- else:
- traceback.print_exception(*exp)
-
+ LogExceptionAndMessage("",exp)
sys.excepthook = LogException
@@ -588,10 +596,9 @@
wampconf = None
# Load extensions
-for extfilename in extensions:
- extension_folder = os.path.split(os.path.realpath(extfilename))[0]
+for extention_file, extension_folder in extensions:
sys.path.append(extension_folder)
- execfile(extfilename, locals())
+ execfile(os.path.join(extension_folder, extention_file), locals())
if havetwisted:
if webport is not None:
@@ -599,8 +606,8 @@
website = NS.RegisterWebsite(webport)
pyruntimevars["website"] = website
statuschange.append(NS.website_statuslistener_factory(website))
- except Exception, e:
- print(_("Nevow Web service failed. "), e)
+ except Exception:
+ LogMessageAndException(_("Nevow Web service failed. "))
if wampconf is not None:
try:
@@ -611,11 +618,11 @@
pyruntimevars["wampsession"] = WC.GetSession
WC.SetServer(pyroserver)
else:
- print(_("WAMP config is incomplete."))
+ raise Exception(_("WAMP config is incomplete."))
else:
- print(_("WAMP config is missing."))
- except Exception, e:
- print(_("WAMP client startup failed. "), e)
+ raise Exception(_("WAMP config is missing."))
+ except Exception:
+ LogMessageAndException(_("WAMP client startup failed. "))
if havetwisted or havewx:
@@ -629,7 +636,7 @@
else:
try:
pyroserver.Loop()
- except KeyboardInterrupt, e:
+ except KeyboardInterrupt:
pass
pyroserver.Quit()
sys.exit(0)
--- a/runtime/PLCObject.py Mon Jan 29 12:56:49 2018 +0100
+++ b/runtime/PLCObject.py Mon Jan 29 13:31:14 2018 +0100
@@ -106,7 +106,10 @@
else:
level = LogLevelsDefault
msg, = args
- return self._LogMessage(level, msg, len(msg))
+ PLCprint(msg)
+ if self._LogMessage is not None:
+ return self._LogMessage(level, msg, len(msg))
+ return None
def ResetLogCount(self):
if self._ResetLogCount is not None:
@@ -254,7 +257,7 @@
self._resumeDebug = lambda: None
self._PythonIterator = lambda: ""
self._GetLogCount = None
- self._LogMessage = lambda l, m, s: PLCprint("OFF LOG :"+m)
+ self._LogMessage = None
self._GetLogMessage = None
self.PLClibraryHandle = None
# Unload library explicitely