runtime/NevowServer.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 26 Apr 2024 09:24:26 +0200
changeset 3938 fc4af5685aa3
parent 3882 c7ec55cbd35a
permissions -rw-r--r--
merge
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
3750
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3703
diff changeset
    26
f62625418bff automated conversion using 2to3-3.9 tool
GP Orcullo <kinsamanka@gmail.com>
parents: 3703
diff changeset
    27
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    28
import os
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
    29
import collections
3703
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
    30
import shutil
3800
a5a6ee271e65 WIP python3 support for runtime
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3750
diff changeset
    31
from zope.interface import implementer
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    32
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
    33
from nevow.page import renderer
2266
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
    34
from nevow.static import File
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    35
from formless import annotate
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    36
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
    37
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
    38
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
    39
1919
ccea0fa6ea91 Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents: 1881
diff changeset
    40
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
    41
from runtime.loglevels import LogLevels, LogLevelsDict
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
    42
from runtime import MainWorker, GetPLCObjectSingleton
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    43
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    44
PAGE_TITLE = 'Beremiz Runtime Web Interface'
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
    45
3800
a5a6ee271e65 WIP python3 support for runtime
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3750
diff changeset
    46
xhtml_header = b'''<?xml version="1.0" encoding="utf-8"?>
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    47
<!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
    48
"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
    49
'''
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
    50
1453
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
    51
