Mercurial > libervia-backend
comparison sat/memory/memory.py @ 3537:f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 03 Jun 2021 15:20:47 +0200 |
parents | 30779935c0aa |
children | 888109774673 |
comparison
equal
deleted
inserted
replaced
3536:0985c47ffd96 | 3537:f9a5b810f14d |
---|---|
31 from twisted.words.protocols.jabber import jid | 31 from twisted.words.protocols.jabber import jid |
32 from sat.core.i18n import _ | 32 from sat.core.i18n import _ |
33 from sat.core.log import getLogger | 33 from sat.core.log import getLogger |
34 from sat.core import exceptions | 34 from sat.core import exceptions |
35 from sat.core.constants import Const as C | 35 from sat.core.constants import Const as C |
36 from sat.memory.sqlite import SqliteStorage | 36 from sat.memory.sqla import Storage |
37 from sat.memory.persistent import PersistentDict | 37 from sat.memory.persistent import PersistentDict |
38 from sat.memory.params import Params | 38 from sat.memory.params import Params |
39 from sat.memory.disco import Discovery | 39 from sat.memory.disco import Discovery |
40 from sat.memory.crypto import BlockCipher | 40 from sat.memory.crypto import BlockCipher |
41 from sat.memory.crypto import PasswordHasher | 41 from sat.memory.crypto import PasswordHasher |
226 class Memory(object): | 226 class Memory(object): |
227 """This class manage all the persistent information""" | 227 """This class manage all the persistent information""" |
228 | 228 |
229 def __init__(self, host): | 229 def __init__(self, host): |
230 log.info(_("Memory manager init")) | 230 log.info(_("Memory manager init")) |
231 self.initialized = defer.Deferred() | |
232 self.host = host | 231 self.host = host |
233 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache | 232 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache |
234 # /!\ an entity is not necessarily in roster | 233 # /!\ an entity is not necessarily in roster |
235 # main key is bare jid, value is a dict | 234 # main key is bare jid, value is a dict |
236 # where main key is resource, or None for bare jid | 235 # where main key is resource, or None for bare jid |
238 self.subscriptions = {} | 237 self.subscriptions = {} |
239 self.auth_sessions = PasswordSessions() # remember the authenticated profiles | 238 self.auth_sessions = PasswordSessions() # remember the authenticated profiles |
240 self.disco = Discovery(host) | 239 self.disco = Discovery(host) |
241 self.config = tools_config.parseMainConf(log_filenames=True) | 240 self.config = tools_config.parseMainConf(log_filenames=True) |
242 self._cache_path = Path(self.getConfig("", "local_dir"), C.CACHE_DIR) | 241 self._cache_path = Path(self.getConfig("", "local_dir"), C.CACHE_DIR) |
242 | |
243 async def initialise(self): | |
243 database_file = os.path.expanduser( | 244 database_file = os.path.expanduser( |
244 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) | 245 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) |
245 ) | 246 ) |
246 self.storage = SqliteStorage(database_file, host.version) | 247 self.storage = Storage(database_file, self.host.version) |
248 await self.storage.initialise() | |
247 PersistentDict.storage = self.storage | 249 PersistentDict.storage = self.storage |
248 self.params = Params(host, self.storage) | 250 self.params = Params(self.host, self.storage) |
249 log.info(_("Loading default params template")) | 251 log.info(_("Loading default params template")) |
250 self.params.load_default_params() | 252 self.params.load_default_params() |
251 d = self.storage.initialized.addCallback(lambda ignore: self.load()) | 253 await self.load() |
252 self.memory_data = PersistentDict("memory") | 254 self.memory_data = PersistentDict("memory") |
253 d.addCallback(lambda ignore: self.memory_data.load()) | 255 await self.memory_data.load() |
254 d.addCallback(lambda ignore: self.disco.load()) | 256 await self.disco.load() |
255 d.chainDeferred(self.initialized) | 257 |
256 | 258 |
257 ## Configuration ## | 259 ## Configuration ## |
258 | 260 |
259 def getConfig(self, section, name, default=None): | 261 def getConfig(self, section, name, default=None): |
260 """Get the main configuration option | 262 """Get the main configuration option |