Make Beremiz_service print version information
authorAndrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 20 Aug 2018 17:11:20 +0300
changeset 2294 da288f63612f
parent 2293 9c6b0109c43f
child 2295 dda34e671700
Make Beremiz_service print version information

Add support for long options '--help' and '--version' as
is recommended by GNU Coding Standards.
Beremiz_service.py
runtime_files.list
--- a/Beremiz_service.py	Mon Aug 20 16:46:50 2018 +0300
+++ b/Beremiz_service.py	Mon Aug 20 17:11:20 2018 +0300
@@ -41,7 +41,13 @@
 import util.paths as paths
 
 
+def version():
+    from version import app_version
+    print("Beremiz_service: ", app_version)
+
+
 def usage():
+    version()
     print("""
 Usage of Beremiz PLC execution service :\n
 %s {[-n servicename] [-i IP] [-p port] [-x enabletaskbar] [-a autostart]|-h|--help} working_dir
@@ -62,7 +68,7 @@
 
 
 try:
-    opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:s:h")
+    opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:w:c:e:s:h", ["help", "version"])
 except getopt.GetoptError, err:
     # print help information and exit:
     print(str(err))  # will print something like "option -a not recognized"
@@ -85,9 +91,12 @@
 extensions = []
 
 for o, a in opts:
-    if o == "-h":
+    if o == "-h" or o == "--help":
         usage()
         sys.exit()
+    if o == "--version":
+        version()
+        sys.exit()
     elif o == "-i":
         if len(a.split(".")) == 4 or a == "localhost":
             given_ip = a
@@ -136,6 +145,7 @@
     __builtin__.__dict__['_'] = lambda x: x
     # TODO: add a cmdline parameter if Trying Preloading Xenomai makes problem
     TryPreloadXenomai()
+    version()
 
 
 def Bpath(*args):
--- a/runtime_files.list	Mon Aug 20 16:46:50 2018 +0300
+++ b/runtime_files.list	Mon Aug 20 17:11:20 2018 +0300
@@ -15,3 +15,4 @@
 runtime/typemapping.py 
 runtime/loglevels.py 
 Beremiz_service.py
+version.py
\ No newline at end of file