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
This commit is contained in:
parent
fd22cf011d
commit
a280080563
2 changed files with 356 additions and 31 deletions
|
|
@ -75,3 +75,6 @@ class BridgeInitError(Exception):
|
|||
|
||||
class BridgeExceptionNoService(Exception):
|
||||
pass
|
||||
|
||||
class DatabaseError(Exception):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -82,15 +82,19 @@ class AbortSendMessage(Exception):
|
|||
|
||||
class SAT(service.Service):
|
||||
|
||||
@property
|
||||
def __version__(self):
|
||||
return self.getConst('client_version')
|
||||
|
||||
def get_next_id(self):
|
||||
return sat_next_id()
|
||||
|
||||
def get_const(self, name):
|
||||
def getConst(self, name):
|
||||
"""Return a constant"""
|
||||
try:
|
||||
_const = os.environ['SAT_CONST_%s' % name]
|
||||
if _const:
|
||||
debug(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
|
||||
warning(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
|
||||
return _const
|
||||
except KeyError:
|
||||
pass
|
||||
|
|
@ -99,7 +103,7 @@ class SAT(service.Service):
|
|||
raise Exception
|
||||
return CONST[name]
|
||||
|
||||
def set_const(self, name, value):
|
||||
def setConst(self, name, value):
|
||||
"""Save a constant"""
|
||||
if name in CONST:
|
||||
error(_('Trying to redefine a constant'))
|
||||
|
|
@ -126,7 +130,7 @@ class SAT(service.Service):
|
|||
except exceptions.BridgeInitError:
|
||||
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
|
||||
sys.exit(1)
|
||||
self.bridge.register("getVersion", lambda: self.get_const('client_version'))
|
||||
self.bridge.register("getVersion", lambda: self.getConst('client_version'))
|
||||
self.bridge.register("getProfileName", self.memory.getProfileName)
|
||||
self.bridge.register("getProfilesList", self.memory.getProfilesList)
|
||||
self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
|
||||
|
|
@ -269,8 +273,8 @@ class SAT(service.Service):
|
|||
current.fallBack = xmpp.SatFallbackHandler(self)
|
||||
current.fallBack.setHandlerParent(current)
|
||||
|
||||
current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
|
||||
self.get_const('client_version'))
|
||||
current.versionHandler = xmpp.SatVersionHandler(self.getConst('client_name'),
|
||||
self.getConst('client_version'))
|
||||
current.versionHandler.setHandlerParent(current)
|
||||
|
||||
current.identityHandler = xmpp.SatIdentityHandler()
|
||||
|
|
|
|||
Loading…
Reference in a new issue