comparison src/core/sat_main.py @ 853:c2f6ada7858f

core (sqlite): automatic database update: - new Updater class check database consistency (by calculating a hash on the .schema), and updates base if necessary - database now has a version (1 for current, 0 will be for 0.3's database), for each change this version will be increased - creation statements and update statements are in the form of dict of dict with tuples. There is a help text at the top of the module to explain how it works - if we are on a development version, the updater try to update the database automaticaly (without deleting table or columns). The Updater.generateUpdateData method can be used to ease the creation of update data (i.e. the dictionary at the top, see the one for the key 1 for an example). - if there is an inconsistency, an exception is raised, and a message indicate the SQL statements that should fix the situation. - well... this is rather complicated, a KISS method would maybe have been better. The future will say if we need to simplify it :-/ - new DatabaseError exception
author Goffi <goffi@goffi.org>
date Sun, 23 Feb 2014 23:30:32 +0100
parents 59d486726577
children 308a96bc7c1b
comparison
equal deleted inserted replaced
852:4cc55e05266d 853:c2f6ada7858f
80 pass 80 pass
81 81
82 82
83 class SAT(service.Service): 83 class SAT(service.Service):
84 84
85 @property
86 def __version__(self):
87 return self.getConst('client_version')
88
85 def get_next_id(self): 89 def get_next_id(self):
86 return sat_next_id() 90 return sat_next_id()
87 91
88 def get_const(self, name): 92 def getConst(self, name):
89 """Return a constant""" 93 """Return a constant"""
90 try: 94 try:
91 _const = os.environ['SAT_CONST_%s' % name] 95 _const = os.environ['SAT_CONST_%s' % name]
92 if _const: 96 if _const:
93 debug(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const}) 97 warning(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
94 return _const 98 return _const
95 except KeyError: 99 except KeyError:
96 pass 100 pass
97 if name not in CONST: 101 if name not in CONST:
98 error(_('Trying to access an undefined constant')) 102 error(_('Trying to access an undefined constant'))
99 raise Exception 103 raise Exception
100 return CONST[name] 104 return CONST[name]
101 105
102 def set_const(self, name, value): 106 def setConst(self, name, value):
103 """Save a constant""" 107 """Save a constant"""
104 if name in CONST: 108 if name in CONST:
105 error(_('Trying to redefine a constant')) 109 error(_('Trying to redefine a constant'))
106 raise Exception 110 raise Exception
107 CONST[name] = value 111 CONST[name] = value
124 try: 128 try:
125 self.bridge = DBusBridge() 129 self.bridge = DBusBridge()
126 except exceptions.BridgeInitError: 130 except exceptions.BridgeInitError:
127 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 131 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
128 sys.exit(1) 132 sys.exit(1)
129 self.bridge.register("getVersion", lambda: self.get_const('client_version')) 133 self.bridge.register("getVersion", lambda: self.getConst('client_version'))
130 self.bridge.register("getProfileName", self.memory.getProfileName) 134 self.bridge.register("getProfileName", self.memory.getProfileName)
131 self.bridge.register("getProfilesList", self.memory.getProfilesList) 135 self.bridge.register("getProfilesList", self.memory.getProfilesList)
132 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) 136 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
133 self.bridge.register("createProfile", self.memory.createProfile) 137 self.bridge.register("createProfile", self.memory.createProfile)
134 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) 138 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
267 current.presence.setHandlerParent(current) 271 current.presence.setHandlerParent(current)
268 272
269 current.fallBack = xmpp.SatFallbackHandler(self) 273 current.fallBack = xmpp.SatFallbackHandler(self)
270 current.fallBack.setHandlerParent(current) 274 current.fallBack.setHandlerParent(current)
271 275
272 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'), 276 current.versionHandler = xmpp.SatVersionHandler(self.getConst('client_name'),
273 self.get_const('client_version')) 277 self.getConst('client_version'))
274 current.versionHandler.setHandlerParent(current) 278 current.versionHandler.setHandlerParent(current)
275 279
276 current.identityHandler = xmpp.SatIdentityHandler() 280 current.identityHandler = xmpp.SatIdentityHandler()
277 current.identityHandler.setHandlerParent(current) 281 current.identityHandler.setHandlerParent(current)
278 282