author | greg |
Tue, 02 Sep 2008 12:21:58 +0200 | |
changeset 233 | 95b5aa098c4a |
parent 217 | f3eb35df4d87 |
child 262 | 141a7145c099 |
permissions | -rw-r--r-- |
203 | 1 |
#!/usr/bin/env python |
2 |
# -*- coding: utf-8 -*- |
|
3 |
||
4 |
#This file is part of Beremiz, a Integrated Development Environment for |
|
5 |
#programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
|
6 |
# |
|
7 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 |
# |
|
9 |
#See COPYING file for copyrights details. |
|
10 |
# |
|
11 |
#This library is free software; you can redistribute it and/or |
|
12 |
#modify it under the terms of the GNU General Public |
|
13 |
#License as published by the Free Software Foundation; either |
|
14 |
#version 2.1 of the License, or (at your option) any later version. |
|
15 |
# |
|
16 |
#This library is distributed in the hope that it will be useful, |
|
17 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
19 |
#General Public License for more details. |
|
20 |
# |
|
21 |
#You should have received a copy of the GNU General Public |
|
22 |
#License along with this library; if not, write to the Free Software |
|
23 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
24 |
||
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
25 |
import os, sys, getopt |
203 | 26 |
|
27 |
def usage(): |
|
206 | 28 |
print """ |
29 |
Usage of Beremiz PLC execution service :\n |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
30 |
%s {[-n name] [-i ip] [-p port]|-h|--help} working_dir |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
31 |
-n - zeroconf service name |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
32 |
-i - ip of interface to bind to (x.x.x.x) |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
33 |
-p - port number |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
34 |
-h - print this help text and quit |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
35 |
|
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
36 |
working_dir - directory where are stored PLC files |
206 | 37 |
"""%sys.argv[0] |
203 | 38 |
|
39 |
try: |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
40 |
opts, args = getopt.getopt(sys.argv[1:], "i:p:n:h") |
206 | 41 |
except getopt.GetoptError, err: |
203 | 42 |
# print help information and exit: |
206 | 43 |
print str(err) # will print something like "option -a not recognized" |
203 | 44 |
usage() |
45 |
sys.exit(2) |
|
46 |
||
206 | 47 |
# default values |
48 |
ip = "" |
|
49 |
port = 3000 |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
50 |
name = os.environ[{ |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
51 |
"linux2":"USER", |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
52 |
"win32":"USERNAME", |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
53 |
}.get(sys.platform, "USER")] |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
54 |
|
203 | 55 |
for o, a in opts: |
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
56 |
if o == "-h": |
203 | 57 |
usage() |
58 |
sys.exit() |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
59 |
elif o == "-i": |
206 | 60 |
if len(a.split(".")) == 4 or a == "localhost": |
61 |
ip = a |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
62 |
elif o == "-p": |
206 | 63 |
# port: port that the service runs on |
64 |
port = int(a) |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
65 |
elif o == "-n": |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
66 |
name = a |
206 | 67 |
else: |
68 |
usage() |
|
69 |
sys.exit() |
|
203 | 70 |
|
210
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
71 |
if len(args) > 1: |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
72 |
usage() |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
73 |
sys.exit() |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
74 |
elif len(args) == 1: |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
75 |
WorkingDir = args[0] |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
76 |
elif len(args) == 0: |
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
77 |
WorkingDir = os.getcwd() |
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
78 |
args=[WorkingDir] |
210
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
79 |
|
203 | 80 |
from runtime import PLCObject, ServicePublisher |
81 |
import Pyro.core as pyro |
|
82 |
||
83 |
if not os.path.isdir(WorkingDir): |
|
84 |
os.mkdir(WorkingDir) |
|
85 |
||
86 |
||
87 |
pyro.initServer() |
|
88 |
daemon=pyro.Daemon(host=ip, port=port) |
|
210
ca3bfcf61192
Fixed oddities in arguments/options parsing and passing to plugins initialization...
etisserant
parents:
208
diff
changeset
|
89 |
uri = daemon.connect(PLCObject(WorkingDir, daemon, args),"PLCObject") |
207 | 90 |
|
203 | 91 |
print "The daemon runs on port :",daemon.port |
92 |
print "The object's uri is :",uri |
|
93 |
print "The working directory :",WorkingDir |
|
94 |
||
95 |
# Configure and publish service |
|
207 | 96 |
# Not publish service if localhost in address params |
97 |
if ip != "localhost" and ip != "127.0.0.1": |
|
98 |
print "Publish service on local network" |
|
217
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
99 |
service = ServicePublisher.ServicePublisher(name, ip, port) |
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
100 |
|
f3eb35df4d87
Now, Beremiz launch Beremiz_service at startup, with a one-time workin dir
etisserant
parents:
210
diff
changeset
|
101 |
sys.stdout.flush() |
203 | 102 |
|
103 |
daemon.requestLoop() |