add address ip params
authorgreg
Thu, 21 Aug 2008 13:18:49 +0200
changeset 207 5f4cb3b024cc
parent 206 6b4d58363b80
child 208 dd630979f628
add address ip params
fix configure/publish service
Beremiz_service.py
--- a/Beremiz_service.py	Thu Aug 21 10:35:12 2008 +0200
+++ b/Beremiz_service.py	Thu Aug 21 13:18:49 2008 +0200
@@ -52,7 +52,6 @@
         usage()
         sys.exit()
     elif o in ("-a", "--address"):
-        #ip = socket.inet_aton(a)
         if len(a.split(".")) == 4 or a == "localhost":
             ip = a
     elif o in ("-d", "--directory"):
@@ -95,15 +94,23 @@
 pyro.initServer()
 daemon=pyro.Daemon(host=ip, port=port)
 uri = daemon.connect(PLCObject(WorkingDir, daemon),"PLCObject")
+
 print "The daemon runs on port :",daemon.port
 print "The object's uri is :",uri
 print "The working directory :",WorkingDir
-print "Publish service on local network"
 
-ip_32b = socket.inet_aton(ip)
 # Configure and publish service
-service = ServicePublisher.PublishService()
-service.ConfigureService(type, name, ip_32b, port, serviceproperties)
-service.PublishService()
+# Not publish service if localhost in address params
+print ip
+if ip != "localhost" and ip != "127.0.0.1":    
+    # No ip params -> get host ip
+    if ip == "":
+        ip_32b = socket.inet_aton(gethostaddr(ip))
+    else:
+        ip_32b = ip
+    print "Publish service on local network"
+    service = ServicePublisher.PublishService()
+    service.ConfigureService(type, name, ip_32b, port, serviceproperties)
+    service.PublishService()
 
 daemon.requestLoop()