Mercurial > libervia-web
diff libervia.tac @ 317:bbadd490e63c
misc: gather the constants in a single file, as it is done for other frontends
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 03 Jan 2014 14:14:34 +0100 |
parents | 05e264e96a1c |
children | c12c9a1acf2f |
line wrap: on
line diff
--- a/libervia.tac Fri Jan 03 13:33:44 2014 +0100 +++ b/libervia.tac Fri Jan 03 14:14:34 2014 +0100 @@ -41,21 +41,8 @@ from server_side.blog import MicroBlog from zope.interface import Interface, Attribute, implements from xml.dom import minidom -from sat_frontends.constants import Const - -#import time +from constants import Const -TIMEOUT = 300 #Session's time out, after that the user will be disconnected -LIBERVIA_DIR = "output/" -MEDIA_DIR = "media/" -AVATARS_DIR = "avatars/" -CARDS_DIR = "games/cards/tarot" - -ERRNUM_BRIDGE_ERRBACK = 0 # FIXME -ERRNUM_LIBERVIA = 0 # FIXME - -# Security limit for Libervia (get/set params) -SECURITY_LIMIT = 0 class ISATSession(Interface): profile = Attribute("Sat profile") @@ -68,7 +55,7 @@ self.jid = None class LiberviaSession(server.Session): - sessionTimeout = TIMEOUT + sessionTimeout = Const.TIMEOUT def __init__(self, *args, **kwargs): self.__lock = False @@ -149,7 +136,7 @@ d.callback(args[0]) def _errback(result): - d.errback(Failure(jsonrpclib.Fault(ERRNUM_BRIDGE_ERRBACK, unicode(result)))) + d.errback(Failure(jsonrpclib.Fault(Const.ERRNUM_BRIDGE_ERRBACK, unicode(result)))) kwargs["callback"] = _callback kwargs["errback"] = _errback @@ -169,7 +156,7 @@ if not profile: #user is not identified, we return a jsonrpc fault parsed = jsonrpclib.loads(request.content.read()) - fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) return jsonrpc.JSONRPC.render(self, request) @@ -406,7 +393,7 @@ """Give the path of all the tarot cards""" _join = os.path.join _media_dir = _join(self.sat_host.media_dir,'') - return map(lambda x: _join(MEDIA_DIR, x[len(_media_dir):]),glob.glob(_join(_media_dir,CARDS_DIR,'*_*.png'))); + return map(lambda x: _join(Const.MEDIA_DIR, x[len(_media_dir):]), glob.glob(_join(_media_dir, Const.CARDS_DIR, '*_*.png'))); def jsonrpc_tarotGameReady(self, player, referee): """Tell to the server that we are ready to start the game""" @@ -454,7 +441,7 @@ def jsonrpc_getParamsUI(self): """Return the parameters XML for profile""" profile = ISATSession(self.session).profile - d = self.asyncBridgeCall("getParams", SECURITY_LIMIT, profile) + d = self.asyncBridgeCall("getParams", Const.SECURITY_LIMIT, profile) def setAuthorizedParams(d): if self.authorized_params is None: @@ -478,13 +465,13 @@ def jsonrpc_asyncGetParamA(self, param, category, attribute="value"): """Return the parameter value for profile""" profile = ISATSession(self.session).profile - d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, SECURITY_LIMIT, profile_key=profile) + d = self.asyncBridgeCall("asyncGetParamA", param, category, attribute, Const.SECURITY_LIMIT, profile_key=profile) return d def jsonrpc_setParam(self, name, value, category): profile = ISATSession(self.session).profile if category in self.authorized_params and name in self.authorized_params[category]: - return self.sat_host.bridge.setParam(name, value, category, SECURITY_LIMIT, profile) + return self.sat_host.bridge.setParam(name, value, category, Const.SECURITY_LIMIT, profile) else: warning("Trying to set parameter '%s' in category '%s' without authorization!!!" % (name, category)) @@ -554,7 +541,7 @@ profile = ISATSession(_session).profile if not profile: #user is not identified, we return a jsonrpc fault - fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) self.request = request return jsonrpc.JSONRPC.render(self, request) @@ -825,7 +812,7 @@ profile = ISATSession(_session).profile if not profile: #user is not identified, we return a jsonrpc fault - fault = jsonrpclib.Fault(ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia + fault = jsonrpclib.Fault(Const.ERRNUM_LIBERVIA, "Not allowed") #FIXME: define some standard error codes for libervia return jsonrpc.JSONRPC._cbRender(self, fault, request, parsed.get('id'), parsed.get('jsonrpc')) self.request = request return jsonrpc.JSONRPC.render(self, request) @@ -925,7 +912,7 @@ def __init__(self): self._cleanup = [] - root = ProtectedFile(LIBERVIA_DIR) + root = ProtectedFile(Const.LIBERVIA_DIR) self.signal_handler = SignalHandler(self) _register = Register(self) _upload_radiocol = UploadManagerRadioCol(self) @@ -963,8 +950,8 @@ root.putChild('upload_avatar', _upload_avatar) root.putChild('blog', MicroBlog(self)) root.putChild('css', ProtectedFile("server_css/")) - root.putChild(os.path.dirname(MEDIA_DIR), ProtectedFile(self.media_dir)) - root.putChild(os.path.dirname(AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, AVATARS_DIR))) + root.putChild(os.path.dirname(Const.MEDIA_DIR), ProtectedFile(self.media_dir)) + root.putChild(os.path.dirname(Const.AVATARS_DIR), ProtectedFile(os.path.join(self.local_dir, Const.AVATARS_DIR))) root.putChild('radiocol', ProtectedFile(_upload_radiocol.getTmpDir(), defaultType="audio/ogg")) #We cheat for PoC because we know we are on the same host, so we use directly upload dir self.site = server.Site(root) self.site.sessionFactory = LiberviaSession @@ -993,6 +980,6 @@ registerAdapter(SATSession, server.Session, ISATSession) -application = service.Application('Libervia') +application = service.Application(Const.APP_NAME) service = Libervia() service.setServiceParent(application)