comparison sat/memory/memory.py @ 3053:8b36e5c3f28f

misc: don't import memory in launch script: launch script was importing a method from memory (fixLocalDir), but memory is importing twisted.internet.reactor which can result to a ReactorAlreadyInstalledError. This patch fixes it by moving fixLocalDir to tools/config. The launch script is now using /usr/bin/env.
author Goffi <goffi@goffi.org>
date Tue, 08 Oct 2019 12:10:26 +0200
parents fee60f17ebac
children 130f9cb6e0ab
comparison
equal deleted inserted replaced
3052:60a63723ecea 3053:8b36e5c3f28f
24 log = getLogger(__name__) 24 log = getLogger(__name__)
25 25
26 import os.path 26 import os.path
27 import copy 27 import copy
28 from collections import namedtuple 28 from collections import namedtuple
29 from configparser import ConfigParser, NoOptionError, NoSectionError
30 from uuid import uuid4 29 from uuid import uuid4
31 from twisted.python import failure 30 from twisted.python import failure
32 from twisted.internet import defer, reactor, error 31 from twisted.internet import defer, reactor, error
33 from twisted.words.protocols.jabber import jid 32 from twisted.words.protocols.jabber import jid
34 from sat.core import exceptions 33 from sat.core import exceptions
219 log.debug( 218 log.debug(
220 "FIXME: PasswordSessions should ask for the profile password after the session expired" 219 "FIXME: PasswordSessions should ask for the profile password after the session expired"
221 ) 220 )
222 221
223 222
224 # XXX: tmp update code, will be removed in the future
225 # When you remove this, please add the default value for
226 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
227 def fixLocalDir(silent=True):
228 """Retro-compatibility with the previous local_dir default value.
229
230 @param silent (boolean): toggle logging output (must be True when called from sat.sh)
231 """
232 user_config = ConfigParser()
233 try:
234 user_config.read(C.CONFIG_FILES)
235 except:
236 pass # file is readable but its structure if wrong
237 try:
238 current_value = user_config.get("DEFAULT", "local_dir")
239 except (NoOptionError, NoSectionError):
240 current_value = ""
241 if current_value:
242 return # nothing to do
243 old_default = "~/.sat"
244 if os.path.isfile(os.path.expanduser(old_default) + "/" + C.SAVEFILE_DATABASE):
245 if not silent:
246 log.warning(
247 _(
248 "A database has been found in the default local_dir for previous versions (< 0.5)"
249 )
250 )
251 tools_config.fixConfigOption("", "local_dir", old_default, silent)
252
253
254 class Memory(object): 223 class Memory(object):
255 """This class manage all the persistent information""" 224 """This class manage all the persistent information"""
256 225
257 def __init__(self, host): 226 def __init__(self, host):
258 log.info(_("Memory manager init")) 227 log.info(_("Memory manager init"))
264 # where main key is resource, or None for bare jid 233 # where main key is resource, or None for bare jid
265 self._key_signals = set() # key which need a signal to frontends when updated 234 self._key_signals = set() # key which need a signal to frontends when updated
266 self.subscriptions = {} 235 self.subscriptions = {}
267 self.auth_sessions = PasswordSessions() # remember the authenticated profiles 236 self.auth_sessions = PasswordSessions() # remember the authenticated profiles
268 self.disco = Discovery(host) 237 self.disco = Discovery(host)
269 fixLocalDir(False) # XXX: tmp update code, will be removed in the future 238 # XXX: tmp update code, will be removed in the future
239 tools_config.fixLocalDir(False)
270 self.config = tools_config.parseMainConf() 240 self.config = tools_config.parseMainConf()
271 database_file = os.path.expanduser( 241 database_file = os.path.expanduser(
272 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE) 242 os.path.join(self.getConfig("", "local_dir"), C.SAVEFILE_DATABASE)
273 ) 243 )
274 self.storage = SqliteStorage(database_file, host.version) 244 self.storage = SqliteStorage(database_file, host.version)