Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
--- a/Beremiz_service.py Tue Feb 10 00:25:17 2015 +0100
+++ b/Beremiz_service.py Mon Feb 16 16:23:51 2015 +0100
@@ -434,31 +434,12 @@
pyruntimevars = {}
statuschange = []
-registerserverto = []
if havetwisted:
if havewx:
reactor.registerWxApp(app)
- if webport is not None :
- try:
- import runtime.NevowServer as NS
- website = NS.RegisterWebsite(webport)
- pyruntimevars["website"] = website
- statuschange.append(NS.website_statuslistener_factory(website))
- except Exception, e:
- print "Nevow Web service failed.", e
-
- if wampconf is not None :
- try:
- import runtime.WampClient as WC
- WC.RegisterWampClient(wampconf)
- pyruntimevars["wampsession"] = WC.GetSession
- registerserverto.append(WC.SetServer)
- except Exception, e:
- print "WAMP client startup failed.", e
-
if havewx:
from threading import Semaphore
wx_eval_lock = Semaphore(0)
@@ -495,8 +476,6 @@
WorkingDir, argv, autostart,
statuschange, pyruntimevars=pyruntimevars)
-for registrar in registerserverto :
- registrar(pyroserver)
# Exception hooks s
import threading, traceback
@@ -523,12 +502,45 @@
threading.Thread.__init__ = init
installThreadExcepthook()
+if havetwisted:
+ if webport is not None :
+ try:
+ import runtime.NevowServer as NS
+ except Exception, e:
+ print "Nevow/Athena import failed :", e
+ webport = None
+
+ if wampconf is not None :
+ try:
+ import runtime.WampClient as WC
+ except Exception, e:
+ print "WAMP import failed :", e
+ wampconf = None
+
# Load extensions
for extfilename in extensions:
extension_folder = os.path.split(os.path.realpath(extfilename))[0]
sys.path.append(extension_folder)
execfile(extfilename, locals())
+if havetwisted:
+ if webport is not None :
+ try:
+ website = NS.RegisterWebsite(webport)
+ pyruntimevars["website"] = website
+ statuschange.append(NS.website_statuslistener_factory(website))
+ except Exception, e:
+ print "Nevow Web service failed.", e
+
+ if wampconf is not None :
+ try:
+ WC.RegisterWampClient(wampconf)
+ pyruntimevars["wampsession"] = WC.GetSession
+ WC.SetServer(pyroserver)
+ except Exception, e:
+ print "WAMP client startup failed.", e
+
+
if havetwisted or havewx:
pyro_thread=Thread(target=pyroserver.Loop)
pyro_thread.start()
--- a/runtime/WampClient.py Tue Feb 10 00:25:17 2015 +0100
+++ b/runtime/WampClient.py Mon Feb 16 16:23:51 2015 +0100
@@ -27,7 +27,12 @@
"ResetLogCount",
]
+SubscribedEvents = []
+
+DoOnJoin = []
+
def GetCallee(name):
+ """ Get Callee or Subscriber corresponding to '.' spearated object path """
global _PySrv
names = name.split('.')
obj = _PySrv.plcobj
@@ -45,6 +50,12 @@
for name in ExposedCalls:
reg = yield self.register(GetCallee(name), '.'.join((ID,name)))
+ for name in SubscribedEvents:
+ reg = yield self.subscribe(GetCallee(name), name)
+
+ for func in DoOnJoin:
+ yield func(self)
+
def onLeave(self, details):
global _WampSession
_WampSession = None
@@ -58,9 +69,14 @@
print("WAMP Client connection lost .. retrying ..")
self.retry(connector)
+def LoadWampClientConf(wampconf):
+
+ WSClientConf = json.load(open(wampconf))
+ return WSClientConf
+
def RegisterWampClient(wampconf):
- WSClientConf = json.load(open(wampconf))
+ WSClientConf = LoadWampClientConf(wampconf)
## start logging to console
# log.startLogging(sys.stdout)