changeset 856:fd438e51bda8

server: version check: - added C.APP_VERSIOn to server/constants, to override value from sat.core.constants, this allow checking version mismatch - libervia.__version__ is set - in case of version mismatch with sat module version, an error message is printend and execution is stopped
author Goffi <goffi@goffi.org>
date Sun, 24 Jan 2016 18:45:35 +0100
parents de17f7313cbe
children e17b15f1f260
files src/__init__.py src/server/constants.py src/server/server.py src/twisted/plugins/libervia_server.py
diffstat 4 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/__init__.py	Fri Jan 22 20:22:30 2016 +0100
+++ b/src/__init__.py	Sun Jan 24 18:45:35 2016 +0100
@@ -0,0 +1,3 @@
+from server.constants import Const as C
+
+__version__ = C.APP_VERSION
--- a/src/server/constants.py	Fri Jan 22 20:22:30 2016 +0100
+++ b/src/server/constants.py	Sun Jan 24 18:45:35 2016 +0100
@@ -28,6 +28,9 @@
 
     APP_NAME = 'Libervia'
     APP_NAME_FILE = "libervia"
+    # XXX: we don't want to use the APP_VERSION inherited from sat.core.constants version
+    #      as we use this version to check that there is not a mismatch with backend
+    APP_VERSION = u'0.6.0D'  # Please add 'D' at the end for dev versions
     SERVICE_PROFILE = 'libervia'  # the SàT profile that is used for exporting the service
 
     SESSION_TIMEOUT = 300  # Session's timeout, after that the user will be disconnected
--- a/src/server/server.py	Fri Jan 22 20:22:30 2016 +0100
+++ b/src/server/server.py	Sun Jan 24 18:45:35 2016 +0100
@@ -60,7 +60,6 @@
 
 # following value are set from twisted.plugins.libervia_server initialise (see the comment there)
 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None
-__version__ = C.APP_VERSION
 
 
 class ISATSession(Interface):
--- a/src/twisted/plugins/libervia_server.py	Fri Jan 22 20:22:30 2016 +0100
+++ b/src/twisted/plugins/libervia_server.py	Sun Jan 24 18:45:35 2016 +0100
@@ -31,6 +31,8 @@
         pass
 
 import os.path
+import libervia
+import sat
 
 from libervia.server.constants import Const as C
 
@@ -46,6 +48,25 @@
 
 
 CONFIG_SECTION = C.APP_NAME.lower()
+if libervia.__version__ != sat.__version__:
+    import sys
+    sys.stderr.write(u"""sat module version ({sat_version}) and {current_app} version ({current_version}) mismatch
+
+sat module is located at {sat_path}
+libervia module is located at {libervia_path}
+
+Please be sure to have the same version running
+""".format(
+        sat_version = sat.__version__,
+        current_app = C.APP_NAME,
+        current_version = libervia.__version__,
+        sat_path = os.path.dirname(sat.__file__),
+        libervia_path = os.path.dirname(libervia.__file__),
+        ).encode('utf-8'))
+    sys.stderr.flush()
+    # we call os._exit to avoid help to be printed by twisted
+    import os
+    os._exit(1)
 
 
 def coerceConnectionType(value):  # called from Libervia.OPT_PARAMETERS