comparison src/server/server.py @ 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 a90cc8fc9605
children 9877607c719a
comparison
equal deleted inserted replaced
681:3b185ccb70b4 682:e6bb64bd6b4d
34 log = getLogger(__name__) 34 log = getLogger(__name__)
35 from sat_frontends.bridge.DBus import DBusBridgeFrontend, BridgeExceptionNoService, const_TIMEOUT as BRIDGE_TIMEOUT 35 from sat_frontends.bridge.DBus import DBusBridgeFrontend, BridgeExceptionNoService, const_TIMEOUT as BRIDGE_TIMEOUT
36 from sat.core.i18n import _, D_ 36 from sat.core.i18n import _, D_
37 from sat.core import exceptions 37 from sat.core import exceptions
38 from sat.tools.xml_tools import paramsXML2XMLUI 38 from sat.tools.xml_tools import paramsXML2XMLUI
39 from sat.tools import utils
39 40
40 import re 41 import re
41 import glob 42 import glob
42 import os.path 43 import os.path
43 import sys 44 import sys
45 import shutil 46 import shutil
46 import uuid 47 import uuid
47 from zope.interface import Interface, Attribute, implements 48 from zope.interface import Interface, Attribute, implements
48 from xml.dom import minidom 49 from xml.dom import minidom
49 from httplib import HTTPS_PORT 50 from httplib import HTTPS_PORT
51 import libervia
50 52
51 try: 53 try:
52 import OpenSSL 54 import OpenSSL
53 from twisted.internet import ssl 55 from twisted.internet import ssl
54 ssl_available = True 56 ssl_available = True
56 ssl_available = False 58 ssl_available = False
57 59
58 from libervia.server.constants import Const as C 60 from libervia.server.constants import Const as C
59 from libervia.server.blog import MicroBlog 61 from libervia.server.blog import MicroBlog
60 62
63
61 # following value are set from twisted.plugins.libervia_server initialise (see the comment there) 64 # following value are set from twisted.plugins.libervia_server initialise (see the comment there)
62 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None 65 DATA_DIR_DEFAULT = OPT_PARAMETERS_BOTH = OPT_PARAMETERS_CFG = coerceDataDir = None
66 __version__ = C.APP_VERSION
67
63 68
64 class ISATSession(Interface): 69 class ISATSession(Interface):
65 profile = Attribute("Sat profile") 70 profile = Attribute("Sat profile")
66 jid = Attribute("JID associated with the profile") 71 jid = Attribute("JID associated with the profile")
67 72
182 #user is not identified, we return a jsonrpc fault 187 #user is not identified, we return a jsonrpc fault
183 parsed = jsonrpclib.loads(request.content.read()) 188 parsed = jsonrpclib.loads(request.content.read())
184 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia 189 fault = jsonrpclib.Fault(C.ERRNUM_LIBERVIA, C.NOT_ALLOWED) # FIXME: define some standard error codes for libervia
185 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103 190 return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) # pylint: disable=E1103
186 return jsonrpc.JSONRPC.render(self, request) 191 return jsonrpc.JSONRPC.render(self, request)
192
193 def jsonrpc_getVersion(self):
194 """Return SàT version"""
195 try:
196 return self._version_cache
197 except AttributeError:
198 self._version_cache = self.sat_host.bridge.getVersion()
199 return self._version_cache
200
201 def jsonrpc_getLiberviaVersion(self):
202 """Return Libervia version"""
203 return self.sat_host.full_version
187 204
188 def jsonrpc_disconnect(self): 205 def jsonrpc_disconnect(self):
189 """Disconnect the profile""" 206 """Disconnect the profile"""
190 sat_session = ISATSession(self.session) 207 sat_session = ISATSession(self.session)
191 profile = sat_session.profile 208 profile = sat_session.profile
1116 1133
1117 self.bridge.getReady(lambda: self.initialised.callback(None), 1134 self.bridge.getReady(lambda: self.initialised.callback(None),
1118 lambda failure: self.initialised.errback(Exception(failure))) 1135 lambda failure: self.initialised.errback(Exception(failure)))
1119 self.initialised.addCallback(backendReady) 1136 self.initialised.addCallback(backendReady)
1120 self.initialised.addErrback(lambda failure: log.error("Init error: %s" % failure)) 1137 self.initialised.addErrback(lambda failure: log.error("Init error: %s" % failure))
1138
1139 @property
1140 def version(self):
1141 """Return the short version of Libervia"""
1142 return C.APP_VERSION
1143
1144 @property
1145 def full_version(self):
1146 """Return the full version of Libervia (with extra data when in development mode)"""
1147 version = self.version
1148 if version[-1] == 'D':
1149 # we are in debug version, we add extra data
1150 try:
1151 return self._version_cache
1152 except AttributeError:
1153 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(libervia))
1154 return self._version_cache
1155 else:
1156 return version
1121 1157
1122 def addCleanup(self, callback, *args, **kwargs): 1158 def addCleanup(self, callback, *args, **kwargs):
1123 """Add cleaning method to call when service is stopped 1159 """Add cleaning method to call when service is stopped
1124 cleaning method will be called in reverse order of they insertion 1160 cleaning method will be called in reverse order of they insertion
1125 @param callback: callable to call on service stop 1161 @param callback: callable to call on service stop