--- a/Beremiz_service.py Wed Jul 04 14:17:00 2018 +0200
+++ b/Beremiz_service.py Thu Jul 05 11:11:01 2018 +0200
@@ -623,15 +623,8 @@
- WC.SetServer(pyroserver, wampconf, wampsecret)
- _wampconf = WC.GetConfiguration()
- if _wampconf.get("url", False) and _wampconf.get("active", False): # TODO : test more ?
- WC.RegisterWampClient()
- raise Exception(_("WAMP config is incomplete or active is false."))
- raise Exception(_("WAMP config is missing."))
+ WC.SetServer(pyroserver) + WC.RegisterWampClient(wampconf, wampsecret) LogMessageAndException(_("WAMP client startup failed. "))
--- a/runtime/WampClient.py Wed Jul 04 14:17:00 2018 +0200
+++ b/runtime/WampClient.py Thu Jul 05 11:11:01 2018 +0200
@@ -36,6 +36,8 @@
from twisted.internet.protocol import ReconnectingClientFactory
+mandatoryConfigItems = ["ID", "active", "realm", "url"] @@ -74,15 +76,6 @@
obj = getattr(obj, names.pop(0))
-def getValidOptins(options, arguments):
- validOptions[key] = options[key]
- if len(validOptions) > 0:
class WampSession(wamp.ApplicationSession):
@@ -164,45 +157,25 @@
-def GetConfiguration(items=None):
- WSClientConf = json.load(open(_WampConf))
- if items and isinstance(items, list):
- wampconf_value = WSClientConf.get(item, None)
- if wampconf_value is not None:
- WSClientConfItems[item] = wampconf_value
- return WSClientConfItems
- print(_("WAMP load error: "), ve)
- print(_("WAMP load error: "), e)
+ WSClientConf = json.load(open(_WampConf)) + for itemName in mandatoryConfigItems: + if WSClientConf.get(itemName, None) is None : + raise Exception(_("WAMP configuration error : missing '{}' parameter.").format(itemName)) -def SetConfiguration(items):
+def SetConfiguration(WSClientConf): - WSClientConf = json.load(open(_WampConf))
- for itemKey in items.keys():
- wampconf_value = WSClientConf.get(itemKey, None)
- if (wampconf_value is not None) and (items[itemKey] is not None) and (wampconf_value != items[itemKey]):
- WSClientConf[itemKey] = items[itemKey]
- with open(os.path.realpath(_WampConf), 'w') as f:
- json.dump(WSClientConf, f, sort_keys=True, indent=4)
- if 'active' in WSClientConf and WSClientConf['active']:
- if _transportFactory and _WampSession:
- StopReconnectWampClient()
- StartReconnectWampClient()
+ with open(os.path.realpath(_WampConf), 'w') as f: + json.dump(WSClientConf, f, sort_keys=True, indent=4) + if 'active' in WSClientConf and WSClientConf['active']: + if _transportFactory and _WampSession: StopReconnectWampClient()
+ StartReconnectWampClient() + StopReconnectWampClient() @@ -212,6 +185,7 @@
print(_("WAMP save error: "), e)
def LoadWampSecret(secretfname):
WSClientWampSecret = open(secretfname, 'rb').read()
@@ -230,26 +204,23 @@
-def RegisterWampClient(wampconf=None, secretfname=None):
+def RegisterWampClient(wampconf=None, wampsecret=None): + global _WampConf, _WampSecret + _WampSecret = wampsecret - WSClientConf = GetConfiguration()
- WSClientConf = GetConfiguration()
- print(_("WAMP client connection not established!"))
+ WSClientConf = GetConfiguration() if not IsCorrectUri(WSClientConf["url"]):
- print(_("WAMP url {} is not correct!".format(WSClientConf["url"])))
+ raise Exception(_("WAMP url {} is not correct!").format(WSClientConf["url"]))
- WampSecret = LoadWampSecret(secretfname)
- WampSecret = LoadWampSecret(_WampSecret)
+ if not WSClientConf["active"]: + print(_("WAMP deactivated in configuration")) + WampSecret = LoadWampSecret(_WampSecret) if WampSecret is not None:
WSClientConf["secret"] = WampSecret
@@ -303,8 +274,5 @@
return _WampSession and _WampSession.is_attached()
-def SetServer(pysrv, wampconf=None, wampsecret=None):
- global _PySrv, _WampConf, _WampSecret
- _WampSecret = wampsecret