author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 10 Oct 2018 10:32:57 +0300 | |
changeset 2444 | 235f847be37e |
parent 2260 | 74205edac761 |
child 2262 | 4195545e2d17 |
permissions | -rw-r--r-- |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
1 |
#!/usr/bin/env python |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
3 |
|
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
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:
1453
diff
changeset
|
5 |
# |
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
6 |
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1667
diff
changeset
|
7 |
# Copyright (C) 2017: Andrey Skvortsov |
1511
91538d0c242c
add copyright notices to python files where there were missing, that
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1453
diff
changeset
|
8 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
9 |
# 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:
1453
diff
changeset
|
10 |
# |
1667
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
11 |
# 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:
1595
diff
changeset
|
12 |
# 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:
1595
diff
changeset
|
13 |
# License as published by the Free Software Foundation; either |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
14 |
# 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:
1595
diff
changeset
|
15 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
16 |
# 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:
1453
diff
changeset
|
17 |
# 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:
1595
diff
changeset
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
19 |
# Lesser General Public License for more details. |
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
20 |
|
cefc9219bb48
runtime is licensed under LGPLv2.1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
21 |
# 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:
1595
diff
changeset
|
22 |
# 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:
1595
diff
changeset
|
23 |
# 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:
1453
diff
changeset
|
24 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
25 |
|
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
|
26 |
from __future__ import absolute_import |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
27 |
from __future__ import print_function |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
28 |
import os |
2247 | 29 |
import platform as platform_module |
2208 | 30 |
from zope.interface import implements |
31 |
from nevow import appserver, inevow, tags, loaders, athena, url, rend |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
32 |
from nevow.page import renderer |
2208 | 33 |
from formless import annotate |
34 |
from formless import webform |
|
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
35 |
from formless import configurable |
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:
1438
diff
changeset
|
36 |
from twisted.internet import reactor |
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
37 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1881
diff
changeset
|
38 |
import util.paths as paths |
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
39 |
from runtime.loglevels import LogLevels, LogLevelsDict |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
40 |
|
2208 | 41 |
PAGE_TITLE = 'Beremiz Runtime Web Interface' |
42 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
43 |
xhtml_header = '''<?xml version="1.0" encoding="utf-8"?> |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
44 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
45 |
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
46 |
''' |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
47 |
|
1453 | 48 |
WorkingDir = None |
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
49 |
_PySrv = None |
1453 | 50 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
51 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
52 |
class PLCHMI(athena.LiveElement): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
53 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
54 |
initialised = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
55 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
56 |
def HMIinitialised(self, result): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
57 |
self.initialised = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
58 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
59 |
def HMIinitialisation(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
60 |
self.HMIinitialised(None) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
61 |
|
2246 | 62 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
63 |
class DefaultPLCStartedHMI(PLCHMI): |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
64 |
docFactory = loaders.stan( |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
65 |
tags.div(render=tags.directive('liveElement'))[ |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
66 |
tags.h1["PLC IS NOW STARTED"], |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
67 |
]) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
68 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
69 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
70 |
class PLCStoppedHMI(PLCHMI): |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
71 |
docFactory = loaders.stan( |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
72 |
tags.div(render=tags.directive('liveElement'))[ |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
73 |
tags.h1["PLC IS STOPPED"], |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
74 |
]) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
75 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
76 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
77 |
class MainPage(athena.LiveElement): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
78 |
jsClass = u"WebInterface.PLC" |
1878
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
79 |
docFactory = loaders.stan( |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
80 |
tags.div(render=tags.directive('liveElement'))[ |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
81 |
tags.div(id='content')[ |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
82 |
tags.div(render=tags.directive('PLCElement'))] |
fb73a6b6622d
fix pylint warning '(bad-continuation) Wrong hanging indentation before block'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1870
diff
changeset
|
83 |
]) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
84 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
85 |
def __init__(self, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
86 |
athena.LiveElement.__init__(self, *a, **kw) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
87 |
self.pcl_state = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
88 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
89 |
self.resetPLCStartedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
90 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
91 |
def setPLCState(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
92 |
self.pcl_state = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
93 |
if self.HMI is not None: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
94 |
self.callRemote('updateHMI') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
95 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
96 |
def setPLCStartedHMI(self, hmi): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
97 |
self.PLCStartedHMIClass = hmi |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
98 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
99 |
def resetPLCStartedHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
100 |
self.PLCStartedHMIClass = DefaultPLCStartedHMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
101 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
102 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
103 |
return self.HMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
104 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
105 |
def HMIexec(self, function, *args, **kwargs): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
106 |
if self.HMI is not None: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1736
diff
changeset
|
107 |
getattr(self.HMI, function, lambda: None)(*args, **kwargs) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
108 |
athena.expose(HMIexec) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
109 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
110 |
def resetHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
111 |
self.HMI = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
112 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
113 |
def PLCElement(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
114 |
return self.getPLCElement() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
115 |
renderer(PLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
116 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
117 |
def getPLCElement(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
118 |
self.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
119 |
if self.pcl_state: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
120 |
f = self.PLCStartedHMIClass() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
121 |
else: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
122 |
f = PLCStoppedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
123 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
124 |
self.HMI = f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
125 |
return f |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
126 |
athena.expose(getPLCElement) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
127 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
128 |
def detachFragmentChildren(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
129 |
for child in self.liveFragmentChildren[:]: |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
130 |
child.detach() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
131 |
|
2246 | 132 |
|
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
133 |
class ConfigurableBindings(configurable.Configurable): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
134 |
|
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
135 |
def __init__(self): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
136 |
configurable.Configurable.__init__(self, None) |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
137 |
self.bindingsNames = [] |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
138 |
|
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
139 |
def getBindingNames(self, ctx): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
140 |
return self.bindingsNames |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
141 |
|
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
142 |
def addExtension(self, name, desc, fields, btnlabel, callback): |
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
143 |
def _bind(ctx): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
144 |
return annotate.MethodBinding( |
2246 | 145 |
'action_' + name, |
2247 | 146 |
annotate.Method( |
147 |
arguments=[ |
|
148 |
annotate.Argument(*field) |
|
149 |
for field in fields], |
|
2246 | 150 |
label=desc), |
151 |
action=btnlabel) |
|
152 |
setattr(self, 'bind_' + name, _bind) |
|
153 |
||
154 |
setattr(self, 'action_' + name, callback) |
|
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
155 |
|
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
156 |
self.bindingsNames.append(name) |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
157 |
|
2260
74205edac761
Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents:
2247
diff
changeset
|
158 |
|
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
159 |
ConfigurableSettings = ConfigurableBindings() |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
160 |
|
2246 | 161 |
|
2208 | 162 |
class ISettings(annotate.TypedInterface): |
2246 | 163 |
platform = annotate.String(label=_("Platform"), |
2247 | 164 |
default=platform_module.system() + |
165 |
" " + platform_module.release(), |
|
166 |
immutable=True) |
|
167 |
||
2217
a603d1ba287b
Added some immutable field (platform) in default runtime web setting page, for the example.
Edouard Tisserant
parents:
2214
diff
changeset
|
168 |
# TODO version ? |
a603d1ba287b
Added some immutable field (platform) in default runtime web setting page, for the example.
Edouard Tisserant
parents:
2214
diff
changeset
|
169 |
|
2247 | 170 |
# pylint: disable=no-self-argument |
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
171 |
def sendLogMessage( |
2247 | 172 |
ctx=annotate.Context(), |
173 |
level=annotate.Choice(LogLevels, |
|
174 |
required=True, |
|
175 |
label=_("Log message level")), |
|
2246 | 176 |
message=annotate.String(label=_("Message text"))): |
2247 | 177 |
pass |
178 |
||
2246 | 179 |
sendLogMessage = annotate.autocallable(sendLogMessage, |
180 |
label=_( |
|
181 |
"Send a message to the log"), |
|
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
182 |
action=_("Send")) |
2208 | 183 |
|
2260
74205edac761
Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents:
2247
diff
changeset
|
184 |
|
2219
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
185 |
customSettingsURLs = { |
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
186 |
} |
2208 | 187 |
|
2246 | 188 |
|
2208 | 189 |
class SettingsPage(rend.Page): |
190 |
# We deserve a slash |
|
191 |
addSlash = True |
|
2246 | 192 |
|
2208 | 193 |
# This makes webform_css url answer some default CSS |
194 |
child_webform_css = webform.defaultCSS |
|
195 |
||
196 |
implements(ISettings) |
|
197 |
||
2246 | 198 |
docFactory = loaders.stan([ |
199 |
tags.html[ |
|
200 |
tags.head[ |
|
201 |
tags.title[_("Beremiz Runtime Settings")], |
|
202 |
tags.link(rel='stylesheet', |
|
203 |
type='text/css', |
|
204 |
href=url.here.child("webform_css")) |
|
205 |
], |
|
206 |
tags.body[ |
|
207 |
tags.h1["Runtime settings:"], |
|
208 |
webform.renderForms('staticSettings'), |
|
209 |
tags.h2["Extensions settings:"], |
|
210 |
webform.renderForms('dynamicSettings'), |
|
211 |
] |
|
212 |
] |
|
213 |
]) |
|
2208 | 214 |
|
2209
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
215 |
def configurable_staticSettings(self, ctx): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
216 |
return configurable.TypedInterfaceConfigurable(self) |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
217 |
|
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
218 |
def configurable_dynamicSettings(self, ctx): |
ee2675e4778d
Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents:
2208
diff
changeset
|
219 |
return ConfigurableSettings |
2246 | 220 |
|
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
221 |
def sendLogMessage(self, level, message, **kwargs): |
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
222 |
level = LogLevelsDict[level] |
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
223 |
if _PySrv.plcobj is not None: |
2246 | 224 |
_PySrv.plcobj.LogMessage( |
225 |
level, "Web form log message: " + message) |
|
2208 | 226 |
|
2219
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
227 |
def locateChild(self, ctx, segments): |
2246 | 228 |
if segments[0] in customSettingsURLs: |
2219
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
229 |
return customSettingsURLs[segments[0]](ctx, segments) |
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
230 |
return super(SettingsPage, self).locateChild(ctx, segments) |
73042b2d8d65
Added a way for extension to register dedicated URL under settings page URL (i.e. /settings/something)
Edouard Tisserant
parents:
2217
diff
changeset
|
231 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
232 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
233 |
class WebInterface(athena.LivePage): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
234 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
235 |
docFactory = loaders.stan([tags.raw(xhtml_header), |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1756
diff
changeset
|
236 |
tags.html(xmlns="http://www.w3.org/1999/xhtml")[ |
2208 | 237 |
tags.head(render=tags.directive('liveglue'))[ |
238 |
tags.title[PAGE_TITLE], |
|
239 |
tags.link(rel='stylesheet', |
|
2246 | 240 |
type='text/css', |
2208 | 241 |
href=url.here.child("webform_css")) |
242 |
], |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1756
diff
changeset
|
243 |
tags.body[ |
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1756
diff
changeset
|
244 |
tags.div[ |
2246 | 245 |
tags.div( |
246 |
render=tags.directive( |
|
247 |
"MainPage")), |
|
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1756
diff
changeset
|
248 |
]]]]) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
249 |
MainPage = MainPage() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
250 |
PLCHMI = PLCHMI |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
251 |
|
2208 | 252 |
def child_settings(self, context): |
253 |
return SettingsPage() |
|
254 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
255 |
def __init__(self, plcState=False, *a, **kw): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
256 |
super(WebInterface, self).__init__(*a, **kw) |
2246 | 257 |
self.jsModules.mapping[u'WebInterface'] = paths.AbsNeighbourFile( |
258 |
__file__, 'webinterface.js') |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
259 |
self.plcState = plcState |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
260 |
self.MainPage.setPLCState(plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
261 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
262 |
def getHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
263 |
return self.MainPage.getHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
264 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
265 |
def LoadHMI(self, hmi, jsmodules): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
266 |
for name, path in jsmodules.iteritems(): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
267 |
self.jsModules.mapping[name] = os.path.join(WorkingDir, path) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
268 |
self.MainPage.setPLCStartedHMI(hmi) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
269 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
270 |
def UnLoadHMI(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
271 |
self.MainPage.resetPLCStartedHMI() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
272 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
273 |
def PLCStarted(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
274 |
self.plcState = True |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
275 |
self.MainPage.setPLCState(True) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
276 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
277 |
def PLCStopped(self): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
278 |
self.plcState = False |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
279 |
self.MainPage.setPLCState(False) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
280 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
281 |
def renderHTTP(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
282 |
""" |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
283 |
Force content type to fit with SVG |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
284 |
""" |
1870
4d070115b552
fix pylint error '(too-many-function-args) Too many positional arguments for function call'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
285 |
req = ctx.locate(inevow.IRequest) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
286 |
req.setHeader('Content-type', 'application/xhtml+xml') |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
287 |
return super(WebInterface, self).renderHTTP(ctx) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
288 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
289 |
def render_MainPage(self, ctx, data): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
290 |
f = self.MainPage |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
291 |
f.setFragmentParent(self) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
292 |
return ctx.tag[f] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
293 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
294 |
def child_(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
295 |
self.MainPage.detachFragmentChildren() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
296 |
return WebInterface(plcState=self.plcState) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
297 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
298 |
def beforeRender(self, ctx): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
299 |
d = self.notifyOnDisconnect() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
300 |
d.addErrback(self.disconnected) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
301 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
302 |
def disconnected(self, reason): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
303 |
self.MainPage.resetHMI() |
1782
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1776
diff
changeset
|
304 |
# print reason |
5b6ad7a7fd9d
clean-up: fix PEP8 E265 block comment should start with '# '
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1776
diff
changeset
|
305 |
# print "We will be called back when the client disconnects" |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
306 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
307 |
|
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:
1438
diff
changeset
|
308 |
def RegisterWebsite(port): |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
309 |
website = WebInterface() |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
310 |
site = appserver.NevowSite(website) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
311 |
|
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:
1438
diff
changeset
|
312 |
reactor.listenTCP(port, site) |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1782
diff
changeset
|
313 |
print(_('HTTP interface port :'), port) |
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:
1438
diff
changeset
|
314 |
return website |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
315 |
|
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
316 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
317 |
class statuslistener(object): |
2246 | 318 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
319 |
def __init__(self, site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
320 |
self.oldstate = None |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
321 |
self.site = site |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
322 |
|
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
323 |
def listen(self, state): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
324 |
if state != self.oldstate: |
1453 | 325 |
action = {'Started': self.site.PLCStarted, |
326 |
'Stopped': self.site.PLCStopped}.get(state, None) |
|
1756
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
327 |
if action is not None: |
08e4394ff4fb
clean-up: fix PEP8 E701 multiple statements on one line (colon)
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1746
diff
changeset
|
328 |
action() |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
329 |
self.oldstate = state |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
330 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1682
diff
changeset
|
331 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
332 |
def website_statuslistener_factory(site): |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff
changeset
|
333 |
return statuslistener(site).listen |
2208 | 334 |
|
335 |
||
2210
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
336 |
def SetServer(pysrv): |
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
337 |
global _PySrv |
81949104291d
Nevow based web interface now show simple Log message sending form for basic runtime, and allow extensions to add their own web settings.
Edouard Tisserant
parents:
2209
diff
changeset
|
338 |
_PySrv = pysrv |