Fixed oddities in arguments/options parsing and passing to plugins initialization...
authoretisserant
Thu, 21 Aug 2008 17:18:44 +0200
changeset 210 ca3bfcf61192
parent 209 08dc3d064cb5
child 211 12b23ec6e6ed
Fixed oddities in arguments/options parsing and passing to plugins initialization...
Beremiz_service.py
--- a/Beremiz_service.py	Thu Aug 21 17:17:36 2008 +0200
+++ b/Beremiz_service.py	Thu Aug 21 17:18:44 2008 +0200
@@ -35,7 +35,7 @@
 """%sys.argv[0]
 
 try:
-    opts, args = getopt.getopt(sys.argv[1:], "a:d:p:h", ["directory=", "port=", "help"])
+    opts, args = getopt.getopt(sys.argv[1:], "a:p:h", ["help"])
 except getopt.GetoptError, err:
     # print help information and exit:
     print str(err) # will print something like "option -a not recognized"
@@ -43,10 +43,9 @@
     sys.exit(2)
 
 # default values
-WorkingDir = os.getcwd()
 ip = ""
 port = 3000
-
+print opts
 for o, a in opts:
     if o in ("-h", "--help"):
         usage()
@@ -54,9 +53,6 @@
     elif o in ("-a", "--address"):
         if len(a.split(".")) == 4 or a == "localhost":
             ip = a
-    elif o in ("-d", "--directory"):
-        # overwrite default working directory
-        WorkingDir = a
     elif o in ("-p", "--port"):
         # port: port that the service runs on
         port = int(a)
@@ -64,6 +60,17 @@
         usage()
         sys.exit()
 
+if len(args) > 1:
+    usage()
+    sys.exit()
+elif len(args) == 1:
+    WorkingDir = args[0]
+elif len(args) == 0:
+    WorkingDir = os.getcwd()
+else:
+    usage()
+    sys.exit()
+
 from runtime import PLCObject, ServicePublisher
 import Pyro.core as pyro
 
@@ -93,7 +100,7 @@
 
 pyro.initServer()
 daemon=pyro.Daemon(host=ip, port=port)
-uri = daemon.connect(PLCObject(WorkingDir, daemon),"PLCObject")
+uri = daemon.connect(PLCObject(WorkingDir, daemon, args),"PLCObject")
 
 print "The daemon runs on port :",daemon.port
 print "The object's uri is :",uri