Mercurial > libervia-backend
diff src/memory/memory.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | fe181994246a |
children | 52ec79aa5bbe |
line wrap: on
line diff
--- a/src/memory/memory.py Sat Apr 19 16:48:26 2014 +0200 +++ b/src/memory/memory.py Sat Apr 19 19:19:19 2014 +0200 @@ -24,7 +24,8 @@ from xdg import BaseDirectory from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError from uuid import uuid4 -from logging import debug, info, warning, error +from sat.core.log import getLogger +log = getLogger(__name__) from twisted.internet import defer, reactor from twisted.words.protocols.jabber import jid from sat.core import exceptions @@ -61,7 +62,7 @@ def _purgeSession(self, session_id): del self._sessions[session_id] - debug("Session [%s] purged" % session_id) + log.debug("Session [%s] purged" % session_id) def __len__(self): return len(self._sessions) @@ -97,7 +98,7 @@ timer.cancel() self._purgeSession(session_id) except KeyError: - debug ("Session [%s] doesn't exists, timeout expired ?" % session_id) + log.debug ("Session [%s] doesn't exists, timeout expired ?" % session_id) def keys(self): return self._sessions.keys() @@ -110,7 +111,7 @@ """This class manage all persistent informations""" def __init__(self, host): - info(_("Memory manager init")) + log.info(_("Memory manager init")) self.initialized = defer.Deferred() self.host = host self._entities_cache = {} # XXX: keep presence/last resource/other data in cache @@ -123,7 +124,7 @@ self.storage = SqliteStorage(database_file, host.__version__) PersistentDict.storage = self.storage self.params = Params(host, self.storage) - info(_("Loading default params template")) + log.info(_("Loading default params template")) self.params.load_default_params() d = self.storage.initialized.addCallback(lambda ignore: self.load()) self.memory_data = PersistentDict("memory") @@ -136,7 +137,7 @@ try: config.read(C.CONFIG_FILES) except: - error(_("Can't read main config !")) + log.error(_("Can't read main config !")) return config # XXX: tmp update code, will be removed in the future @@ -148,7 +149,7 @@ return # nothing to do old_default = '~/.sat' if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): - warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) + log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) config = SafeConfigParser() target_file = None for file_ in C.CONFIG_FILES[::-1]: @@ -164,7 +165,7 @@ config.set('', 'local_dir', old_default) with open(target_file, 'wb') as configfile: config.write(configfile) # for the next time that user launches sat - warning(_("Auto-update: local_dir set to %(path)s in the file %(config_file)s") % {'path': old_default, 'config_file': file_}) + log.warning(_("Auto-update: local_dir set to %(path)s in the file %(config_file)s") % {'path': old_default, 'config_file': file_}) default = old_default else: # use the new default local_dir default = C.DEFAULT_LOCAL_DIR @@ -200,10 +201,10 @@ if os.path.exists(filename): try: self.params.load_xml(filename) - debug(_("Parameters loaded from file: %s") % filename) + log.debug(_("Parameters loaded from file: %s") % filename) return True except Exception as e: - error(_("Can't load parameters from file: %s") % e) + log.error(_("Can't load parameters from file: %s") % e) return False def load(self): @@ -219,18 +220,18 @@ def startProfileSession(self, profile): """"Iniatialise session for a profile @param profile: %(doc_profile)s""" - info(_("[%s] Profile session started" % profile)) + log.info(_("[%s] Profile session started" % profile)) self._entities_cache[profile] = {} def purgeProfileSession(self, profile): """Delete cache of data of profile @param profile: %(doc_profile)s""" - info(_("[%s] Profile session purge" % profile)) + log.info(_("[%s] Profile session purge" % profile)) self.params.purgeProfile(profile) try: del self._entities_cache[profile] except KeyError: - error(_("Trying to purge roster status cache for a profile not in memory: [%s]") % profile) + log.error(_("Trying to purge roster status cache for a profile not in memory: [%s]") % profile) def save_xml(self, filename=None): """Save parameters template to xml file""" @@ -240,10 +241,10 @@ filename = os.path.expanduser(filename) try: self.params.save_xml(filename) - debug(_("Parameters saved to file: %s") % filename) + log.debug(_("Parameters saved to file: %s") % filename) return True except Exception as e: - error(_("Can't save parameters to file: %s") % e) + log.error(_("Can't save parameters to file: %s") % e) return False def getProfilesList(self): @@ -312,7 +313,7 @@ if "presence" in self._entities_cache[profile][entity]: entities_presence[entity] = self._entities_cache[profile][entity]["presence"] - debug("Memory getPresenceStatus (%s)", entities_presence) + log.debug("Memory getPresenceStatus (%s)", entities_presence) return entities_presence def setPresenceStatus(self, entity_jid, show, priority, statuses, profile_key): @@ -393,7 +394,7 @@ try: del entity_data[key] except KeyError: - debug("Key [%s] doesn't exist for [%s] in entities_cache" % (key, entity_jid.full())) + log.debug("Key [%s] doesn't exist for [%s] in entities_cache" % (key, entity_jid.full())) def getEntityData(self, entity_jid, keys_list, profile_key): """Get a list of cached values for entity @@ -454,7 +455,7 @@ try: del self._entities_cache[profile][entity] except KeyError: - debug("Can't delete entity [%s]: not in cache" % entity.full()) + log.debug("Can't delete entity [%s]: not in cache" % entity.full()) def addWaitingSub(self, type_, entity_jid, profile_key): """Called when a subcription request is received""" @@ -475,7 +476,7 @@ """Called to get a list of currently waiting subscription requests""" profile = self.getProfileName(profile_key) if not profile: - error(_('Asking waiting subscriptions for a non-existant profile')) + log.error(_('Asking waiting subscriptions for a non-existant profile')) return {} if profile not in self.subscriptions: return {}