author | Edouard Tisserant |
Tue, 27 Nov 2018 13:34:14 +0100 | |
changeset 2462 | ed6b0e905fcb |
parent 2459 | 21164625b393 |
child 2471 | 9d5c291b510f |
permissions | -rw-r--r-- |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
3 |
|
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
4 |
# This file is part of Beremiz runtime. |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
5 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
7 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
8 |
# See COPYING.Runtime file for copyrights details. |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
9 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
10 |
# This library is free software; you can redistribute it and/or |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
11 |
# modify it under the terms of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
12 |
# License as published by the Free Software Foundation; either |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
13 |
# version 2.1 of the License, or (at your option) any later version. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
14 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
15 |
# This library is distributed in the hope that it will be useful, |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
18 |
# Lesser General Public License for more details. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
19 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
20 |
# You should have received a copy of the GNU Lesser General Public |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
21 |
# License along with this library; if not, write to the Free Software |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1511
diff
changeset
|
22 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1446
diff
changeset
|
23 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
24 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1878
diff
changeset
|
25 |
from __future__ import absolute_import |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
26 |
from __future__ import print_function |
1899
ff4410112b67
runtime/WAMP : was 'Added time print on session left.' from dporopat. Purpose is to log (dis/re)connection, to help debugging connection problem
Edouard Tisserant
parents:
1898
diff
changeset
|
27 |
import time |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
28 |
import json |
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
29 |
import os |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
30 |
import re |
2434
07f48018b6f5
python3 support: pylint, W1612 # (unicode-builtin) unicode built-in referenced
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2418
diff
changeset
|
31 |
from builtins import str as text |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
32 |
from autobahn.twisted import wamp |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
33 |
from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
34 |
from autobahn.wamp import types, auth |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
35 |
from autobahn.wamp.serializer import MsgPackSerializer |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
36 |
from twisted.internet.protocol import ReconnectingClientFactory |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
37 |
from twisted.python.components import registerAdapter |
1832
0f1081928d65
fix wrong-import-order. first standard modules are imported, then others
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
38 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
39 |
from formless import annotate, webform |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
40 |
import formless |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
41 |
from nevow import tags, url, static |
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
42 |
from runtime import GetPLCObjectSingleton |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
43 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
44 |
mandatoryConfigItems = ["ID", "active", "realm", "url"] |
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
45 |
|
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
46 |
_transportFactory = None |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
47 |
_WampSession = None |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
48 |
_PySrv = None |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
49 |
WorkingDir = None |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
50 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
51 |
# Find pre-existing project WAMP config file |
2202
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
52 |
_WampConf = None |
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
53 |
_WampSecret = None |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
54 |
|
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
55 |
ExposedCalls = [ |
2206
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
56 |
("StartPLC", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
57 |
("StopPLC", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
58 |
("GetPLCstatus", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
59 |
("NewPLC", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
60 |
("MatchMD5", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
61 |
("SetTraceVariablesList", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
62 |
("GetTraceVariables", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
63 |
("RemoteExec", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
64 |
("GetLogMessage", {}), |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
65 |
("ResetLogCount", {}) |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
66 |
] |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
67 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
68 |
# de-activated dumb wamp config |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
69 |
defaultWampConfig = { |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
70 |
"ID": "wamptest", |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
71 |
"active": False, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
72 |
"realm": "Automation", |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
73 |
"url": "ws://127.0.0.1:8888" |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
74 |
} |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
75 |
|
1898
d2dbdeffc426
runtime/Wamp : adapt to unicode being enforced in latest crossbar API. Updated some documentation, to explain why there is unused definitions like SubscribedEvents or DoOnJoin.
Edouard Tisserant
parents:
1894
diff
changeset
|
76 |
# Those two lists are meant to be filled by customized runtime |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
77 |
# or User python code. |
1898
d2dbdeffc426
runtime/Wamp : adapt to unicode being enforced in latest crossbar API. Updated some documentation, to explain why there is unused definitions like SubscribedEvents or DoOnJoin.
Edouard Tisserant
parents:
1894
diff
changeset
|
78 |
|
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
79 |
""" crossbar Events to register to """ |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
80 |
SubscribedEvents = [] |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
81 |
|
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
82 |
""" things to do on join (callables) """ |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
83 |
DoOnJoin = [] |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
84 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
85 |
lastKnownConfig = None |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
86 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
87 |
|
1445
e25479e3fe11
More versatile registering of wamp callees
Edouard Tisserant
parents:
1443
diff
changeset
|
88 |
def GetCallee(name): |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
89 |
""" Get Callee or Subscriber corresponding to '.' spearated object path """ |
1445
e25479e3fe11
More versatile registering of wamp callees
Edouard Tisserant
parents:
1443
diff
changeset
|
90 |
names = name.split('.') |
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
91 |
obj = GetPLCObjectSingleton() |
1756
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1753
diff
changeset
|
92 |
while names: |
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1753
diff
changeset
|
93 |
obj = getattr(obj, names.pop(0)) |
1445
e25479e3fe11
More versatile registering of wamp callees
Edouard Tisserant
parents:
1443
diff
changeset
|
94 |
return obj |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
95 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
96 |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
97 |
class WampSession(wamp.ApplicationSession): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
98 |
|
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
99 |
def onConnect(self): |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
100 |
if "secret" in self.config.extra: |
2194
35d6b9321ffd
#2486 Updated wamp test project to work with the latest Crossbar version.
dporopat <denis.poropat@smarteh.si>
parents:
2193
diff
changeset
|
101 |
user = self.config.extra["ID"] |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
102 |
self.join(u"Automation", [u"wampcra"], user) |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
103 |
else: |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
104 |
self.join(u"Automation") |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
105 |
|
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
106 |
def onChallenge(self, challenge): |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
107 |
if challenge.method == u"wampcra": |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
108 |
if "secret" in self.config.extra: |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
109 |
secret = self.config.extra["secret"].encode('utf8') |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
110 |
signature = auth.compute_wcs( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
111 |
secret, challenge.extra['challenge'].encode('utf8')) |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
112 |
return signature.decode("ascii") |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
113 |
else: |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
114 |
raise Exception("no secret given for authentication") |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
115 |
else: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
116 |
raise Exception( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
117 |
"don't know how to handle authmethod {}".format(challenge.method)) |
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
118 |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
119 |
def onJoin(self, details): |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
120 |
global _WampSession |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
121 |
_WampSession = self |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
122 |
ID = self.config.extra["ID"] |
2206
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
123 |
|
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
124 |
for name, kwargs in ExposedCalls: |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
125 |
try: |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
126 |
registerOptions = types.RegisterOptions(**kwargs) |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
127 |
except TypeError as e: |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
128 |
registerOptions = None |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
129 |
print(_("TypeError register option: {}".format(e))) |
1e397afc36a9
#2486 ExposedCalls with register options as a dictionary.
dporopat <denis.poropat@smarteh.si>
parents:
2205
diff
changeset
|
130 |
|
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
131 |
self.register(GetCallee(name), u'.'.join((ID, name)), registerOptions) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
132 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
133 |
for name in SubscribedEvents: |
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
134 |
self.subscribe(GetCallee(name), unicode(name)) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
135 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
136 |
for func in DoOnJoin: |
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
137 |
func(self) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
138 |
|
2194
35d6b9321ffd
#2486 Updated wamp test project to work with the latest Crossbar version.
dporopat <denis.poropat@smarteh.si>
parents:
2193
diff
changeset
|
139 |
print(_('WAMP session joined (%s) by:' % time.ctime()), ID) |
35d6b9321ffd
#2486 Updated wamp test project to work with the latest Crossbar version.
dporopat <denis.poropat@smarteh.si>
parents:
2193
diff
changeset
|
140 |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
141 |
def onLeave(self, details): |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
142 |
global _WampSession, _transportFactory |
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
143 |
super(WampSession, self).onLeave(details) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
144 |
_WampSession = None |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
145 |
_transportFactory = None |
1890
916099cb8d22
non significant print syntax change. ready for py3.
Edouard Tisserant
parents:
1881
diff
changeset
|
146 |
print(_('WAMP session left')) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
147 |
|
2310 | 148 |
def publishWithOwnID(self, eventID, value): |
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
149 |
ID = self.config.extra["ID"] |
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
150 |
self.publish(unicode(ID+'.'+eventID), value) |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
151 |
|
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
152 |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
153 |
class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
154 |
|
2195
2cef75d036c2
#2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents:
2194
diff
changeset
|
155 |
def __init__(self, config, *args, **kwargs): |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
156 |
global _transportFactory |
2195
2cef75d036c2
#2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents:
2194
diff
changeset
|
157 |
WampWebSocketClientFactory.__init__(self, *args, **kwargs) |
2cef75d036c2
#2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents:
2194
diff
changeset
|
158 |
|
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
159 |
try: |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
160 |
protocolOptions = config.extra.get('protocolOptions', None) |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
161 |
if protocolOptions: |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
162 |
self.setProtocolOptions(**protocolOptions) |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
163 |
_transportFactory = self |
2418
5587c490a070
Use python 3 compatible exception syntax everywhere
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2287
diff
changeset
|
164 |
except Exception as e: |
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
165 |
print(_("Custom protocol options failed :"), e) |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
166 |
_transportFactory = None |
2195
2cef75d036c2
#2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents:
2194
diff
changeset
|
167 |
|
2193
259df9ecf9ca
#2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents:
1955
diff
changeset
|
168 |
def buildProtocol(self, addr): |
259df9ecf9ca
#2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents:
1955
diff
changeset
|
169 |
self.resetDelay() |
259df9ecf9ca
#2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents:
1955
diff
changeset
|
170 |
return ReconnectingClientFactory.buildProtocol(self, addr) |
259df9ecf9ca
#2486 Reset delay function added. It resets the delay and the retry counter on reconnect.
dporopat <denis.poropat@smarteh.si>
parents:
1955
diff
changeset
|
171 |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
172 |
def clientConnectionFailed(self, connector, reason): |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
173 |
if self.continueTrying: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
174 |
print(_("WAMP Client connection failed (%s) .. retrying ..") % |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
175 |
time.ctime()) |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
176 |
super(ReconnectingWampWebSocketClientFactory, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
177 |
self).clientConnectionFailed(connector, reason) |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
178 |
else: |
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
179 |
del connector |
1751
c28db6f7616b
clean-up: fix PEP8 E301 expected 1 blank line, found 0
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1748
diff
changeset
|
180 |
|
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
181 |
def clientConnectionLost(self, connector, reason): |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
182 |
if self.continueTrying: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
183 |
print(_("WAMP Client connection lost (%s) .. retrying ..") % |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
184 |
time.ctime()) |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
185 |
super(ReconnectingWampWebSocketClientFactory, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
186 |
self).clientConnectionFailed(connector, reason) |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
187 |
else: |
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
188 |
del connector |
1441
826730e60407
Added auto-reconnect for runtime. Fixed Beremiz closing problem caused by remaining twisted reactor thread in IDE.
Edouard Tisserant
parents:
1440
diff
changeset
|
189 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
190 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
191 |
def CheckConfiguration(WampClientConf): |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
192 |
url = WampClientConf["url"] |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
193 |
if not IsCorrectUri(url): |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
194 |
raise annotate.ValidateError( |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
195 |
{"url": "Invalid URL: {}".format(url)}, |
2223 | 196 |
_("WAMP configuration error:")) |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
197 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
198 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
199 |
def GetConfiguration(): |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
200 |
global lastKnownConfig |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
201 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
202 |
if os.path.exists(_WampConf): |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
203 |
WampClientConf = json.load(open(_WampConf)) |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
204 |
else: |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
205 |
WampClientConf = defaultWampConfig.copy() |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
206 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
207 |
for itemName in mandatoryConfigItems: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
208 |
if WampClientConf.get(itemName, None) is None: |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
209 |
raise Exception( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
210 |
_("WAMP configuration error : missing '{}' parameter.").format(itemName)) |
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
211 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
212 |
CheckConfiguration(WampClientConf) |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
213 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
214 |
lastKnownConfig = WampClientConf.copy() |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
215 |
return WampClientConf |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
216 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
217 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
218 |
def SetWampSecret(wampSecret): |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
219 |
with open(os.path.realpath(_WampSecret), 'w') as f: |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
220 |
f.write(wampSecret) |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
221 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
222 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
223 |
def SetConfiguration(WampClientConf): |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
224 |
global lastKnownConfig |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
225 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
226 |
CheckConfiguration(WampClientConf) |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
227 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
228 |
lastKnownConfig = WampClientConf.copy() |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
229 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
230 |
with open(os.path.realpath(_WampConf), 'w') as f: |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
231 |
json.dump(WampClientConf, f, sort_keys=True, indent=4) |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
232 |
if 'active' in WampClientConf and WampClientConf['active']: |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
233 |
if _transportFactory and _WampSession: |
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
234 |
StopReconnectWampClient() |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
235 |
StartReconnectWampClient() |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
236 |
else: |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
237 |
StopReconnectWampClient() |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
238 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
239 |
return WampClientConf |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
240 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
241 |
|
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
242 |
def LoadWampSecret(secretfname): |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
243 |
WSClientWampSecret = open(secretfname, 'rb').read() |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
244 |
if len(WSClientWampSecret) == 0: |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
245 |
raise Exception(_("WAMP secret empty")) |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
246 |
return WSClientWampSecret |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1445
diff
changeset
|
247 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
248 |
|
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
249 |
def IsCorrectUri(uri): |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
250 |
return re.match(r'wss?://[^\s?:#-]+(:[0-9]+)?(/[^\s]*)?$', uri) is not None |
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
251 |
|
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
252 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
253 |
def RegisterWampClient(wampconf=None, wampsecret=None): |
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
254 |
global _WampConf, _WampSecret |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
255 |
_WampConfDefault = os.path.join(WorkingDir, "wampconf.json") |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
256 |
_WampSecretDefault = os.path.join(WorkingDir, "wamp.secret") |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
257 |
|
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
258 |
# set config file path only if not already set |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
259 |
if _WampConf is None: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
260 |
# default project's wampconf has precedance over commandline given |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
261 |
if os.path.exists(_WampConfDefault) or wampconf is None: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
262 |
_WampConf = _WampConfDefault |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
263 |
else: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
264 |
_WampConf = wampconf |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
265 |
|
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
266 |
WampClientConf = GetConfiguration() |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
267 |
|
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
268 |
# set secret file path only if not already set |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
269 |
if _WampSecret is None: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
270 |
# default project's wamp secret also |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
271 |
# has precedance over commandline given |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
272 |
if os.path.exists(_WampSecretDefault): |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
273 |
_WampSecret = _WampSecretDefault |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
274 |
else: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
275 |
_WampSecret = wampsecret |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
276 |
|
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
277 |
if _WampSecret is not None: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
278 |
WampClientConf["secret"] = LoadWampSecret(_WampSecret) |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
279 |
else: |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
280 |
print(_("WAMP authentication has no secret configured")) |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
281 |
_WampSecret = _WampSecretDefault |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
282 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
283 |
if not WampClientConf["active"]: |
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
284 |
print(_("WAMP deactivated in configuration")) |
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
285 |
return |
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
286 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
287 |
# create a WAMP application session factory |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
288 |
component_config = types.ComponentConfig( |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
289 |
realm=WampClientConf["realm"], |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
290 |
extra=WampClientConf) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
291 |
session_factory = wamp.ApplicationSessionFactory( |
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1740
diff
changeset
|
292 |
config=component_config) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
293 |
session_factory.session = WampSession |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
294 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
295 |
# create a WAMP-over-WebSocket transport client factory |
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
296 |
ReconnectingWampWebSocketClientFactory( |
2195
2cef75d036c2
#2486 Added option to use websocket protocol options.
dporopat <denis.poropat@smarteh.si>
parents:
2194
diff
changeset
|
297 |
component_config, |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
298 |
session_factory, |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
299 |
url=WampClientConf["url"], |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1892
diff
changeset
|
300 |
serializers=[MsgPackSerializer()]) |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
301 |
|
1440
e8daabf2c438
Runtime : Added PLCobject methods registring. IDE : Added WAMP connector. Still need some fixes
Edouard Tisserant
parents:
1439
diff
changeset
|
302 |
# start the client from a Twisted endpoint |
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
303 |
if _transportFactory: |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
304 |
connectWS(_transportFactory) |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
305 |
print(_("WAMP client connecting to :"), WampClientConf["url"]) |
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
306 |
return True |
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
307 |
else: |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
308 |
print(_("WAMP client can not connect to :"), WampClientConf["url"]) |
2207
c27b820cb96b
#2486 Exception if custom protocol options are wrong.
dporopat <denis.poropat@smarteh.si>
parents:
2206
diff
changeset
|
309 |
return False |
2204
25dafeb98b55
#2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents:
2203
diff
changeset
|
310 |
|
2201
4e511f5aad19
#2486 Added global TransportFactory, needed in WebInterface reconnecting function.
dporopat <denis.poropat@smarteh.si>
parents:
2199
diff
changeset
|
311 |
|
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
312 |
def StopReconnectWampClient(): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
313 |
if _transportFactory is not None: |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
314 |
_transportFactory.stopTrying() |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
315 |
if _WampSession is not None: |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
316 |
_WampSession.leave() |
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
317 |
|
2204
25dafeb98b55
#2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents:
2203
diff
changeset
|
318 |
|
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
319 |
def StartReconnectWampClient(): |
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
320 |
if _WampSession: |
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
321 |
# do reconnect |
2202
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
322 |
_WampSession.disconnect() |
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
323 |
return True |
2204
25dafeb98b55
#2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents:
2203
diff
changeset
|
324 |
else: |
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
325 |
# do connect |
2202
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
326 |
RegisterWampClient() |
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
327 |
return True |
2203
c8a32ad27c0a
#2486 Modified reconnect function. Added 'active' parameter to wampconf.json file.
dporopat <denis.poropat@smarteh.si>
parents:
2202
diff
changeset
|
328 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
329 |
|
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
330 |
def GetSession(): |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
331 |
return _WampSession |
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
332 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
333 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
334 |
def getWampStatus(): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
335 |
if _transportFactory is not None: |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
336 |
if _WampSession is not None: |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
337 |
if _WampSession.is_attached(): |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
338 |
return "Attached" |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
339 |
return "Established" |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
340 |
return "Connecting" |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
341 |
return "Disconnected" |
2202
237c1a2de1c8
#2486 Adding reconnect funtion to WampClient. Global TransportFactory not needed anymore.
dporopat <denis.poropat@smarteh.si>
parents:
2201
diff
changeset
|
342 |
|
2204
25dafeb98b55
#2486 Reconnect funtion in SaveWampClientConf function.
dporopat <denis.poropat@smarteh.si>
parents:
2203
diff
changeset
|
343 |
|
2212
cf1718962567
WampClient : Simplified, removed dead code, use exception for handling failures and misconfiguration, check existence of mandatory parameters.
Edouard Tisserant
parents:
2207
diff
changeset
|
344 |
def SetServer(pysrv): |
2287
f09f31602ba6
Fix SetServer method in WAMP
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2286
diff
changeset
|
345 |
global _PySrv |
1439
a68cd4253259
Added stub code for runtime WAMP client. Added runtime command line switch to select WAMP url and Nevow web site port. Web port is now fixed, next port number is not tested if bind fails.
Edouard Tisserant
parents:
diff
changeset
|
346 |
_PySrv = pysrv |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
347 |
|
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
348 |
|
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
349 |
def PublishEvent(eventID, value): |
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
350 |
if getWampStatus() == "Attached": |
2326
d42ae2877b6e
WAMP : ensure that unicode string is passed for published events IDs
Edouard Tisserant
parents:
2315
diff
changeset
|
351 |
_WampSession.publish(unicode(eventID), value) |
2309
d8fb90a2e11f
Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2308
diff
changeset
|
352 |
|
2306
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
353 |
|
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
354 |
def PublishEventWithOwnID(eventID, value): |
908471b344ba
Some cleanup in WampClient and added functions that are usefull for extensions that need to use pub/sub.
Edouard Tisserant
parents:
2265
diff
changeset
|
355 |
if getWampStatus() == "Attached": |
2326
d42ae2877b6e
WAMP : ensure that unicode string is passed for published events IDs
Edouard Tisserant
parents:
2315
diff
changeset
|
356 |
_WampSession.publishWithOwnID(unicode(eventID), value) |
2309
d8fb90a2e11f
Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2308
diff
changeset
|
357 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
358 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
359 |
# WEB CONFIGURATION INTERFACE |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
360 |
WAMP_SECRET_URL = "secret" |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
361 |
webExposedConfigItems = ['active', 'url', 'ID'] |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
362 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
363 |
|
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
364 |
def wampConfigDefault(ctx, argument): |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
365 |
if lastKnownConfig is not None: |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
366 |
return lastKnownConfig.get(argument.name, None) |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
367 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
368 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
369 |
def wampConfig(**kwargs): |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
370 |
secretfile_field = kwargs["secretfile"] |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
371 |
if secretfile_field is not None: |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
372 |
secretfile = getattr(secretfile_field, "file", None) |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
373 |
if secretfile is not None: |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
374 |
secret = secretfile_field.file.read() |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
375 |
SetWampSecret(secret) |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
376 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
377 |
newConfig = lastKnownConfig.copy() |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
378 |
for argname in webExposedConfigItems: |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
379 |
arg = kwargs.get(argname, None) |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
380 |
if arg is not None: |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
381 |
newConfig[argname] = arg |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
382 |
|
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
383 |
SetConfiguration(newConfig) |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
384 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
385 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
386 |
class FileUploadDownload(annotate.FileUpload): |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
387 |
pass |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
388 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
389 |
|
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
390 |
class FileUploadDownloadRenderer(webform.FileUploadRenderer): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
391 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
392 |
def input(self, context, slot, data, name, value): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
393 |
# pylint: disable=expression-not-assigned |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
394 |
slot[_("Upload:")] |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
395 |
slot = webform.FileUploadRenderer.input( |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
396 |
self, context, slot, data, name, value) |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
397 |
download_url = data.typedValue.getAttribute('download_url') |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
398 |
return slot[tags.a(href=download_url)[_("Download")]] |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
399 |
|
2260
74205edac761
Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents:
2248
diff
changeset
|
400 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
401 |
registerAdapter(FileUploadDownloadRenderer, FileUploadDownload, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
402 |
formless.iformless.ITypedRenderer) |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
403 |
|
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
404 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
405 |
def getDownloadUrl(ctx, argument): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
406 |
if lastKnownConfig is not None: |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
407 |
return url.URL.fromContext(ctx).\ |
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
408 |
child(WAMP_SECRET_URL).\ |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
409 |
child(lastKnownConfig["ID"] + ".secret") |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
410 |
|
2260
74205edac761
Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents:
2248
diff
changeset
|
411 |
|
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
412 |
webFormInterface = [ |
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
413 |
("status", |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
414 |
annotate.String(label=_("Current status"), |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
415 |
immutable=True, |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
416 |
default=lambda *k:getWampStatus())), |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
417 |
("ID", |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
418 |
annotate.String(label=_("ID"), |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
419 |
default=wampConfigDefault)), |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
420 |
("secretfile", |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
421 |
FileUploadDownload(label=_("File containing secret for that ID"), |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
422 |
download_url=getDownloadUrl)), |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
423 |
("active", |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
424 |
annotate.Boolean(label=_("Enable WAMP connection"), |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
425 |
default=wampConfigDefault)), |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
426 |
("url", |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
427 |
annotate.String(label=_("WAMP Server URL"), |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
428 |
default=wampConfigDefault))] |
2218
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
429 |
|
7a4deed94eb2
Fixed a bit of everything in WAMP, and added web settings for that same extension.
Edouard Tisserant
parents:
2215
diff
changeset
|
430 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
431 |
def deliverWampSecret(ctx, segments): |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
432 |
# filename = segments[1].decode('utf-8') |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
433 |
|
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
434 |
# FIXME: compare filename to ID+".secret" |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
435 |
# for now all url under /secret returns the secret |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
436 |
|
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
437 |
# TODO: make beautifull message in case of exception |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
438 |
# while loading secret (if empty or dont exist) |
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
439 |
secret = LoadWampSecret(_WampSecret) |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
440 |
return static.Data(secret, 'application/octet-stream'), () |
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
441 |
|
2220
985f234b0d09
Moved Wamp configuration file selection logic into runtime/wampclient.py. Added Wamp CRA secret file upload and download. Slightly reworked code for config and secret file loading and saving.
Edouard Tisserant
parents:
2218
diff
changeset
|
442 |
|
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
443 |
def RegisterWebSettings(NS): |
2262
4195545e2d17
NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents:
2260
diff
changeset
|
444 |
|
4195545e2d17
NevowServer : added addInfoString to allow extensions to declare some read-only strings to be displayed in settings. Also renamed addExtension in addSettings for clarity.
Edouard Tisserant
parents:
2260
diff
changeset
|
445 |
NS.ConfigurableSettings.addSettings( |
2248
d9353e440887
autopep8 + hand made fixes on ProjectController.py runtime/WampClient.py wxglade_hmi/wxglade_hmi.py
Edouard Tisserant
parents:
2223
diff
changeset
|
446 |
"wamp", |
2221
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
447 |
_("Wamp Settings"), |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
448 |
webFormInterface, |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
449 |
_("Set"), |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
450 |
wampConfig) |
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
451 |
|
e03f7649bfb3
WAMP: now config and secret given in project files always override those given in commandline. Also made extensions web customisations happen before registration of web interface.
Edouard Tisserant
parents:
2220
diff
changeset
|
452 |
NS.customSettingsURLs[WAMP_SECRET_URL] = deliverWampSecret |