50 for o, a in opts: |
50 for o, a in opts: |
51 if o in ("-h", "--help"): |
51 if o in ("-h", "--help"): |
52 usage() |
52 usage() |
53 sys.exit() |
53 sys.exit() |
54 elif o in ("-a", "--address"): |
54 elif o in ("-a", "--address"): |
55 #ip = socket.inet_aton(a) |
|
56 if len(a.split(".")) == 4 or a == "localhost": |
55 if len(a.split(".")) == 4 or a == "localhost": |
57 ip = a |
56 ip = a |
58 elif o in ("-d", "--directory"): |
57 elif o in ("-d", "--directory"): |
59 # overwrite default working directory |
58 # overwrite default working directory |
60 WorkingDir = a |
59 WorkingDir = a |
93 serviceproperties = {'description':'Remote control for PLC'} |
92 serviceproperties = {'description':'Remote control for PLC'} |
94 |
93 |
95 pyro.initServer() |
94 pyro.initServer() |
96 daemon=pyro.Daemon(host=ip, port=port) |
95 daemon=pyro.Daemon(host=ip, port=port) |
97 uri = daemon.connect(PLCObject(WorkingDir, daemon),"PLCObject") |
96 uri = daemon.connect(PLCObject(WorkingDir, daemon),"PLCObject") |
|
97 |
98 print "The daemon runs on port :",daemon.port |
98 print "The daemon runs on port :",daemon.port |
99 print "The object's uri is :",uri |
99 print "The object's uri is :",uri |
100 print "The working directory :",WorkingDir |
100 print "The working directory :",WorkingDir |
101 print "Publish service on local network" |
|
102 |
101 |
103 ip_32b = socket.inet_aton(ip) |
|
104 # Configure and publish service |
102 # Configure and publish service |
105 service = ServicePublisher.PublishService() |
103 # Not publish service if localhost in address params |
106 service.ConfigureService(type, name, ip_32b, port, serviceproperties) |
104 print ip |
107 service.PublishService() |
105 if ip != "localhost" and ip != "127.0.0.1": |
|
106 # No ip params -> get host ip |
|
107 if ip == "": |
|
108 ip_32b = socket.inet_aton(gethostaddr(ip)) |
|
109 else: |
|
110 ip_32b = ip |
|
111 print "Publish service on local network" |
|
112 service = ServicePublisher.PublishService() |
|
113 service.ConfigureService(type, name, ip_32b, port, serviceproperties) |
|
114 service.PublishService() |
108 |
115 |
109 daemon.requestLoop() |
116 daemon.requestLoop() |