# HG changeset patch # User Edouard Tisserant # Date 1532077517 -7200 # Node ID 2a9549e4380eb2c0f2c4f6e67a6e0cc4a9ef3757 # Parent 7f59aa39866926bcc2e2494f5f6e82dced810b83# Parent ebd83ec387f94f7d66bf4e621e2e94beb75ca729 Merged diff -r 7f59aa398669 -r 2a9549e4380e Beremiz_service.py --- a/Beremiz_service.py Fri Jun 15 09:48:05 2018 +0200 +++ b/Beremiz_service.py Fri Jul 20 11:05:17 2018 +0200 @@ -45,17 +45,17 @@ print(""" Usage of Beremiz PLC execution service :\n %s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir - -n - zeroconf service name (default:disabled) - -i - IP address of interface to bind to (default:localhost) - -p - port number default:3000 - -h - print this help text and quit - -a - autostart PLC (0:disable 1:enable) (default:0) - -x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) - -t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) - -w - web server port or "off" to disable web server (default:8009) - -c - WAMP client default config file (default:wampconf.json) - -s - WAMP client secret, given as a file - -e - python extension (absolute path .py) + -n zeroconf service name (default:disabled) + -i IP address of interface to bind to (default:localhost) + -p port number default:3000 + -h print this help text and quit + -a autostart PLC (0:disable 1:enable) (default:0) + -x enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) + -t enable/disable Twisted web interface (0:disable 1:enable) (default:1) + -w web server port or "off" to disable web server (default:8009) + -c WAMP client config file (can be overriden by wampconf.json in project) + -s WAMP client secret, given as a file (can be overriden by wamp.secret in project) + -e python extension (absolute path .py) working_dir - directory where are stored PLC files """ % sys.argv[0]) @@ -582,29 +582,23 @@ installThreadExcepthook() +havewamp = False if havetwisted: if webport is not None: try: import runtime.NevowServer as NS # pylint: disable=ungrouped-imports - except Exception, e: - print(_("Nevow/Athena import failed :"), e) + except Exception: + LogMessageAndException(_("Nevow/Athena import failed :")) webport = None NS.WorkingDir = WorkingDir - # Find pre-existing project WAMP config file - _wampconf = os.path.join(WorkingDir, "wampconf.json") - - # If project's WAMP config file exits, override default (-c) - if os.path.exists(_wampconf): - wampconf = _wampconf - - if wampconf is not None: - try: - import runtime.WampClient as WC # pylint: disable=ungrouped-imports - except Exception, e: - print(_("WAMP import failed :"), e) - wampconf = None + try: + import runtime.WampClient as WC # pylint: disable=ungrouped-imports + WC.WorkingDir = WorkingDir + havewamp = True + except Exception: + LogMessageAndException(_("WAMP import failed :")) # Load extensions for extention_file, extension_folder in extensions: @@ -616,22 +610,16 @@ try: website = NS.RegisterWebsite(webport) pyruntimevars["website"] = website + NS.SetServer(pyroserver) statuschange.append(NS.website_statuslistener_factory(website)) except Exception: LogMessageAndException(_("Nevow Web service failed. ")) - if wampconf is not None: + if havewamp: try: - _wampconf = WC.LoadWampClientConf(wampconf) - if _wampconf: - if _wampconf["url"]: # TODO : test more ? - WC.RegisterWampClient(wampconf, wampsecret) - pyruntimevars["wampsession"] = WC.GetSession - WC.SetServer(pyroserver) - else: - raise Exception(_("WAMP config is incomplete.")) - else: - raise Exception(_("WAMP config is missing.")) + WC.SetServer(pyroserver) + WC.RegisterWampClient(wampconf, wampsecret) + WC.RegisterWebSettings(NS) except Exception: LogMessageAndException(_("WAMP client startup failed. ")) diff -r 7f59aa398669 -r 2a9549e4380e ProjectController.py --- a/ProjectController.py Fri Jun 15 09:48:05 2018 +0200 +++ b/ProjectController.py Fri Jul 20 11:05:17 2018 +0200 @@ -1352,6 +1352,31 @@ if self.AppFrame is not None: self.AppFrame.LogViewer.SetLogCounters(log_count) + DefaultMethods = { + "_Run": False, + "_Stop": False, + "_Transfer": False, + "_Connect": True, + "_Disconnect": False + } + + MethodsFromStatus = { + "Started": {"_Stop": True, + "_Transfer": True, + "_Connect": False, + "_Disconnect": True}, + "Stopped": {"_Run": True, + "_Transfer": True, + "_Connect": False, + "_Disconnect": True}, + "Empty": {"_Transfer": True, + "_Connect": False, + "_Disconnect": True}, + "Broken": {"_Connect": False, + "_Disconnect": True}, + "Disconnected": {}, + } + def UpdateMethodsFromPLCStatus(self): updated = False status = None @@ -1364,21 +1389,11 @@ self._SetConnector(None, False) status = "Disconnected" if self.previous_plcstate != status: - for args in { - "Started": [("_Run", False), - ("_Stop", True)], - "Stopped": [("_Run", True), - ("_Stop", False)], - "Empty": [("_Run", False), - ("_Stop", False)], - "Broken": [], - "Disconnected": [("_Run", False), - ("_Stop", False), - ("_Transfer", False), - ("_Connect", True), - ("_Disconnect", False)], - }.get(status, []): - self.ShowMethod(*args) + allmethods = self.DefaultMethods.copy() + allmethods.update( + self.MethodsFromStatus.get(status, {})) + for method, active in allmethods.items(): + self.ShowMethod(method,active) self.previous_plcstate = status if self.AppFrame is not None: updated = True @@ -1713,10 +1728,6 @@ # Oups. self.logger.write_error(_("Connection failed to %s!\n") % uri) else: - self.ShowMethod("_Connect", False) - self.ShowMethod("_Disconnect", True) - self.ShowMethod("_Transfer", True) - self.CompareLocalAndRemotePLC() # Init with actual PLC status and print it diff -r 7f59aa398669 -r 2a9549e4380e runtime/NevowServer.py --- a/runtime/NevowServer.py Fri Jun 15 09:48:05 2018 +0200 +++ b/runtime/NevowServer.py Fri Jul 20 11:05:17 2018 +0200 @@ -26,10 +26,19 @@ from __future__ import absolute_import from __future__ import print_function import os -from nevow import appserver, inevow, tags, loaders, athena +import platform +from zope.interface import implements +from nevow import appserver, inevow, tags, loaders, athena, url, rend from nevow.page import renderer +from formless import annotate +from formless import webform +from formless import configurable from twisted.internet import reactor + import util.paths as paths +from runtime.loglevels import LogLevels, LogLevelsDict + +PAGE_TITLE = 'Beremiz Runtime Web Interface' xhtml_header = ''' - + diff -r 7f59aa398669 -r 2a9549e4380e tests/wamp/project_files/wampconf.json --- a/tests/wamp/project_files/wampconf.json Fri Jun 15 09:48:05 2018 +0200 +++ b/tests/wamp/project_files/wampconf.json Fri Jul 20 11:05:17 2018 +0200 @@ -1,7 +1,10 @@ { - "url":"ws://127.0.0.1:8888", - "realm":"Automation", - "ID":"wamptest", - "password":"1234567890", - "key":"ABCDEFGHIJ" + "ID": "wamptest", + "active": true, + "protocolOptions": { + "autoPingInterval": 60, + "autoPingTimeout": 20 + }, + "realm": "Automation", + "url": "ws://127.0.0.1:8888" }