author | Edouard Tisserant |
Mon, 19 Feb 2018 15:14:30 +0100 | |
changeset 1948 | b9a3f771aaab |
parent 1934 | 67b06b30f2bd |
child 1953 | 5736d25bb393 |
permissions | -rwxr-xr-x |
641 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
4 |
# This file is part of Beremiz, a Integrated Development Environment for |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
5 |
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
641 | 6 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
7 |
# 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:
1598
diff
changeset
|
8 |
# Copyright (C) 2017: Andrey Skvortsov |
641 | 9 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
641 | 11 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
12 |
# This program is free software; you can redistribute it and/or |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
13 |
# modify it under the terms of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
14 |
# as published by the Free Software Foundation; either version 2 |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
15 |
# of the License, or (at your option) any later version. |
641 | 16 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
17 |
# This program is distributed in the hope that it will be useful, |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
18 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
19 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
20 |
# GNU General Public License for more details. |
641 | 21 |
# |
1571
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
22 |
# You should have received a copy of the GNU General Public License |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
23 |
# along with this program; if not, write to the Free Software |
486f94a8032c
fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1458
diff
changeset
|
24 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
641 | 25 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
26 |
|
1881
091005ec69c4
fix pylint py3k conversion warning: "(no-absolute-import) import missing `from __future__ import absolute_import`"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1872
diff
changeset
|
27 |
from __future__ import absolute_import |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
28 |
from __future__ import print_function |
1732
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
29 |
import os |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
30 |
import sys |
94ffe74e6895
clean-up: fix PEP8 E401 multiple imports on one line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1730
diff
changeset
|
31 |
import getopt |
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
32 |
import threading |
1834
cd42b426028b
fix ungrouped imports from package X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1831
diff
changeset
|
33 |
from threading import Thread, currentThread, Semaphore |
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
34 |
import traceback |
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
35 |
import __builtin__ |
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
36 |
import Pyro.core as pyro |
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
37 |
|
1850
614396cbffbf
fix pylint warning '(unused-import), Unused import connectors'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1847
diff
changeset
|
38 |
from runtime import PLCObject, ServicePublisher |
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
39 |
import util.paths as paths |
641 | 40 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
41 |
|
641 | 42 |
def usage(): |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
43 |
print(""" |
641 | 44 |
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
|
45 |
%s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir |
641 | 46 |
-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
|
47 |
-i - IP address of interface to bind to (default:localhost) |
641 | 48 |
-p - port number default:3000 |
49 |
-h - print this help text and quit |
|
50 |
-a - autostart PLC (0:disable 1:enable) (default:0) |
|
51 |
-x - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1) |
|
52 |
-t - enable/disable Twisted web interface (0:disable 1:enable) (default:1) |
|
1934
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
53 |
-w - web server port or "off" to disable web server (default:8009) |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
54 |
-c - WAMP client default config file (default:wampconf.json) |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
55 |
-s - WAMP client secret, given as a file |
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
|
56 |
-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
|
57 |
|
641 | 58 |
working_dir - directory where are stored PLC files |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
59 |
""" % sys.argv[0]) |
641 | 60 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
61 |
|
641 | 62 |
try: |
1900
9d1547578f55
runtime/WAMP: Fixed secret loading into configuration. Fixed secret commandline switch handling.
Edouard Tisserant
parents:
1894
diff
changeset
|
63 |
opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:s:h") |
641 | 64 |
except getopt.GetoptError, err: |
65 |
# print help information and exit: |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
66 |
print(str(err)) # will print something like "option -a not recognized" |
641 | 67 |
usage() |
68 |
sys.exit(2) |
|
69 |
||
70 |
# 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
|
71 |
given_ip = None |
641 | 72 |
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
|
73 |
webport = 8009 |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1889
diff
changeset
|
74 |
wampsecret = None |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1889
diff
changeset
|
75 |
wampconf = None |
641 | 76 |
servicename = None |
77 |
autostart = False |
|
78 |
enablewx = True |
|
79 |
havewx = False |
|
80 |
enabletwisted = True |
|
81 |
havetwisted = False |
|
82 |
||
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
83 |
extensions = [] |
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
|
84 |
|
641 | 85 |
for o, a in opts: |
86 |
if o == "-h": |
|
87 |
usage() |
|
88 |
sys.exit() |
|
89 |
elif o == "-i": |
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
sys.exit() |
641 | 95 |
elif o == "-p": |
96 |
# port: port that the service runs on |
|
97 |
port = int(a) |
|
98 |
elif o == "-n": |
|
99 |
servicename = a |
|
100 |
elif o == "-x": |
|
101 |
enablewx = int(a) |
|
102 |
elif o == "-t": |
|
103 |
enabletwisted = int(a) |
|
104 |
elif o == "-a": |
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
wampconf = None if a == "off" else a |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1889
diff
changeset
|
110 |
elif o == "-s": |
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1889
diff
changeset
|
111 |
wampsecret = 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
|
112 |
elif o == "-e": |
1907
9d17b9d91697
fixed erro introduced 2 commits ago (-e) : tuples have no reverse() method
Edouard Tisserant
parents:
1906
diff
changeset
|
113 |
l = list(os.path.split(os.path.realpath(a))) |
1905
87c908079bc6
Changed way to deal with extensions arguments (-e) so that path and filename are stored independently and accessible for extensions themselves.
Edouard Tisserant
parents:
1901
diff
changeset
|
114 |
l.reverse() |
87c908079bc6
Changed way to deal with extensions arguments (-e) so that path and filename are stored independently and accessible for extensions themselves.
Edouard Tisserant
parents:
1901
diff
changeset
|
115 |
extensions.append(l) |
641 | 116 |
else: |
117 |
usage() |
|
118 |
sys.exit() |
|
119 |
||
1783
3311eea28d56
clean-up: fix PEP8 E402 module level import not at top of file
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1780
diff
changeset
|
120 |
|
1680
6db967480b7d
make run Beremiz and PLCOpen Editor, if full path contain non-lating
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1598
diff
changeset
|
121 |
beremiz_dir = paths.AbsDir(__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
|
122 |
|
641 | 123 |
if len(argv) > 1: |
124 |
usage() |
|
125 |
sys.exit() |
|
126 |
elif len(argv) == 1: |
|
127 |
WorkingDir = argv[0] |
|
128 |
os.chdir(WorkingDir) |
|
129 |
elif len(argv) == 0: |
|
130 |
WorkingDir = os.getcwd() |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
131 |
argv = [WorkingDir] |
641 | 132 |
|
133 |
if __name__ == '__main__': |
|
134 |
__builtin__.__dict__['_'] = lambda x: x |
|
135 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
136 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
137 |
def Bpath(*args): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
138 |
return os.path.join(beremiz_dir, *args) |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
139 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
140 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
141 |
def SetupI18n(): |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
142 |
# Get folder containing translation files |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
143 |
localedir = os.path.join(beremiz_dir, "locale") |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
144 |
# Get the default language |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
145 |
langid = wx.LANGUAGE_DEFAULT |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
146 |
# Define translation domain (name of translation files) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
147 |
domain = "Beremiz" |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
148 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
149 |
# Define locale for wx |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
150 |
loc = __builtin__.__dict__.get('loc', None) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
151 |
if loc is None: |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
152 |
loc = wx.Locale(langid) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
153 |
__builtin__.__dict__['loc'] = loc |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
154 |
# Define location for searching translation files |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
155 |
loc.AddCatalogLookupPathPrefix(localedir) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
156 |
# Define locale domain |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
157 |
loc.AddCatalog(domain) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
158 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
159 |
import locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
160 |
global default_locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
161 |
default_locale = locale.getdefaultlocale()[1] |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
162 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
163 |
# sys.stdout.encoding = default_locale |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
164 |
# if Beremiz_service is started from Beremiz IDE |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
165 |
# sys.stdout.encoding is None (that means 'ascii' encoding'). |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
166 |
# And unicode string returned by wx.GetTranslation() are |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
167 |
# automatically converted to 'ascii' string. |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
168 |
def unicode_translation(message): |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
169 |
return wx.GetTranslation(message).encode(default_locale) |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
170 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
171 |
if __name__ == '__main__': |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
172 |
__builtin__.__dict__['_'] = unicode_translation |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
173 |
# __builtin__.__dict__['_'] = wx.GetTranslation |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
174 |
|
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
175 |
|
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1916
diff
changeset
|
176 |
# Life is hard... have a candy. |
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1916
diff
changeset
|
177 |
# pylint: disable=wrong-import-position,wrong-import-order |
641 | 178 |
if enablewx: |
179 |
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
|
180 |
import wx |
641 | 181 |
havewx = True |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
182 |
except ImportError: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
183 |
print("Wx unavailable !") |
641 | 184 |
havewx = False |
185 |
||
186 |
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
|
187 |
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
|
188 |
from types import * |
1590
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
189 |
|
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
190 |
if wx.VERSION >= (3, 0, 0): |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
191 |
app = wx.App(redirect=False) |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
192 |
else: |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
193 |
app = wx.PySimpleApp(redirect=False) |
cdf95900d44f
add python-wxgtk3.0 support to Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1571
diff
changeset
|
194 |
app.SetTopWindow(wx.Frame(None, -1)) |
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
|
195 |
|
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
196 |
default_locale = None |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
197 |
SetupI18n() |
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
|
198 |
|
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
|
641 | 203 |
class ParamsEntryDialog(wx.TextEntryDialog): |
204 |
if wx.VERSION < (2, 6, 0): |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
205 |
def Bind(self, event, function, id=None): |
641 | 206 |
if id is not None: |
207 |
event(self, id, function) |
|
208 |
else: |
|
209 |
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
|
210 |
|
1744
69dfdb26f600
clean-up: fix PEP8 E251 unexpected spaces around keyword / parameter equals
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1742
diff
changeset
|
211 |
def __init__(self, parent, message, caption=_("Please enter text"), defaultValue="", |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
212 |
style=wx.OK | wx.CANCEL | wx.CENTRE, pos=wx.DefaultPosition): |
641 | 213 |
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
|
214 |
|
641 | 215 |
self.Tests = [] |
216 |
if wx.VERSION >= (2, 8, 0): |
|
217 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetAffirmativeId()) |
|
218 |
elif wx.VERSION >= (2, 6, 0): |
|
219 |
self.Bind(wx.EVT_BUTTON, self.OnOK, id=self.GetSizer().GetItem(3).GetSizer().GetAffirmativeButton().GetId()) |
|
220 |
else: |
|
221 |
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
|
222 |
|
641 | 223 |
def OnOK(self, event): |
224 |
value = self.GetValue() |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
225 |
texts = {"value": value} |
641 | 226 |
for function, message in self.Tests: |
227 |
if not function(value): |
|
1745
f9d32913bad4
clean-up: fix PEP8 E227 missing whitespace around bitwise or shift operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1744
diff
changeset
|
228 |
message = wx.MessageDialog(self, message % texts, _("Error"), wx.OK | wx.ICON_ERROR) |
641 | 229 |
message.ShowModal() |
230 |
message.Destroy() |
|
231 |
return |
|
232 |
self.EndModal(wx.ID_OK) |
|
233 |
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
|
234 |
|
641 | 235 |
def GetValue(self): |
236 |
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
|
237 |
|
641 | 238 |
def SetTests(self, tests): |
239 |
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
|
240 |
|
641 | 241 |
class BeremizTaskBarIcon(wx.TaskBarIcon): |
242 |
TBMENU_START = wx.NewId() |
|
243 |
TBMENU_STOP = wx.NewId() |
|
244 |
TBMENU_CHANGE_NAME = wx.NewId() |
|
245 |
TBMENU_CHANGE_PORT = wx.NewId() |
|
246 |
TBMENU_CHANGE_INTERFACE = wx.NewId() |
|
247 |
TBMENU_LIVE_SHELL = wx.NewId() |
|
248 |
TBMENU_WXINSPECTOR = wx.NewId() |
|
249 |
TBMENU_CHANGE_WD = wx.NewId() |
|
250 |
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
|
251 |
|
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
|
252 |
def __init__(self, pyroserver, level): |
641 | 253 |
wx.TaskBarIcon.__init__(self) |
254 |
self.pyroserver = pyroserver |
|
255 |
# Set the image |
|
256 |
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
|
257 |
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
|
258 |
|
641 | 259 |
# bind some events |
260 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStartPLC, id=self.TBMENU_START) |
|
261 |
self.Bind(wx.EVT_MENU, self.OnTaskBarStopPLC, id=self.TBMENU_STOP) |
|
262 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeName, id=self.TBMENU_CHANGE_NAME) |
|
263 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeInterface, id=self.TBMENU_CHANGE_INTERFACE) |
|
264 |
self.Bind(wx.EVT_MENU, self.OnTaskBarLiveShell, id=self.TBMENU_LIVE_SHELL) |
|
265 |
self.Bind(wx.EVT_MENU, self.OnTaskBarWXInspector, id=self.TBMENU_WXINSPECTOR) |
|
266 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangePort, id=self.TBMENU_CHANGE_PORT) |
|
267 |
self.Bind(wx.EVT_MENU, self.OnTaskBarChangeWorkingDir, id=self.TBMENU_CHANGE_WD) |
|
268 |
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
|
269 |
|
641 | 270 |
def CreatePopupMenu(self): |
271 |
""" |
|
272 |
This method is called by the base class when it needs to popup |
|
273 |
the menu for the default EVT_RIGHT_DOWN event. Just create |
|
274 |
the menu how you want it and return it from this function, |
|
275 |
the base class takes care of the rest. |
|
276 |
""" |
|
277 |
menu = wx.Menu() |
|
278 |
menu.Append(self.TBMENU_START, _("Start PLC")) |
|
279 |
menu.Append(self.TBMENU_STOP, _("Stop PLC")) |
|
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
280 |
if self.level == 1: |
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
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
menu.Append(self.TBMENU_WXINSPECTOR, _("Launch WX GUI inspector")) |
641 | 289 |
menu.AppendSeparator() |
290 |
menu.Append(self.TBMENU_QUIT, _("Quit")) |
|
291 |
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
|
292 |
|
641 | 293 |
def MakeIcon(self, img): |
294 |
""" |
|
295 |
The various platforms have different requirements for the |
|
296 |
icon size... |
|
297 |
""" |
|
298 |
if "wxMSW" in wx.PlatformInfo: |
|
299 |
img = img.Scale(16, 16) |
|
300 |
elif "wxGTK" in wx.PlatformInfo: |
|
301 |
img = img.Scale(22, 22) |
|
302 |
# wxMac can be any size upto 128x128, so leave the source img alone.... |
|
1746
45d6f5fba016
clean-up: fix PEP8 E202 whitespace before ')'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1745
diff
changeset
|
303 |
icon = wx.IconFromBitmap(img.ConvertToBitmap()) |
641 | 304 |
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
|
305 |
|
641 | 306 |
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
|
307 |
if self.pyroserver.plcobj is not None: |
1592
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
308 |
plcstatus = self.pyroserver.plcobj.GetPLCstatus()[0] |
1738
d2e979738700
clean-up: fix PEP8 E271 multiple spaces after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1737
diff
changeset
|
309 |
if plcstatus is "Stopped": |
1592
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
310 |
self.pyroserver.plcobj.StartPLC() |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
311 |
else: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
312 |
print(_("PLC is empty or already started.")) |
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
|
313 |
|
641 | 314 |
def OnTaskBarStopPLC(self, evt): |
315 |
if self.pyroserver.plcobj is not None: |
|
1592
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
316 |
if self.pyroserver.plcobj.GetPLCstatus()[0] == "Started": |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
317 |
Thread(target=self.pyroserver.plcobj.StopPLC).start() |
c40355f450a5
start/stop from taskbar icon only if PLC is stopped/started
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1591
diff
changeset
|
318 |
else: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
319 |
print(_("PLC is not started.")) |
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
|
320 |
|
641 | 321 |
def OnTaskBarChangeInterface(self, evt): |
1593
6a27490fed96
don't crash on trying to change IP interface for Beremiz_service using taskbar icon if IP wasn't previously
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1592
diff
changeset
|
322 |
ip_addr = self.pyroserver.ip_addr |
6a27490fed96
don't crash on trying to change IP interface for Beremiz_service using taskbar icon if IP wasn't previously
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1592
diff
changeset
|
323 |
ip_addr = '' if ip_addr is None else ip_addr |
1730
64d8f52bc8c8
clean-up for PEP8: fix W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1680
diff
changeset
|
324 |
dlg = ParamsEntryDialog(None, _("Enter the IP of the interface to bind"), defaultValue=ip_addr) |
641 | 325 |
dlg.SetTests([(re.compile('\d{1,3}(?:\.\d{1,3}){3}$').match, _("IP is not valid!")), |
1767
c74815729afd
clean-up: fix PEP8 E127 continuation line over-indented for visual indent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1766
diff
changeset
|
326 |
(lambda x:len([x for x in x.split(".") if 0 <= int(x) <= 255]) == 4, |
1773
38fde37c3766
clean-up: fix PEP8 E124 closing bracket does not match visual indentation
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1767
diff
changeset
|
327 |
_("IP is not valid!"))]) |
641 | 328 |
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
|
329 |
self.pyroserver.ip_addr = dlg.GetValue() |
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
330 |
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
|
331 |
|
641 | 332 |
def OnTaskBarChangePort(self, evt): |
333 |
dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port)) |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
334 |
dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port: 0 <= int(port) <= 65535, _("Port number must be 0 <= port <= 65535!"))]) |
641 | 335 |
if dlg.ShowModal() == wx.ID_OK: |
336 |
self.pyroserver.port = int(dlg.GetValue()) |
|
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
337 |
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
|
338 |
|
641 | 339 |
def OnTaskBarChangeWorkingDir(self, evt): |
340 |
dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON) |
|
341 |
if dlg.ShowModal() == wx.ID_OK: |
|
342 |
self.pyroserver.workdir = dlg.GetPath() |
|
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
343 |
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
|
344 |
|
641 | 345 |
def OnTaskBarChangeName(self, evt): |
1594
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
346 |
servicename = self.pyroserver.servicename |
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
347 |
servicename = '' if servicename is None else servicename |
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
348 |
dlg = ParamsEntryDialog(None, _("Enter a name "), defaultValue=servicename) |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
349 |
dlg.SetTests([(lambda name: len(name) is not 0, _("Name must not be null!"))]) |
641 | 350 |
if dlg.ShowModal() == wx.ID_OK: |
1594
049b7144a710
fix issue with changing annonced Pyro service name via taskbar icon
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1593
diff
changeset
|
351 |
self.pyroserver.servicename = dlg.GetValue() |
641 | 352 |
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
|
353 |
|
959
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
354 |
def _LiveShellLocals(self): |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
355 |
if self.pyroserver.plcobj is not None: |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
356 |
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
|
357 |
else: |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
358 |
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
|
359 |
|
641 | 360 |
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
|
361 |
from wx import py |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
362 |
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
|
363 |
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
|
364 |
|
641 | 365 |
def OnTaskBarWXInspector(self, evt): |
366 |
# Activate the widget inspection tool |
|
367 |
from wx.lib.inspection import InspectionTool |
|
368 |
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
|
369 |
InspectionTool().Init(**self._LiveShellLocals()) |
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
370 |
|
046aeae0d71c
Python shell and wx inspector now both available even when PLC not started
Edouard Tisserant
parents:
867
diff
changeset
|
371 |
wnd = wx.GetApp() |
641 | 372 |
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
|
373 |
|
641 | 374 |
def OnTaskBarQuit(self, evt): |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
375 |
if wx.Platform == '__WXMSW__': |
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
376 |
Thread(target=self.pyroserver.Quit).start() |
641 | 377 |
self.RemoveIcon() |
1121
d3838e8f1b90
Fixed Beremiz_service not closing on Windows
Laurent Bessard
parents:
1067
diff
changeset
|
378 |
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
|
379 |
|
641 | 380 |
def UpdateIcon(self, plcstatus): |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
381 |
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
|
382 |
currenticon = self.MakeIcon(starticon) |
641 | 383 |
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
|
384 |
currenticon = self.MakeIcon(stopicon) |
641 | 385 |
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
|
386 |
currenticon = self.MakeIcon(defaulticon) |
641 | 387 |
self.SetIcon(currenticon, "Beremiz Service") |
388 |
||
389 |
||
390 |
if not os.path.isdir(WorkingDir): |
|
391 |
os.mkdir(WorkingDir) |
|
392 |
||
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
393 |
|
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
|
394 |
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
|
395 |
try: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
396 |
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
|
397 |
except Exception: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
398 |
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
|
399 |
return res |
641 | 400 |
|
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
401 |
|
1831
56b48961cc68
fix (old-style-class) Old-style class defined error for most parts of
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1829
diff
changeset
|
402 |
class Server(object): |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
403 |
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
|
404 |
workdir, argv, autostart=False, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
405 |
statuschange=None, evaluator=default_evaluator, |
1458 | 406 |
pyruntimevars=None): |
641 | 407 |
self.continueloop = True |
408 |
self.daemon = None |
|
409 |
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
|
410 |
self.ip_addr = ip_addr |
641 | 411 |
self.port = port |
412 |
self.workdir = workdir |
|
413 |
self.argv = argv |
|
414 |
self.plcobj = None |
|
415 |
self.servicepublisher = None |
|
416 |
self.autostart = autostart |
|
417 |
self.statuschange = statuschange |
|
418 |
self.evaluator = evaluator |
|
1458 | 419 |
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
|
420 |
|
641 | 421 |
def Loop(self): |
422 |
while self.continueloop: |
|
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
423 |
pyro.initServer() |
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
424 |
self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port) |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
425 |
# pyro never frees memory after connection close if no timeout set |
1929
ed95aa627647
Fixed pyro timeout for runtime, was set too short and runtime was disconnecting when building PLC
Edouard Tisserant
parents:
1919
diff
changeset
|
426 |
# taking too small timeout value may cause |
ed95aa627647
Fixed pyro timeout for runtime, was set too short and runtime was disconnecting when building PLC
Edouard Tisserant
parents:
1919
diff
changeset
|
427 |
# unwanted diconnection when IDE is kept busy for long periods |
ed95aa627647
Fixed pyro timeout for runtime, was set too short and runtime was disconnecting when building PLC
Edouard Tisserant
parents:
1919
diff
changeset
|
428 |
self.daemon.setTimeout(60); |
641 | 429 |
self.Start() |
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
430 |
self.daemon.requestLoop() |
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
431 |
self.daemon.sock.close() |
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
|
432 |
|
641 | 433 |
def Restart(self): |
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
434 |
self._stop() |
641 | 435 |
|
436 |
def Quit(self): |
|
437 |
self.continueloop = False |
|
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
438 |
if self.plcobj is not None: |
1596
f5868f866d2b
stop PLC before unloading
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1595
diff
changeset
|
439 |
self.plcobj.StopPLC() |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
440 |
self.plcobj.UnLoadPLC() |
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
441 |
self._stop() |
641 | 442 |
|
443 |
def Start(self): |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
444 |
self.plcobj = PLCObject(self.workdir, self.daemon, self.argv, |
1889 | 445 |
self.statuschange, self.evaluator, |
446 |
self.pyruntimevars) |
|
447 |
||
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
448 |
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
|
449 |
|
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
450 |
print(_("Pyro port :"), self.port) |
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
451 |
print(_("Pyro object's uri :"), uri) |
1595
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
452 |
|
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
453 |
# Beremiz IDE detects daemon start by looking |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
454 |
# for self.workdir in the daemon's stdout. |
b3cc68dd037d
add internatialization support for Beremiz_service.py
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1594
diff
changeset
|
455 |
# Therefore don't delete the following line |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
456 |
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
|
457 |
|
641 | 458 |
# Configure and publish service |
459 |
# Not publish service if localhost in address params |
|
1766
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
460 |
if self.servicename is not None and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
461 |
self.ip_addr is not None and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
462 |
self.ip_addr != "localhost" and \ |
c1e5b9f19483
clean-up: fix PEP8 E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1750
diff
changeset
|
463 |
self.ip_addr != "127.0.0.1": |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
464 |
print(_("Publishing service on local network")) |
641 | 465 |
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
|
466 |
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
|
467 |
|
1597
0e4182e9cc09
always load existing PLC program from the working directory
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1596
diff
changeset
|
468 |
self.plcobj.AutoLoad() |
0e4182e9cc09
always load existing PLC program from the working directory
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1596
diff
changeset
|
469 |
if self.plcobj.GetPLCstatus()[0] != "Empty": |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
470 |
if self.autostart: |
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
|
471 |
self.plcobj.StartPLC() |
1598
1445457547f7
update PLC status after initialization
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1597
diff
changeset
|
472 |
self.plcobj.StatusChange() |
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 |
|
641 | 474 |
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
|
475 |
|
1887
1b9907ef770b
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Edouard Tisserant
parents:
1881
diff
changeset
|
476 |
def _stop(self): |
1045
a220a27defe5
Runtime now unloads and cleanup PLC before exit (created threads was preventing exit)
Edouard Tisserant
parents:
1034
diff
changeset
|
477 |
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
|
478 |
self.plcobj.StopPLC() |
641 | 479 |
if self.servicepublisher is not None: |
480 |
self.servicepublisher.UnRegisterService() |
|
481 |
self.servicepublisher = None |
|
482 |
self.daemon.shutdown(True) |
|
483 |
||
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
484 |
|
641 | 485 |
if enabletwisted: |
486 |
import warnings |
|
487 |
with warnings.catch_warnings(): |
|
488 |
warnings.simplefilter("ignore") |
|
489 |
try: |
|
490 |
if havewx: |
|
491 |
from twisted.internet import wxreactor |
|
492 |
wxreactor.install() |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
493 |
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
|
494 |
|
641 | 495 |
havetwisted = True |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
496 |
except ImportError: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
497 |
print(_("Twisted unavailable.")) |
641 | 498 |
havetwisted = False |
499 |
||
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
500 |
pyruntimevars = {} |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
501 |
statuschange = [] |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
502 |
|
641 | 503 |
if havetwisted: |
504 |
if havewx: |
|
505 |
reactor.registerWxApp(app) |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
506 |
|
641 | 507 |
if havewx: |
508 |
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
|
509 |
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
|
510 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
511 |
def statuschangeTskBar(status): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
512 |
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
|
513 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
514 |
statuschange.append(statuschangeTskBar) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
515 |
|
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
|
516 |
def wx_evaluator(obj, *args, **kwargs): |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
517 |
tocall, args, kwargs = obj.call |
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
|
518 |
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
|
519 |
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
|
520 |
|
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
|
521 |
def evaluator(tocall, *args, **kwargs): |
1828
396da88d7b5c
fix unnecessary parens after keyword
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1826
diff
changeset
|
522 |
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
|
523 |
# 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
|
524 |
return default_evaluator(tocall, *args, **kwargs) |
641 | 525 |
else: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
526 |
o = type('', (object,), dict(call=(tocall, args, kwargs), res=None)) |
1740
b789b695b5c6
clean-up: fix PEP8 E231 missing whitespace after ':' or ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1739
diff
changeset
|
527 |
wx.CallAfter(wx_evaluator, o) |
641 | 528 |
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
|
529 |
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
|
530 |
|
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
531 |
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
|
532 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
533 |
statuschange, evaluator, pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
534 |
|
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
|
535 |
taskbar_instance = BeremizTaskBarIcon(pyroserver, enablewx) |
641 | 536 |
else: |
1438
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
537 |
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
|
538 |
WorkingDir, argv, autostart, |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
539 |
statuschange, pyruntimevars=pyruntimevars) |
19ebe96b41c0
Moved twisted/nevow/athena away from Berermiz_service.py + some minor cleanup
Edouard Tisserant
parents:
1437
diff
changeset
|
540 |
|
641 | 541 |
|
1916 | 542 |
# Exception hooks |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
543 |
|
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
544 |
|
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
545 |
def LogMessageAndException(msg, exp=None): |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
546 |
if exp is None: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
547 |
exp = sys.exc_info() |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
548 |
if pyroserver.plcobj is not None: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
549 |
pyroserver.plcobj.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
550 |
else: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
551 |
print(msg) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
552 |
traceback.print_exception(*exp) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
553 |
|
1916 | 554 |
|
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
|
555 |
def LogException(*exp): |
1919
ccea0fa6ea91
Another set of meaningless changes to satisfy PEP8 and PyLint.
Edouard Tisserant
parents:
1916
diff
changeset
|
556 |
LogMessageAndException("", exp) |
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
557 |
|
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
|
558 |
sys.excepthook = LogException |
1736
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
559 |
|
7e61baa047f0
clean-up: fix PEP8 E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1734
diff
changeset
|
560 |
|
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
|
561 |
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
|
562 |
init_old = threading.Thread.__init__ |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
563 |
|
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
|
564 |
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
|
565 |
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
|
566 |
run_old = self.run |
1750
acf02488f37f
clean-up: fix PEP8 E306 expected 1 blank line before a nested definition, found X
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1749
diff
changeset
|
567 |
|
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
|
568 |
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
|
569 |
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
|
570 |
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
|
571 |
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
|
572 |
raise |
1780
c52d1460cea8
clean-up: fix PEP8 E722 do not use bare except'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1773
diff
changeset
|
573 |
except Exception: |
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
|
574 |
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
|
575 |
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
|
576 |
threading.Thread.__init__ = init |
1749
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
577 |
|
d73b64672238
clean-up: fix PEP8 E305 expected 2 blank lines after class or function definition
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1747
diff
changeset
|
578 |
|
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
|
579 |
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
|
580 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
581 |
if havetwisted: |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
582 |
if webport is not None: |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
583 |
try: |
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
584 |
import runtime.NevowServer as NS # pylint: disable=ungrouped-imports |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
585 |
except Exception, e: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
586 |
print(_("Nevow/Athena import failed :"), e) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
587 |
webport = None |
1453 | 588 |
NS.WorkingDir = WorkingDir |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
589 |
|
1934
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
590 |
# Find pre-existing project WAMP config file |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
591 |
_wampconf = os.path.join(WorkingDir, "wampconf.json") |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
592 |
|
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
593 |
# If project's WAMP config file exits, override default (-c) |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
594 |
if os.path.exists(_wampconf): |
67b06b30f2bd
Changed meaning of -c commandline argument for Beremiz service : only gives DEFAULT wamp config.
Edouard Tisserant
parents:
1929
diff
changeset
|
595 |
wampconf = _wampconf |
1894
f224383cc883
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents:
1893
diff
changeset
|
596 |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
597 |
if wampconf is not None: |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
598 |
try: |
1872
866fb3ab8778
fix pylint error "(undefined-variable) Undefined variable 'X'"
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1850
diff
changeset
|
599 |
import runtime.WampClient as WC # pylint: disable=ungrouped-imports |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
600 |
except Exception, e: |
1826
91796f408540
fix usage of python2-only print statement
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1790
diff
changeset
|
601 |
print(_("WAMP import failed :"), e) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
602 |
wampconf = None |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
603 |
|
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
|
604 |
# Load extensions |
1905
87c908079bc6
Changed way to deal with extensions arguments (-e) so that path and filename are stored independently and accessible for extensions themselves.
Edouard Tisserant
parents:
1901
diff
changeset
|
605 |
for extention_file, extension_folder in extensions: |
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
|
606 |
sys.path.append(extension_folder) |
1905
87c908079bc6
Changed way to deal with extensions arguments (-e) so that path and filename are stored independently and accessible for extensions themselves.
Edouard Tisserant
parents:
1901
diff
changeset
|
607 |
execfile(os.path.join(extension_folder, extention_file), locals()) |
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
|
608 |
|
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
609 |
if havetwisted: |
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
610 |
if webport is not None: |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
611 |
try: |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
612 |
website = NS.RegisterWebsite(webport) |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
613 |
pyruntimevars["website"] = website |
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
614 |
statuschange.append(NS.website_statuslistener_factory(website)) |
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
615 |
except Exception: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
616 |
LogMessageAndException(_("Nevow Web service failed. ")) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
617 |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
618 |
if wampconf is not None: |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
619 |
try: |
1901
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
620 |
_wampconf = WC.LoadWampClientConf(wampconf) |
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
621 |
if _wampconf: |
e8cf68d69447
Enforced check_source.sh pep8 and pylint rules.
Edouard Tisserant
parents:
1900
diff
changeset
|
622 |
if _wampconf["url"]: # TODO : test more ? |
1894
f224383cc883
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents:
1893
diff
changeset
|
623 |
WC.RegisterWampClient(wampconf, wampsecret) |
f224383cc883
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents:
1893
diff
changeset
|
624 |
pyruntimevars["wampsession"] = WC.GetSession |
f224383cc883
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents:
1893
diff
changeset
|
625 |
WC.SetServer(pyroserver) |
f224383cc883
Fixed changes from dporopat and agregorcic about WAMP CRA and config.
Edouard Tisserant
parents:
1893
diff
changeset
|
626 |
else: |
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
627 |
raise Exception(_("WAMP config is incomplete.")) |
1893
971de876b1af
WAMP runtime : changes from dporopat and agregorcic, adding CRA (-s) and changed way to load WAMP conf (-c)
Edouard Tisserant
parents:
1889
diff
changeset
|
628 |
else: |
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
629 |
raise Exception(_("WAMP config is missing.")) |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
630 |
except Exception: |
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
631 |
LogMessageAndException(_("WAMP client startup failed. ")) |
1446
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
632 |
|
4963e3816641
Split runtime's twisted modules import and setup to ease runtime extensions hotpatching
Edouard Tisserant
parents:
1439
diff
changeset
|
633 |
|
641 | 634 |
if havetwisted or havewx: |
1742
92932cd370a4
clean-up: fix PEP8 E225 missing whitespace around operator
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1741
diff
changeset
|
635 |
pyro_thread = Thread(target=pyroserver.Loop) |
641 | 636 |
pyro_thread.start() |
637 |
||
638 |
if havetwisted: |
|
639 |
reactor.run() |
|
640 |
elif havewx: |
|
641 |
app.MainLoop() |
|
642 |
else: |
|
1739
ec153828ded2
clean-up: fix PEP8 E203 whitespace before ':' and whitespace before ','
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
1738
diff
changeset
|
643 |
try: |
641 | 644 |
pyroserver.Loop() |
1906
60edd0c901f1
Trying to get better logging/display of exceptions at runtime's startup
Edouard Tisserant
parents:
1905
diff
changeset
|
645 |
except KeyboardInterrupt: |
641 | 646 |
pass |
647 |
pyroserver.Quit() |
|
648 |
sys.exit(0) |