comparison src/core/sat_main.py @ 923:e77948faaef3

core: removed default_config: - constants in core.default_config moved to core.constants - removed unused host.getConst and host.setConst - APP_NAME* used where it make sense
author Goffi <goffi@goffi.org>
date Sat, 22 Mar 2014 17:48:10 +0100
parents c897c8d321b3
children 5c78cefd233f
comparison
equal deleted inserted replaced
922:c897c8d321b3 923:e77948faaef3
34 from logging import debug, info, warning, error 34 from logging import debug, info, warning, error
35 35
36 import sys 36 import sys
37 import os.path 37 import os.path
38 38
39 from sat.core.default_config import CONST
40 from sat.core import xmpp 39 from sat.core import xmpp
41 from sat.core import exceptions 40 from sat.core import exceptions
42 from sat.core.constants import Const as C 41 from sat.core.constants import Const as C
43 from sat.memory.memory import Memory 42 from sat.memory.memory import Memory
44 from sat.tools.xml_tools import tupleList2dataForm 43 from sat.tools.xml_tools import tupleList2dataForm
83 82
84 class SAT(service.Service): 83 class SAT(service.Service):
85 84
86 @property 85 @property
87 def __version__(self): 86 def __version__(self):
88 return self.getConst('client_version') 87 return C.APP_VERSION
89 88
90 def get_next_id(self): 89 def get_next_id(self):
91 return sat_next_id() 90 return sat_next_id()
92
93 def getConst(self, name):
94 """Return a constant"""
95 try:
96 _const = os.environ['SAT_CONST_%s' % name]
97 if _const:
98 warning(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
99 return _const
100 except KeyError:
101 pass
102 if name not in CONST:
103 error(_('Trying to access an undefined constant'))
104 raise Exception
105 return CONST[name]
106
107 def setConst(self, name, value):
108 """Save a constant"""
109 if name in CONST:
110 error(_('Trying to redefine a constant'))
111 raise Exception
112 CONST[name] = value
113 91
114 def __init__(self): 92 def __init__(self):
115 self._cb_map = {} # map from callback_id to callbacks 93 self._cb_map = {} # map from callback_id to callbacks
116 self._menus = {} # dynamic menus. key: callback_id, value: menu data (dictionnary) 94 self._menus = {} # dynamic menus. key: callback_id, value: menu data (dictionnary)
117 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed 95 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed
129 try: 107 try:
130 self.bridge = DBusBridge() 108 self.bridge = DBusBridge()
131 except exceptions.BridgeInitError: 109 except exceptions.BridgeInitError:
132 print (u"Bridge can't be initialised, can't start SàT core") # reactor is not launched yet, so we can't use error log 110 print (u"Bridge can't be initialised, can't start SàT core") # reactor is not launched yet, so we can't use error log
133 sys.exit(1) 111 sys.exit(1)
134 self.bridge.register("getVersion", lambda: self.getConst('client_version')) 112 self.bridge.register("getVersion", lambda: C.APP_VERSION)
135 self.bridge.register("getProfileName", self.memory.getProfileName) 113 self.bridge.register("getProfileName", self.memory.getProfileName)
136 self.bridge.register("getProfilesList", self.memory.getProfilesList) 114 self.bridge.register("getProfilesList", self.memory.getProfilesList)
137 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) 115 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
138 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) 116 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
139 self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile) 117 self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile)
271 current.presence.setHandlerParent(current) 249 current.presence.setHandlerParent(current)
272 250
273 current.fallBack = xmpp.SatFallbackHandler(self) 251 current.fallBack = xmpp.SatFallbackHandler(self)
274 current.fallBack.setHandlerParent(current) 252 current.fallBack.setHandlerParent(current)
275 253
276 current.versionHandler = xmpp.SatVersionHandler(self.getConst('client_name'), 254 current.versionHandler = xmpp.SatVersionHandler(C.APP_NAME_FULL,
277 self.getConst('client_version')) 255 C.APP_VERSION)
278 current.versionHandler.setHandlerParent(current) 256 current.versionHandler.setHandlerParent(current)
279 257
280 current.identityHandler = xmpp.SatIdentityHandler() 258 current.identityHandler = xmpp.SatIdentityHandler()
281 current.identityHandler.setHandlerParent(current) 259 current.identityHandler.setHandlerParent(current)
282 260