Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
authorEdouard Tisserant
Mon, 02 Feb 2015 23:45:30 +0100
changeset 1437 04177743b066
parent 1436 e15ca67197b9
child 1438 19ebe96b41c0
Added Beremiz_service.py command line switch to load python extention for runtime independently from PLC program
Beremiz_service.py
--- a/Beremiz_service.py	Mon Feb 02 23:11:01 2015 +0100
+++ b/Beremiz_service.py	Mon Feb 02 23:45:30 2015 +0100
@@ -36,12 +36,13 @@
            -a        - autostart PLC (0:disable 1:enable) (default:0)
            -x        - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1)
            -t        - enable/disable Twisted web interface (0:disable 1:enable) (default:1)
+           -e        - python extension (absolute path .py)
 
            working_dir - directory where are stored PLC files
 """%sys.argv[0]
 
 try:
-    opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:h")
+    opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:e:h")
 except getopt.GetoptError, err:
     # print help information and exit:
     print str(err) # will print something like "option -a not recognized"
@@ -58,6 +59,8 @@
 enabletwisted = True
 havetwisted = False
 
+extensions=[]
+
 for o, a in opts:
     if o == "-h":
         usage()
@@ -79,6 +82,8 @@
         enabletwisted = int(a)
     elif o == "-a":
         autostart = int(a)
+    elif o == "-e":
+        extensions.append(a)
     else:
         usage()
         sys.exit()
@@ -632,6 +637,12 @@
     threading.Thread.__init__ = init
 installThreadExcepthook()
 
+# Load extensions
+for extfilename in extensions:
+    extension_folder = os.path.split(os.path.realpath(extfilename))[0]
+    sys.path.append(extension_folder)
+    execfile(extfilename, locals())
+
 if havetwisted or havewx:
     pyro_thread=Thread(target=pyroserver.Loop)
     pyro_thread.start()