author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Wed, 24 Aug 2016 13:06:52 +0300 | |
changeset 1519 | f7ac0d11118e |
parent 1458 | 5c87045af670 |
child 1571 | 486f94a8032c |
permissions | -rwxr-xr-x |
641 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
641 | 6 |
# |
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
25 |
import os, sys, getopt |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
26 |
from threading import Thread |
641 | 27 |
|
28 |
def usage(): |
|
29 |
print """ |
|
30 |
Usage of Beremiz PLC execution service :\n |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
31 |
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
641 | 32 |
-n - zeroconf service name (default:disabled) |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
33 |
-i - IP address of interface to bind to (default:localhost) |
641 | 34 |
-p - port number default:3000 |
35 |
-h - print this help text and quit |
|
36 |
-a - autostart PLC (0:disable 1:enable) (default:0) |
|
37 |
-x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) |
|
38 |
-t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) |
|
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
|
39 |
-w - web server port or "off" (default:8009) |
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
|
40 |
-c - WAMP client config file or "off" (default:wampconf.json) |
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
41 |
-e - python extension (absolute path .py) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
42 |
|
641 | 43 |
working_dir - directory where are stored PLC files |
44 |
"""%sys.argv[0] |
|
45 |
||
46 |
try: |
|
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
|
47 |
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:h") |
641 | 48 |
except getopt.GetoptError, err: |
49 |
# print help information and exit: |
|
50 |
print str(err) # will print something like "option -a not recognized" |
|
51 |
usage() |
|
52 |
sys.exit(2) |
|
53 |
||
54 |
# default values |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
55 |
given_ip = None |
641 | 56 |
port = 3000 |
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
|
57 |
webport = 8009 |
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
|
58 |
wampconf = "wampconf.json" |
641 | 59 |
servicename = None |
60 |
autostart = False |
|
61 |
enablewx = True |
|
62 |
havewx = False |
|
63 |
enabletwisted = True |
|
64 |
havetwisted = False |
|
65 |
||
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
66 |
extensions=[] |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
67 |
|
641 | 68 |
for o, a in opts: |
69 |
if o == "-h": |
|
70 |
usage() |
|
71 |
sys.exit() |
|
72 |
elif o == "-i": |
|
73 |
if len(a.split(".")) == 4 or a == "localhost": |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
74 |
given_ip = a |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
75 |
else: |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
76 |
usage() |
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
77 |
sys.exit() |
641 | 78 |
elif o == "-p": |
79 |
# port: port that the service runs on |
|
80 |
port = int(a) |
|
81 |
elif o == "-n": |
|
82 |
servicename = a |
|
83 |
elif o == "-x": |
|
84 |
enablewx = int(a) |
|
85 |
elif o == "-t": |
|
86 |
enabletwisted = int(a) |
|
87 |
elif o == "-a": |
|
88 |
autostart = int(a) |
|
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
|
89 |
elif o == "-w": |
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
|
90 |
webport = None if a == "off" else int(a) |
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
|
91 |
elif o == "-c": |
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
|
92 |
wampconf = None if a == "off" else a |
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
93 |
elif o == "-e": |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
94 |
extensions.append(a) |
641 | 95 |
else: |
96 |
usage() |
|
97 |
sys.exit() |
|
98 |
||
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
99 |
beremiz_dir = os.path.dirname(os.path.realpath(__file__)) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
100 |
|
641 | 101 |
if len(argv) > 1: |
102 |
usage() |
|
103 |
sys.exit() |
|
104 |
elif len(argv) == 1: |
|
105 |
WorkingDir = argv[0] |
|
106 |
os.chdir(WorkingDir) |
|
107 |
elif len(argv) == 0: |
|
108 |
WorkingDir = os.getcwd() |
|
109 |
argv=[WorkingDir] |
|
110 |
||
111 |
import __builtin__ |
|
112 |
if __name__ == '__main__': |
|
113 |
__builtin__.__dict__['_'] = lambda x: x |
|
114 |
||
115 |
if enablewx: |
|
116 |
try: |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
117 |
import wxversion |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
118 |
wxversion.select('2.8') |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
119 |
import wx |
641 | 120 |
havewx = True |
121 |
except: |
|
122 |
print "Wx unavailable !" |
|
123 |
havewx = False |
|
124 |
||
125 |
if havewx: |
|
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
126 |
import re |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
127 |
from threading import Thread, currentThread |
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
128 |
from types import * |
641 | 129 |
app=wx.App(redirect=False) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
130 |
|
641 | 131 |
# Import module for internationalization |
132 |
import gettext |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
133 |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
134 |
def Bpath(*args): |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
135 |
return os.path.join(beremiz_dir,*args) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
136 |
|
641 | 137 |
# Get folder containing translation files |
1451
94e620cbd9de
Added Ronan Bignaux (genesis) patch to use wxversion. Fixed side effects with sys.path. Other cosmetic fixes about path included.
Edouard Tisserant
parents:
1447
diff
changeset
|
138 |
localedir = os.path.join(beremiz_dir,"locale") |
641 | 139 |
# Get the default language |
140 |
langid = wx.LANGUAGE_DEFAULT |
|
141 |
# Define translation domain (name of translation files) |
|
142 |
domain = "Beremiz" |
|
143 |
||
144 |
# Define locale for wx |
|
145 |
loc = __builtin__.__dict__.get('loc', None) |
|
146 |
if loc is None: |
|
147 |
loc = wx.Locale(langid) |
|
148 |
__builtin__.__dict__['loc'] = loc |
|
149 |
# Define location for searching translation files |
|
150 |
loc.AddCatalogLookupPathPrefix(localedir) |
|
151 |
# Define locale domain |
|
152 |
loc.AddCatalog(domain) |
|
153 |
||
154 |
def unicode_translation(message): |
|
155 |
return wx.GetTranslation(message).encode("utf-8") |
|
156 |
||
157 |
if __name__ == '__main__': |
|
158 |
__builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
159 |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
160 |
defaulticon = wx.Image(Bpath("images", "brz.png")) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
161 |
starticon = wx.Image(Bpath("images", "icoplay24.png")) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
162 |
stopicon = wx.Image(Bpath("images", "icostop24.png")) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
163 |
|
641 | 164 |
class ParamsEntryDialog(wx.TextEntryDialog): |
165 |
if wx.VERSION < (2, 6, 0): |
|
166 |
def Bind(self, event, function, id = None): |
|
167 |
if id is not None: |
|
168 |
event(self, id, function) |
|
169 |
else: |
|
170 |
event(self, function) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
171 |
|
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
172 |
|
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
173 |
def __init__(self, parent, message, caption = "Please enter text", defaultValue = "", |
641 | 174 |
style = wx.OK|wx.CANCEL|wx.CENTRE, pos = wx.DefaultPosition): |
175 |
wx.TextEntryDialog.__init__(self, parent, message, caption, defaultValue, style, pos) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
176 |
|
641 | 177 |
self.Tests = [] |
178 |
if wx.VERSION >= (2, 8, 0): |
|
179 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
|
180 |
elif wx.VERSION >= (2, 6, 0): |
|
181 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
182 |
else: |
|
183 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetChildren()[0].GetSizer().GetChildren()[0].GetWindow().GetId()) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
184 |
|
641 | 185 |
def OnOK(self, event): |
186 |
value = self.GetValue() |
|
187 |
texts = {"value" : value} |
|
188 |
for function, message in self.Tests: |
|
189 |
if not function(value): |
|
190 |
message = wx.MessageDialog(self, message%texts, _("Error"), wx.OK|wx.ICON_ERROR) |
|
191 |
message.ShowModal() |
|
192 |
message.Destroy() |
|
193 |
return |
|
194 |
self.EndModal(wx.ID_OK) |
|
195 |
event.Skip() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
196 |
|
641 | 197 |
def GetValue(self): |
198 |
return self.GetSizer().GetItem(1).GetWindow().GetValue() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
199 |
|
641 | 200 |
def SetTests(self, tests): |
201 |
self.Tests = tests |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
202 |
|
641 | 203 |
class BeremizTaskBarIcon(wx.TaskBarIcon): |
204 |
TBMENU_START = wx.NewId() |
|
205 |
TBMENU_STOP = wx.NewId() |
|
206 |
TBMENU_CHANGE_NAME = wx.NewId() |
|
207 |
TBMENU_CHANGE_PORT = wx.NewId() |
|
208 |
TBMENU_CHANGE_INTERFACE = wx.NewId() |
|
209 |
TBMENU_LIVE_SHELL = wx.NewId() |
|
210 |
TBMENU_WXINSPECTOR = wx.NewId() |
|
211 |
TBMENU_CHANGE_WD = wx.NewId() |
|
212 |
TBMENU_QUIT = wx.NewId() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
213 |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
214 |
def __init__(self, pyroserver, level): |
641 | 215 |
wx.TaskBarIcon.__init__(self) |
216 |
self.pyroserver = pyroserver |
|
217 |
# Set the image |
|
218 |
self.UpdateIcon(None) |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
219 |
self.level = level |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
220 |
|
641 | 221 |
# bind some events |
222 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
|
223 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
|
224 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
|
225 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) |
|
226 |
self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) |
|
227 |
self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) |
|
228 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) |
|
229 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) |
|
230 |
self.Bind(wx.EVT_MENU, self.OnTaskBarQuit, id=self.TBMENU_QUIT) |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
231 |
|
641 | 232 |
def CreatePopupMenu(self): |
233 |
""" |
|
234 |
This method is called by the base class when it needs to popup |
|
235 |
the menu for the default EVT_RIGHT_DOWN event. Just create |
|
236 |
the menu how you want it and return it from this function, |
|
237 |
the base class takes care of the rest. |
|
238 |
""" |
|
239 |
menu = wx.Menu() |
|
240 |
menu.Append(self.TBMENU_START, _("Start PLC")) |
|
241 |
menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
242 |
if self.level==1: |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
243 |
menu.AppendSeparator() |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
244 |
menu.Append(self.TBMENU_CHANGE_NAME, _("Change Name")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
245 |
menu.Append(self.TBMENU_CHANGE_INTERFACE, _("Change IP of interface to bind")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
246 |
menu.Append(self.TBMENU_CHANGE_PORT, _("Change Port Number")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
247 |
menu.Append(self.TBMENU_CHANGE_WD, _("Change working directory")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
248 |
menu.AppendSeparator() |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
249 |
menu.Append(self.TBMENU_LIVE_SHELL, _("Launch a live Python shell")) |
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
250 |
menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
641 | 251 |
menu.AppendSeparator() |
252 |
menu.Append(self.TBMENU_QUIT, _("Quit")) |
|
253 |
return menu |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
254 |
|
641 | 255 |
def MakeIcon(self, img): |
256 |
""" |
|
257 |
The various platforms have different requirements for the |
|
258 |
icon size... |
|
259 |
""" |
|
260 |
if "wxMSW" in wx.PlatformInfo: |
|
261 |
img = img.Scale(16, 16) |
|
262 |
elif "wxGTK" in wx.PlatformInfo: |
|
263 |
img = img.Scale(22, 22) |
|
264 |
# wxMac can be any size upto 128x128, so leave the source img alone.... |
|
265 |
icon = wx.IconFromBitmap(img.ConvertToBitmap() ) |
|
266 |
return icon |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
267 |
|
641 | 268 |
def OnTaskBarStartPLC(self, evt): |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
269 |
if self.pyroserver.plcobj is not None: |
641 | 270 |
self.pyroserver.plcobj.StartPLC() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
271 |
|
641 | 272 |
def OnTaskBarStopPLC(self, evt): |
273 |
if self.pyroserver.plcobj is not None: |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
274 |
Thread(target=self.pyroserver.plcobj.StopPLC).start() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
275 |
|
641 | 276 |
def OnTaskBarChangeInterface(self, evt): |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
277 |
dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=self.pyroserver.ip_addr) |
641 | 278 |
dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), |
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
279 |
( lambda x :len([x for x in x.split(".") if 0 <= int(x) <= 255]) == 4, _("IP is not valid!")) |
641 | 280 |
]) |
281 |
if dlg.ShowModal() == wx.ID_OK: |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
282 |
self.pyroserver.ip_addr = dlg.GetValue() |
641 | 283 |
self.pyroserver.Stop() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
284 |
|
641 | 285 |
def OnTaskBarChangePort(self, evt): |
286 |
dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
|
287 |
dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port : 0 <= int(port) <= 65535 , _("Port number must be 0 <= port <= 65535!"))]) |
|
288 |
if dlg.ShowModal() == wx.ID_OK: |
|
289 |
self.pyroserver.port = int(dlg.GetValue()) |
|
290 |
self.pyroserver.Stop() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
291 |
|
641 | 292 |
def OnTaskBarChangeWorkingDir(self, evt): |
293 |
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
|
294 |
if dlg.ShowModal() == wx.ID_OK: |
|
295 |
self.pyroserver.workdir = dlg.GetPath() |
|
296 |
self.pyroserver.Stop() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
297 |
|
641 | 298 |
def OnTaskBarChangeName(self, evt): |
299 |
dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=self.pyroserver.name) |
|
300 |
dlg.SetTests([(lambda name : len(name) is not 0 , _("Name must not be null!"))]) |
|
301 |
if dlg.ShowModal() == wx.ID_OK: |
|
302 |
self.pyroserver.name = dlg.GetValue() |
|
303 |
self.pyroserver.Restart() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
304 |
|
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
305 |
def _LiveShellLocals(self): |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
306 |
if self.pyroserver.plcobj is not None: |
1049 | 307 |
return {"locals":self.pyroserver.plcobj.python_runtime_vars} |
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
308 |
else: |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
309 |
return {} |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
310 |
|
641 | 311 |
def OnTaskBarLiveShell(self, evt): |
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
312 |
from wx import py |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
313 |
frame = py.crust.CrustFrame(**self._LiveShellLocals()) |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
314 |
frame.Show() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
315 |
|
641 | 316 |
def OnTaskBarWXInspector(self, evt): |
317 |
# Activate the widget inspection tool |
|
318 |
from wx.lib.inspection import InspectionTool |
|
319 |
if not InspectionTool().initialized: |
|
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
320 |
InspectionTool().Init(**self._LiveShellLocals()) |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
321 |
|
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
322 |
wnd = wx.GetApp() |
641 | 323 |
InspectionTool().Show(wnd, True) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
324 |
|
641 | 325 |
def OnTaskBarQuit(self, evt): |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
326 |
if wx.Platform == '__WXMSW__': |
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
327 |
Thread(target=self.pyroserver.Quit).start() |
641 | 328 |
self.RemoveIcon() |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
329 |
wx.CallAfter(wx.GetApp().ExitMainLoop) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
330 |
|
641 | 331 |
def UpdateIcon(self, plcstatus): |
332 |
if plcstatus is "Started" : |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
333 |
currenticon = self.MakeIcon(starticon) |
641 | 334 |
elif plcstatus is "Stopped": |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
335 |
currenticon = self.MakeIcon(stopicon) |
641 | 336 |
else: |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
337 |
currenticon = self.MakeIcon(defaulticon) |
641 | 338 |
self.SetIcon(currenticon, "Beremiz Service") |
339 |
||
340 |
from runtime import PLCObject, PLCprint, ServicePublisher |
|
341 |
import Pyro.core as pyro |
|
342 |
||
343 |
if not os.path.isdir(WorkingDir): |
|
344 |
os.mkdir(WorkingDir) |
|
345 |
||
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
346 |
def default_evaluator(tocall, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
347 |
try: |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
348 |
res=(tocall(*args,**kwargs), None) |
1051
847d68c3e7ff
Extended exception info from evaluator. Problems in python runtime init/cleanup code now more readable
Edouard Tisserant
parents:
1049
diff
changeset
|
349 |
except Exception: |
847d68c3e7ff
Extended exception info from evaluator. Problems in python runtime init/cleanup code now more readable
Edouard Tisserant
parents:
1049
diff
changeset
|
350 |
res=(None, sys.exc_info()) |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
351 |
return res |
641 | 352 |
|
353 |
class Server(): |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
354 |
def __init__(self, servicename, ip_addr, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
355 |
workdir, argv, autostart=False, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
356 |
statuschange=None, evaluator=default_evaluator, |
1458 | 357 |
pyruntimevars=None): |
641 | 358 |
self.continueloop = True |
359 |
self.daemon = None |
|
360 |
self.servicename = servicename |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
361 |
self.ip_addr = ip_addr |
641 | 362 |
self.port = port |
363 |
self.workdir = workdir |
|
364 |
self.argv = argv |
|
365 |
self.plcobj = None |
|
366 |
self.servicepublisher = None |
|
367 |
self.autostart = autostart |
|
368 |
self.statuschange = statuschange |
|
369 |
self.evaluator = evaluator |
|
1458 | 370 |
self.pyruntimevars = pyruntimevars |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
371 |
|
641 | 372 |
def Loop(self): |
373 |
while self.continueloop: |
|
374 |
self.Start() |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
375 |
|
641 | 376 |
def Restart(self): |
377 |
self.Stop() |
|
378 |
||
379 |
def Quit(self): |
|
380 |
self.continueloop = False |
|
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
381 |
if self.plcobj is not None: |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
382 |
self.plcobj.UnLoadPLC() |
641 | 383 |
self.Stop() |
384 |
||
385 |
def Start(self): |
|
386 |
pyro.initServer() |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
387 |
self.daemon=pyro.Daemon(host=self.ip_addr, port=self.port) |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
388 |
self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
389 |
self.statuschange, self.evaluator, |
1458 | 390 |
self.pyruntimevars) |
641 | 391 |
uri = self.daemon.connect(self.plcobj,"PLCObject") |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
392 |
|
641 | 393 |
print "Pyro port :",self.port |
394 |
print "Pyro object's uri :",uri |
|
395 |
print "Current working directory :",self.workdir |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
396 |
|
641 | 397 |
# Configure and publish service |
398 |
# Not publish service if localhost in address params |
|
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
399 |
if (self.servicename is not None and |
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
400 |
self.ip_addr is not None and |
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
401 |
self.ip_addr != "localhost" and |
648
73295e742da2
Avoid starting Zeroconf if ip unspecified or set to localhost. Pick one interface address when given IP is 0.0.0.0
Edouard Tisserant
parents:
644
diff
changeset
|
402 |
self.ip_addr != "127.0.0.1"): |
641 | 403 |
print "Publishing service on local network" |
404 |
self.servicepublisher = ServicePublisher.ServicePublisher() |
|
644
b511cab580eb
Better naming of IP address related variables in Beremiz_service.py, Ignore errors that occur on shutdown in Zeroconf.py, fixed discovery dialog crash due to asynchronous call from zeroconf
Edouard Tisserant
parents:
641
diff
changeset
|
405 |
self.servicepublisher.RegisterService(self.servicename, self.ip_addr, self.port) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
406 |
|
1447
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1446
diff
changeset
|
407 |
if self.autostart : |
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1446
diff
changeset
|
408 |
self.plcobj.AutoLoad() |
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1446
diff
changeset
|
409 |
if self.plcobj.GetPLCstatus()[0] != "Empty": |
d6b878525ceb
Fixed systematically loading PLC binary at startup even without -a parameter. Extended py_ext extensions instances variable description (PLCGlobalsDesc). Now contains list of variables organizd by extension, with extension name
Edouard Tisserant
parents:
1446
diff
changeset
|
410 |
self.plcobj.StartPLC() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
411 |
|
641 | 412 |
sys.stdout.flush() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
413 |
|
641 | 414 |
self.daemon.requestLoop() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
415 |
|
641 | 416 |
def Stop(self): |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
417 |
if self.plcobj is not None: |
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
418 |
self.plcobj.StopPLC() |
641 | 419 |
if self.servicepublisher is not None: |
420 |
self.servicepublisher.UnRegisterService() |
|
421 |
self.servicepublisher = None |
|
422 |
self.daemon.shutdown(True) |
|
423 |
||
424 |
if enabletwisted: |
|
425 |
import warnings |
|
426 |
with warnings.catch_warnings(): |
|
427 |
warnings.simplefilter("ignore") |
|
428 |
try: |
|
429 |
from threading import Thread, currentThread |
|
430 |
if havewx: |
|
431 |
from twisted.internet import wxreactor |
|
432 |
wxreactor.install() |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
433 |
from twisted.internet import reactor |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
434 |
|
641 | 435 |
havetwisted = True |
436 |
except: |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
437 |
print "Twisted unavailable." |
641 | 438 |
havetwisted = False |
439 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
440 |
pyruntimevars = {} |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
441 |
statuschange = [] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
442 |
|
641 | 443 |
if havetwisted: |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
444 |
|
641 | 445 |
if havewx: |
446 |
reactor.registerWxApp(app) |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
447 |
|
641 | 448 |
if havewx: |
449 |
from threading import Semaphore |
|
450 |
wx_eval_lock = Semaphore(0) |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
451 |
main_thread = currentThread() |
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
452 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
453 |
def statuschangeTskBar(status): |
641 | 454 |
wx.CallAfter(taskbar_instance.UpdateIcon,status) |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
455 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
456 |
statuschange.append(statuschangeTskBar) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
457 |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
458 |
def wx_evaluator(obj, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
459 |
tocall,args,kwargs = obj.call |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
460 |
obj.res = default_evaluator(tocall, *args, **kwargs) |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
461 |
wx_eval_lock.release() |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
462 |
|
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
463 |
def evaluator(tocall, *args, **kwargs): |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
464 |
global main_thread |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
465 |
if(main_thread == currentThread()): |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
466 |
# avoid dead lock if called from the wx mainloop |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
467 |
return default_evaluator(tocall, *args, **kwargs) |
641 | 468 |
else: |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
469 |
o=type('',(object,),dict(call=(tocall, args, kwargs), res=None)) |
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
470 |
wx.CallAfter(wx_evaluator,o) |
641 | 471 |
wx_eval_lock.acquire() |
867
06495975e8a4
Added caching for python eval (avoid compiling when same code called, but still execute). Cleaned up some evaluator related code.
Edouard Tisserant
parents:
850
diff
changeset
|
472 |
return o.res |
1434
6e0cd0ceabb7
Added runtime side trace buffer, handled in a separate thread, limited to 1MB, and dropped after 3 seconds if not used by IDE. GetTraceVariables is not anymore blocking on next PLC cycle
Edouard Tisserant
parents:
1270
diff
changeset
|
473 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
474 |
pyroserver = Server(servicename, given_ip, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
475 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
476 |
statuschange, evaluator, pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
477 |
|
835
8145be14a2ae
Fixed runtime GUI freeze when stopping PLC from the menu. Added -x 2 argument to Beremiz_service.py to restrict content of systray icon menu.
Edouard Tisserant
parents:
719
diff
changeset
|
478 |
taskbar_instance = BeremizTaskBarIcon(pyroserver, enablewx) |
641 | 479 |
else: |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
480 |
pyroserver = Server(servicename, given_ip, port, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
481 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
482 |
statuschange, pyruntimevars=pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
483 |
|
641 | 484 |
|
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
485 |
# Exception hooks s |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
486 |
import threading, traceback |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
487 |
def LogException(*exp): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
488 |
if pyroserver.plcobj is not None: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
489 |
pyroserver.plcobj.LogMessage(0,'\n'.join(traceback.format_exception(*exp))) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
490 |
else: |
1270 | 491 |
traceback.print_exception(*exp) |
1067
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
492 |
|
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
493 |
sys.excepthook = LogException |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
494 |
def installThreadExcepthook(): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
495 |
init_old = threading.Thread.__init__ |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
496 |
def init(self, *args, **kwargs): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
497 |
init_old(self, *args, **kwargs) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
498 |
run_old = self.run |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
499 |
def run_with_except_hook(*args, **kw): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
500 |
try: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
501 |
run_old(*args, **kw) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
502 |
except (KeyboardInterrupt, SystemExit): |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
503 |
raise |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
504 |
except: |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
505 |
sys.excepthook(*sys.exc_info()) |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
506 |
self.run = run_with_except_hook |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
507 |
threading.Thread.__init__ = init |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
508 |
installThreadExcepthook() |
4f460c1dffb5
Added exception hook to Beremiz_service, so that exception go in PLC log. Extended Beremiz.py exception hook to threads. Stripped images embedded in Beremiz_service.py, user real images instead.
Edouard Tisserant
parents:
1051
diff
changeset
|
509 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
510 |
if havetwisted: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
511 |
if webport is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
512 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
513 |
import runtime.NevowServer as NS |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
514 |
except Exception, e: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
515 |
print "Nevow/Athena import failed :", e |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
516 |
webport = None |
1453 | 517 |
NS.WorkingDir = WorkingDir |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
518 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
519 |
if wampconf is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
520 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
521 |
import runtime.WampClient as WC |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
522 |
except Exception, e: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
523 |
print "WAMP import failed :", e |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
524 |
wampconf = None |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
525 |
|
1437
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
526 |
# Load extensions |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
527 |
for extfilename in extensions: |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
528 |
extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
529 |
sys.path.append(extension_folder) |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
530 |
execfile(extfilename, locals()) |
04177743b066
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Edouard Tisserant
parents:
1434
diff
changeset
|
531 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
532 |
if havetwisted: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
533 |
if webport is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
534 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
535 |
website = NS.RegisterWebsite(webport) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
536 |
pyruntimevars["website"] = website |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
537 |
statuschange.append(NS.website_statuslistener_factory(website)) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
538 |
except Exception, e: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
539 |
print "Nevow Web service failed.", e |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
540 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
541 |
if wampconf is not None : |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
542 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
543 |
WC.RegisterWampClient(wampconf) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
544 |
pyruntimevars["wampsession"] = WC.GetSession |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
545 |
WC.SetServer(pyroserver) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
546 |
except Exception, e: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
547 |
print "WAMP client startup failed.", e |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
548 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
549 |
|
641 | 550 |
if havetwisted or havewx: |
551 |
pyro_thread=Thread(target=pyroserver.Loop) |
|
552 |
pyro_thread.start() |
|
553 |
||
554 |
if havetwisted: |
|
555 |
reactor.run() |
|
556 |
elif havewx: |
|
557 |
app.MainLoop() |
|
558 |
else: |
|
559 |
try : |
|
560 |
pyroserver.Loop() |
|
561 |
except KeyboardInterrupt,e: |
|
562 |
pass |
|
563 |
pyroserver.Quit() |
|
564 |
sys.exit(0) |