Fixed changes from dporopat and agregorcic about WAMP CRA and config.
authorEdouard Tisserant
Wed, 10 Jan 2018 13:21:42 +0100
changeset 1894 f224383cc883
parent 1893 971de876b1af
child 1895 876ce4e492a1
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Beremiz_service.py
connectors/WAMP/__init__.py
runtime/WampClient.py
--- a/Beremiz_service.py	Tue Jan 09 15:08:08 2018 +0100
+++ b/Beremiz_service.py	Wed Jan 10 13:21:42 2018 +0100
@@ -576,6 +576,11 @@
             webport = None
         NS.WorkingDir = WorkingDir
 
+    if wampconf is None:
+        _wampconf = os.path.join(WorkingDir, "wampconf.json")
+        if os.path.exists(_wampconf) :
+            wampconf = _wampconf
+
     if wampconf is not None:
         try:
             import runtime.WampClient as WC  # pylint: disable=ungrouped-imports
@@ -600,21 +605,16 @@
 
     if wampconf is not None:
         try:
-            wampconf_project = os.path.join(WorkingDir, "wampconf.json")
-            _wampconf = WC.LoadWampClientConf(wampconf_project) # if project WAMP config is added
-
-            if not _wampconf:
-                # loaded wamp config file path forced parameter -c
-                _wampconf = WC.LoadWampClientConf(wampconf)
+            _wampconf = WC.LoadWampClientConf(wampconf) # if project WAMP config is added
+            if _wampconf :
+                if _wampconf["url"]: #TODO : test more ?
+                    WC.RegisterWampClient(wampconf, wampsecret)
+                    pyruntimevars["wampsession"] = WC.GetSession
+                    WC.SetServer(pyroserver)
+                else:
+                    print(_("WAMP config is incomplete."))
             else:
-                wampconf = wampconf_project
-
-            if _wampconf and _wampconf["url"]:
-                WC.RegisterWampClient(wampconf, wampsecret)
-                pyruntimevars["wampsession"] = WC.GetSession
-                WC.SetServer(pyroserver)
-            else:
-                print(_("WAMP config is not defined."))
+                print(_("WAMP config is missing."))
         except Exception, e:
             print(_("WAMP client startup failed. "), e)
 
--- a/connectors/WAMP/__init__.py	Tue Jan 09 15:08:08 2018 +0100
+++ b/connectors/WAMP/__init__.py	Wed Jan 10 13:21:42 2018 +0100
@@ -83,7 +83,7 @@
 
         # create a WAMP application session factory
         component_config = types.ComponentConfig(
-            realm=realm,
+            realm=unicode(realm),
             extra={"ID": ID})
         session_factory = wamp.ApplicationSessionFactory(
             config=component_config)
@@ -93,9 +93,7 @@
         transport_factory = WampWebSocketClientFactory(
             session_factory,
             url=url,
-            serializers=[MsgPackSerializer()],
-            debug=False,
-            debug_wamp=False)
+            serializers=[MsgPackSerializer()])
 
         # start the client from a Twisted endpoint
         conn = connectWS(transport_factory)
@@ -111,7 +109,7 @@
         reactor.run(installSignalHandlers=False)
 
     def WampSessionProcMapper(funcname):
-        wampfuncname = '.'.join((ID, funcname))
+        wampfuncname = unicode('.'.join((ID, funcname)))
 
         def catcher_func(*args, **kwargs):
             if _WampSession is not None:
--- a/runtime/WampClient.py	Tue Jan 09 15:08:08 2018 +0100
+++ b/runtime/WampClient.py	Wed Jan 10 13:21:42 2018 +0100
@@ -70,8 +70,7 @@
 
 class WampSession(wamp.ApplicationSession):
     def onConnect(self):
-        secret = self.config.extra["secret"]
-        if secret:
+        if self.config.extra.has_key("secret"):
             user = self.config.extra["ID"].encode('utf8')
             self.join(u"Automation", [u"wampcra"], user)
         else:
@@ -143,7 +142,7 @@
     WSClientConf = LoadWampClientConf(wampconf)
 
     if not WSClientConf:
-        print _("WAMP client connection not established!")
+        print(_("WAMP client connection not established!"))
         return
 
     WampSecret = LoadWampSecret(secretfname)
@@ -164,7 +163,7 @@
 
     # start the client from a Twisted endpoint
     conn = connectWS(transport_factory)
-    print(_("WAMP client connecting to :"), _WSClientConf["url"])
+    print(_("WAMP client connecting to :"), WSClientConf["url"])
     return conn