WorkingDir = None
f31353cac197 Fixed Nevow website startup
Edouard Tisserant
parents: 1439
diff changeset
    52
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
    53
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
    54
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
    55
    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
    56
        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
    57
        self.bindingsNames = []
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
    58
        self.infostringcount = 0
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
    59
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
    60
    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
    61
        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
    62
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
    63
    def addInfoString(self, label, value, name=None):
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
    64
        if isinstance(value, str):
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
    65
            def default(*k):
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
    66
                return value
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
    67
        else:
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
    68
            def default(*k):
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
    69
                return value()
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
    70
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
    71
        if name is None:
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
    72
            name = "_infostring_" + str(self.infostringcount)
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
    73
            self.infostringcount = self.infostringcount + 1
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
    74
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
    75
        def _bind(ctx):
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
    76
            return annotate.Property(
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
    77
                name,
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
    78
                annotate.String(
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
    79
                    label=label,
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
    80
                    default=default,
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
    81
                    immutable=True))
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
    82
        setattr(self, 'bind_' + name, _bind)
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
    83
        self.bindingsNames.append(name)
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
    84
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
    85
    def addSettings(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
    86
        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
    87
            return annotate.MethodBinding(
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    88
                'action_' + name,
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
    89
                annotate.Method(
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
    90
                    arguments=[
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
    91
                        annotate.Argument(*field)
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
    92
                        for field in fields],
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    93
                    label=desc),
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    94
                action=btnlabel)
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    95
        setattr(self, 'bind_' + name, _bind)
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    96
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
    97
        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
    98
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
    99
        self.bindingsNames.append(name)
2654
7575050a80c5 Add web extension: configure Modbus plugin parameters (currently only supports Modbus clients)
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
   100
            
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   101
    customSettingsURLs = {}
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   102
    def addCustomURL(self, segment, func):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   103
        self.customSettingsURLs[segment] = func
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   104
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   105
    def removeCustomURL(self, segment):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   106
        del self.customSettingsURLs[segment]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   107
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   108
    def customLocateChild(self, ctx, segments):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   109
        segment = segments[0]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   110
        if segment in self.customSettingsURLs:
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   111
            return self.customSettingsURLs[segment](ctx, segments)
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2247
diff changeset
   112
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   113
ConfigurableSettings = ConfigurableBindings()
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   114
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   115
def newExtensionSetting(display, token):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   116
    global extensions_settings_od
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   117
    settings = ConfigurableBindings()
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   118
    extensions_settings_od[token] = (settings, display)
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   119
    return settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   120
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   121
def removeExtensionSetting(token):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   122
    global extensions_settings_od
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   123
    extensions_settings_od.pop(token)
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   124
3855
beccb995b10e Runtime web settings: allow customization of version string by extensions
Edouard Tisserant
parents: 3703
diff changeset
   125
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   126
class ISettings(annotate.TypedInterface):
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   127
    platform = annotate.String(label=_("Platform"),
3861
7e17f7e02a2b Runtime: add GetVersions() call to PLCObject, use it in web settings and expose it in WAMP and Pyro.
Edouard Tisserant
parents: 3858
diff changeset
   128
                               default=lambda *a,**k:GetPLCObjectSingleton().GetVersions(),
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   129
                               immutable=True)
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   130
2217
a603d1ba287b Added some immutable field (platform) in default runtime web setting page, for the example.
Edouard Tisserant
parents: 2214
diff changeset
   131
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   132
    # 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
   133
    def sendLogMessage(
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   134
            ctx=annotate.Context(),
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   135
            level=annotate.Choice(LogLevels,
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   136
                                  required=True,
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   137
                                  label=_("Log message level")),
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   138
            message=annotate.String(label=_("Message text"))):
2247
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   139
        pass
921ba5658183 pylint on runtime/NevowServer.py
Edouard Tisserant
parents: 2246
diff changeset
   140
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   141
    sendLogMessage = annotate.autocallable(sendLogMessage,
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   142
                                           label=_(
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   143
                                               "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
   144
                                           action=_("Send"))
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   145
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   146
    # pylint: disable=no-self-argument
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   147
    def restartOrRepairPLC(
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   148
            ctx=annotate.Context(),
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   149
            action=annotate.Choice(["Restart", "Repair"],
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   150
                                  required=True,
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   151
                                  label=_("Action"))):
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   152
        pass
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   153
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   154
    restartOrRepairPLC = annotate.autocallable(restartOrRepairPLC,
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   155
                                           label=_(
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   156
                                               "Restart or Repair"),
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   157
                                           action=_("Do"))
2260
74205edac761 Some blank lines to make bitbucket's PEP8 2.2.0 happy
Edouard Tisserant
parents: 2247
diff changeset
   158
3703
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   159
    # pylint: disable=no-self-argument
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   160
    def uploadFile(
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   161
            ctx=annotate.Context(),
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   162
            uploadedfile=annotate.FileUpload(required=True,
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   163
                                  label=_("File to upload"))):
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   164
        pass
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   165
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   166
    uploadFile = annotate.autocallable(uploadFile,
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   167
                                           label=_(
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   168
                                               "Upload a file to PLC working directory"),
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   169
                                           action=_("Upload"))
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   170
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   171
extensions_settings_od = collections.OrderedDict()
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   172
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   173
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   174
CSS_tags = [tags.link(rel='stylesheet',
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   175
                      type='text/css',
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   176
                      href=url.here.child("webform_css")),
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   177
           tags.link(rel='stylesheet',
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   178
                      type='text/css',
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   179
                      href=url.here.child("webinterface_css"))]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   180
3800
a5a6ee271e65 WIP python3 support for runtime
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3750
diff changeset
   181
@implementer(ISettings)
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   182
class StyledSettingsPage(rend.Page):
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   183
    addSlash = True
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   184
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   185
    # This makes webform_css url answer some default CSS
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   186
    child_webform_css = webform.defaultCSS
2266
ed415982a9aa NevowServer : Added minimalist css style customization and a link to go to settings page and back
dporopat <denis.poropat@smarteh.si>
parents: 2219
diff changeset
   187
    child_webinterface_css = File(paths.AbsNeighbourFile(__file__, 'webinterface.css'), 'text/css')
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   188
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   189
class SettingsPage(StyledSettingsPage):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   190
   
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   191
    def extensions_settings(self, context, data):
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   192
        """ Project extensions settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   193
        Extensions added to Configuration Tree in IDE have their setting rendered here
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   194
        """
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   195
        global extensions_settings_od
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   196
        res = []
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   197
        for token in extensions_settings_od:
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   198
            _settings, display = extensions_settings_od[token]
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   199
            res += [tags.p[tags.a(href=token)[display]]]
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   200
        return res
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   201
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   202
    docFactory = loaders.stan([tags.html[
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   203
        tags.head[
Edouard Tisserant
parents: 2262 2266
diff changeset
   204
            tags.title[_("Beremiz Runtime Settings")],
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   205
            CSS_tags
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   206
        ],
Edouard Tisserant
parents: 2262 2266
diff changeset
   207
        tags.body[
3858
dcc83e03d065 Runtime web settings: fix punctuation and update CSS again
Edouard Tisserant
parents: 3856
diff changeset
   208
            tags.h1["Settings"],
dcc83e03d065 Runtime web settings: fix punctuation and update CSS again
Edouard Tisserant
parents: 3856
diff changeset
   209
            tags.h2["Runtime service"],
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   210
            webform.renderForms('staticSettings'),
3858
dcc83e03d065 Runtime web settings: fix punctuation and update CSS again
Edouard Tisserant
parents: 3856
diff changeset
   211
            tags.h2["Target specific"],
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   212
            webform.renderForms('dynamicSettings'),
3858
dcc83e03d065 Runtime web settings: fix punctuation and update CSS again
Edouard Tisserant
parents: 3856
diff changeset
   213
            tags.h2["Extensions"],
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   214
            extensions_settings
2267
Edouard Tisserant
parents: 2262 2266
diff changeset
   215
        ]]])
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   216
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   217
    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
   218
        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
   219
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   220
    def configurable_dynamicSettings(self, ctx):
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   221
        """ Runtime Extensions settings
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   222
        Extensions loaded through Beremiz_service -e or optional runtime features render setting forms here
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2654
diff changeset
   223
        """
2209
ee2675e4778d Now, runtime extensions should be able to add their own settings to web configuration interface.
Edouard Tisserant
parents: 2208
diff changeset
   224
        return ConfigurableSettings
2246
51047284cb0e pep8 on runtime/NevowServer.py
Edouard Tisserant
parents: 2219
diff changeset
   225
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
   226
    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
   227
        level = LogLevelsDict[level]
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   228
        GetPLCObjectSingleton().LogMessage(
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   229
            level, "Web form log message: " + message)
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   230
2701
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   231
    def restartOrRepairPLC(self, action, **kwargs):
f4dac054cfa3 WebInterface: better wording for wiping PLC content: "Repair"
Edouard Tisserant
parents: 2700
diff changeset
   232
        if(action == "Repair"):
2700
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   233
            GetPLCObjectSingleton().RepairPLC()
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   234
        else:
144b149cded4 runtime: added restart/reset button in web settings. Accidentaly fixed web settings logging feature.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2672
diff changeset
   235
            MainWorker.quit()
3703
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   236
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   237
    def uploadFile(self, uploadedfile, **kwargs):
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   238
        if uploadedfile is not None:
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   239
            fobj = getattr(uploadedfile, "file", None)
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   240
        if fobj is not None:
3804
ef65e5b07464 Runtime: Fix web settings file upload.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3803
diff changeset
   241
            with open(uploadedfile.filename, 'wb') as destfd:
3703
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   242
                fobj.seek(0)
4b75f1506ea1 Runtime: add arbitrary file upload to working dir in web interface
Edouard Tisserant
parents: 3440
diff changeset
   243
                shutil.copyfileobj(fobj,destfd)
2208
32dcacb67f7a Embrio of setting form, just to test
Edouard Tisserant
parents: 1919
diff changeset
   244
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
   245
    def locateChild(self, ctx, segments):
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   246
        segment = segments[0]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   247
        if segment in extensions_settings_od:
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   248
            settings, display = extensions_settings_od[segment]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   249
            return ExtensionSettingsPage(settings, display), segments[1:]
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   250
        else:
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   251
            res = ConfigurableSettings.customLocateChild(ctx, segments)
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   252
            if res:
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   253
                return res 
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
   254
        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
   255
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   256
class ExtensionSettingsPage(StyledSettingsPage):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   257
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   258
    docFactory = loaders.stan([
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   259
        tags.html[
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   260
            tags.head()[
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   261
                tags.title[tags.directive("title")],
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   262
                CSS_tags
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   263
            ],
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   264
            tags.body[
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   265
                tags.h1[tags.directive("title")],
3882
c7ec55cbd35a Fix settings URL: now '/' instead of '/settings'
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3881
diff changeset
   266
                tags.a(href='/')['Back'],
3856
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   267
                webform.renderForms('settings')
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   268
            ]]])
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   269
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   270
    def render_title(self, ctx, data):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   271
        return self._display_name
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   272
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   273
    def configurable_settings(self, ctx):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   274
        return self._settings
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   275
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   276
    def __init__(self, settings, display):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   277
        self._settings = settings
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   278
        self._display_name = display
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   279
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   280
    def locateChild(self, ctx, segments):
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   281
        res = self._settings.customLocateChild(ctx, segments)
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   282
        if res:
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   283
            return res 
054c4f1b2ea7 Runtime WebSetings for extensions are now served on individual URLs to prevent cluttering.
Edouard Tisserant
parents: 3855
diff changeset
   284
        return super(ExtensionSettingsPage, self).locateChild(ctx, segments)
1736
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
   285
7e61baa047f0 clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1682
diff changeset
   286
2311
bef2b4b87370 Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
Edouard Tisserant
parents: 2267
diff changeset
   287
def RegisterWebsite(iface, port):
3803
b3394107eb8b Runtime: drop Athena. Nevow now only for settings.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3800
diff changeset
   288
    website = SettingsPage()
1438
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   289
    site = appserver.NevowSite(website)
19ebe96b41c0 Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
diff changeset
   290
2311
bef2b4b87370 Beremiz_service now binds both pyro and nevow ports to interface given with '-i' argument.
Edouard Tisserant
parents: 2267
diff changeset
   291
    reactor.listenTCP(port, site, interface=iface)
1826
91796f408540 fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1782
diff changeset
   292
    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
   293
    return website