changeset 682:e6bb64bd6b4d

server side: implemented methods to get SàT and Libervia versions
author Goffi <goffi@goffi.org>
date Thu, 19 Mar 2015 20:41:14 +0100
parents 3b185ccb70b4
children 801eb94aa869
files src/server/server.py
diffstat 1 files changed, 36 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/server/server.py	Thu Mar 19 17:27:22 2015 +0100
+++ b/src/server/server.py	Thu Mar 19 20:41:14 2015 +0100
@@ -36,6 +36,7 @@
 from sat.core.i18n import _, D_
 from sat.core import exceptions
 from sat.tools.xml_tools import paramsXML2XMLUI
+from sat.tools import utils
 
 import re
 import glob
@@ -47,6 +48,7 @@
 from zope.interface import Interface, Attribute, implements
 from xml.dom import minidom
 from httplib import HTTPS_PORT
+import libervia
 
 try:
     import OpenSSL
@@ -58,8 +60,11 @@
 from libervia.server.constants import Const as C
 from libervia.server.blog import MicroBlog
 
+
 # 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):
     profile = Attribute("Sat profile")
@@ -185,6 +190,18 @@
             return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc'))  # pylint: disable=E1103
         return jsonrpc.JSONRPC.render(self, request)
 
+    def jsonrpc_getVersion(self):
+        """Return SàT version"""
+        try:
+            return self._version_cache
+        except AttributeError:
+            self._version_cache = self.sat_host.bridge.getVersion()
+            return self._version_cache
+
+    def jsonrpc_getLiberviaVersion(self):
+        """Return Libervia version"""
+        return self.sat_host.full_version
+
     def jsonrpc_disconnect(self):
         """Disconnect the profile"""
         sat_session = ISATSession(self.session)
@@ -1119,6 +1136,25 @@
         self.initialised.addCallback(backendReady)
         self.initialised.addErrback(lambda failure: log.error("Init error: %s" % failure))
 
+    @property
+    def version(self):
+        """Return the short version of Libervia"""
+        return C.APP_VERSION
+
+    @property
+    def full_version(self):
+        """Return the full version of Libervia (with extra data when in development mode)"""
+        version = self.version
+        if version[-1] == 'D':
+            # we are in debug version, we add extra data
+            try:
+                return self._version_cache
+            except AttributeError:
+                self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(libervia))
+                return self._version_cache
+        else:
+            return version
+
     def addCleanup(self, callback, *args, **kwargs):
         """Add cleaning method to call when service is stopped
         cleaning method will be called in reverse order of they insertion