core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
This commit is contained in:
parent
dc5c042fe7
commit
501bc92528
5 changed files with 707 additions and 941 deletions
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
from sat.core import exceptions
|
||||
from logging import debug, info, warning, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.words.protocols.jabber.error import StanzaError
|
||||
from twisted.internet import defer
|
||||
|
|
@ -126,9 +127,9 @@ class Discovery(object):
|
|||
# we cache items only for our own server
|
||||
try:
|
||||
items = self.host.memory.getEntityData(jid_, ["DISCO_ITEMS"], client.profile)["DISCO_ITEMS"]
|
||||
debug("[%s] disco items are in cache" % jid_.full())
|
||||
log.debug("[%s] disco items are in cache" % jid_.full())
|
||||
except KeyError:
|
||||
debug("Caching [%s] disco items" % jid_.full())
|
||||
log.debug("Caching [%s] disco items" % jid_.full())
|
||||
items = yield client.disco.requestItems(jid_)
|
||||
self.host.memory.updateEntityData(jid_, "DISCO_ITEMS", items, client.profile)
|
||||
else:
|
||||
|
|
@ -139,7 +140,7 @@ class Discovery(object):
|
|||
|
||||
def _infosEb(self, failure, entity_jid):
|
||||
failure.trap(StanzaError)
|
||||
warning(_("Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(),
|
||||
log.warning(_("Error while requesting [%(jid)s]: %(error)s") % {'jid': entity_jid.full(),
|
||||
'error': failure.getErrorMessage()})
|
||||
|
||||
def findServiceEntities(self, category, type_, jid_=None, profile_key=C.PROF_KEY_NONE):
|
||||
|
|
@ -236,7 +237,7 @@ class Discovery(object):
|
|||
s.append('<')
|
||||
#TODO: manage XEP-0128 data form here
|
||||
cap_hash = b64encode(sha1(''.join(s)).digest())
|
||||
debug(_('Capability hash generated: [%s]') % cap_hash)
|
||||
log.debug(_('Capability hash generated: [%s]') % cap_hash)
|
||||
return cap_hash
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ import csv
|
|||
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 @@ class Sessions(object):
|
|||
|
||||
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 @@ class Sessions(object):
|
|||
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 @@ class Memory(object):
|
|||
"""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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
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 @@ class Memory(object):
|
|||
"""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 {}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ from sat.core.i18n import _
|
|||
from sat.core import exceptions
|
||||
from sat.core.constants import Const as C
|
||||
from xml.dom import minidom, NotFoundErr
|
||||
from logging import debug, info, warning, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from twisted.internet import defer
|
||||
from twisted.python.failure import Failure
|
||||
from sat.tools.xml_tools import paramsXML2XMLUI
|
||||
|
|
@ -115,7 +116,7 @@ class Params(object):
|
|||
try:
|
||||
del self.params[profile]
|
||||
except KeyError:
|
||||
error(_("Trying to purge cache of a profile not in memory: [%s]") % profile)
|
||||
log.error(_("Trying to purge cache of a profile not in memory: [%s]") % profile)
|
||||
|
||||
def save_xml(self, filename):
|
||||
"""Save parameters template to xml file"""
|
||||
|
|
@ -123,7 +124,7 @@ class Params(object):
|
|||
xml_file.write(self.dom.toxml('utf-8'))
|
||||
|
||||
def __init__(self, host, storage):
|
||||
debug("Parameters init")
|
||||
log.debug("Parameters init")
|
||||
self.host = host
|
||||
self.storage = storage
|
||||
self.default_profile = None
|
||||
|
|
@ -138,7 +139,7 @@ class Params(object):
|
|||
@return: a Deferred instance
|
||||
"""
|
||||
if self.storage.hasProfile(profile):
|
||||
info(_('The profile name already exists'))
|
||||
log.info(_('The profile name already exists'))
|
||||
return defer.fail(Failure(exceptions.ConflictError))
|
||||
if not self.host.trigger.point("ProfileCreation", profile):
|
||||
return defer.fail(Failure(exceptions.CancelError))
|
||||
|
|
@ -153,13 +154,13 @@ class Params(object):
|
|||
@return: a Deferred instance
|
||||
"""
|
||||
if not self.storage.hasProfile(profile):
|
||||
info(_('Trying to delete an unknown profile'))
|
||||
log.info(_('Trying to delete an unknown profile'))
|
||||
return defer.fail(Failure(exceptions.ProfileUnknownError))
|
||||
if self.host.isConnected(profile):
|
||||
if force:
|
||||
self.host.disconnect(profile)
|
||||
else:
|
||||
info(_("Trying to delete a connected profile"))
|
||||
log.info(_("Trying to delete a connected profile"))
|
||||
return defer.fail(Failure(exceptions.ConnectedProfileError))
|
||||
return self.storage.deleteProfile(profile)
|
||||
|
||||
|
|
@ -174,11 +175,11 @@ class Params(object):
|
|||
if profile_key == '@DEFAULT@':
|
||||
default = self.host.memory.memory_data.get('Profile_default')
|
||||
if not default:
|
||||
info(_('No default profile, returning first one')) # TODO: manage real default profile
|
||||
log.info(_('No default profile, returning first one')) # TODO: manage real default profile
|
||||
try:
|
||||
default = self.host.memory.memory_data['Profile_default'] = self.storage.getProfilesList()[0]
|
||||
except IndexError:
|
||||
info(_('No profile exist yet'))
|
||||
log.info(_('No profile exist yet'))
|
||||
return ""
|
||||
return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
|
||||
elif profile_key == C.PROF_KEY_NONE:
|
||||
|
|
@ -186,7 +187,7 @@ class Params(object):
|
|||
elif return_profile_keys and profile_key in ["@ALL@"]:
|
||||
return profile_key # this value must be managed by the caller
|
||||
if not self.storage.hasProfile(profile_key):
|
||||
info(_('Trying to access an unknown profile'))
|
||||
log.info(_('Trying to access an unknown profile'))
|
||||
return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places)
|
||||
return profile_key
|
||||
|
||||
|
|
@ -267,23 +268,23 @@ class Params(object):
|
|||
@param app: name of the frontend registering the parameters
|
||||
"""
|
||||
if not app:
|
||||
warning(_("Trying to register frontends parameters with no specified app: aborted"))
|
||||
log.warning(_("Trying to register frontends parameters with no specified app: aborted"))
|
||||
return
|
||||
if not hasattr(self, "frontends_cache"):
|
||||
self.frontends_cache = []
|
||||
if app in self.frontends_cache:
|
||||
debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
|
||||
log.debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
|
||||
return
|
||||
self.frontends_cache.append(app)
|
||||
self.updateParams(xml, security_limit, app)
|
||||
debug("Frontends parameters registered for %(app)s" % {'app': app})
|
||||
log.debug("Frontends parameters registered for %(app)s" % {'app': app})
|
||||
|
||||
def __default_ok(self, value, name, category):
|
||||
#FIXME: will not work with individual parameters
|
||||
self.setParam(name, value, category)
|
||||
|
||||
def __default_ko(self, failure, name, category):
|
||||
error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)})
|
||||
log.error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)})
|
||||
|
||||
def setDefault(self, name, category, callback, errback=None):
|
||||
"""Set default value of parameter
|
||||
|
|
@ -295,17 +296,17 @@ class Params(object):
|
|||
"""
|
||||
#TODO: send signal param update if value changed
|
||||
#TODO: manage individual paramaters
|
||||
debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
|
||||
log.debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
|
||||
node = self._getParamNode(name, category, '@ALL@')
|
||||
if not node:
|
||||
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
return
|
||||
if node[1].getAttribute('default_cb') == 'yes':
|
||||
# del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value,
|
||||
# and we can still use it later e.g. to call a generic setDefault method
|
||||
value = self._getParam(category, name, C.GENERAL)
|
||||
if value is None: # no value set by the user: we have the default value
|
||||
debug ("Default value to set, using callback")
|
||||
log.debug ("Default value to set, using callback")
|
||||
d = defer.maybeDeferred(callback)
|
||||
d.addCallback(self.__default_ok, name, category)
|
||||
d.addErrback(errback or self.__default_ko, name, category)
|
||||
|
|
@ -343,7 +344,7 @@ class Params(object):
|
|||
#FIXME: looks really dirty and buggy, need to be reviewed/refactored
|
||||
node = self._getParamNode(name, category)
|
||||
if not node:
|
||||
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
raise exceptions.NotFound
|
||||
|
||||
if node[0] == C.GENERAL:
|
||||
|
|
@ -354,11 +355,11 @@ class Params(object):
|
|||
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Requesting a param for an non-existant profile'))
|
||||
log.error(_('Requesting a param for an non-existant profile'))
|
||||
raise exceptions.ProfileUnknownError
|
||||
|
||||
if profile not in self.params:
|
||||
error(_('Requesting synchronous param for not connected profile'))
|
||||
log.error(_('Requesting synchronous param for not connected profile'))
|
||||
raise exceptions.NotConnectedProfileError(profile)
|
||||
|
||||
if attr == "value":
|
||||
|
|
@ -378,11 +379,11 @@ class Params(object):
|
|||
@param profile: owner of the param (@ALL@ for everyone)"""
|
||||
node = self._getParamNode(name, category)
|
||||
if not node:
|
||||
error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
|
||||
return None
|
||||
|
||||
if not self.checkSecurityLimit(node[1], security_limit):
|
||||
warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
|
||||
log.warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
|
||||
% {'param': name, 'cat': category}))
|
||||
return None
|
||||
|
||||
|
|
@ -394,7 +395,7 @@ class Params(object):
|
|||
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Requesting a param for a non-existant profile'))
|
||||
log.error(_('Requesting a param for a non-existant profile'))
|
||||
return defer.fail()
|
||||
|
||||
if attr != "value":
|
||||
|
|
@ -538,7 +539,7 @@ class Params(object):
|
|||
"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Asking params for inexistant profile"))
|
||||
log.error(_("Asking params for inexistant profile"))
|
||||
return ""
|
||||
d = self.getParams(security_limit, app, profile)
|
||||
return d.addCallback(lambda param_xml: paramsXML2XMLUI(param_xml))
|
||||
|
|
@ -554,7 +555,7 @@ class Params(object):
|
|||
"""
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Asking params for inexistant profile"))
|
||||
log.error(_("Asking params for inexistant profile"))
|
||||
return defer.succeed("")
|
||||
|
||||
def returnXML(prof_xml):
|
||||
|
|
@ -577,7 +578,7 @@ class Params(object):
|
|||
#TODO: manage category of general type (without existant profile)
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Asking params for inexistant profile"))
|
||||
log.error(_("Asking params for inexistant profile"))
|
||||
return ""
|
||||
|
||||
def returnCategoryXml(prof_xml):
|
||||
|
|
@ -629,17 +630,17 @@ class Params(object):
|
|||
if profile_key != C.PROF_KEY_NONE:
|
||||
profile = self.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_('Trying to set parameter for an unknown profile'))
|
||||
log.error(_('Trying to set parameter for an unknown profile'))
|
||||
return # TODO: throw an error
|
||||
|
||||
node = self._getParamNode(name, category, '@ALL@')
|
||||
if not node:
|
||||
error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
|
||||
log.error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
|
||||
% {'category': category, 'name': name})
|
||||
return
|
||||
|
||||
if not self.checkSecurityLimit(node[1], security_limit):
|
||||
warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
|
||||
log.warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
|
||||
% {'param': name, 'cat': category}))
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from logging import debug, info, warning, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
|
||||
|
||||
class MemoryNotInitializedError(Exception):
|
||||
|
|
@ -35,7 +36,7 @@ class PersistentDict(object):
|
|||
"""@param namespace: unique namespace for this dictionary
|
||||
@param profile: profile which *MUST* exists, or None for general values"""
|
||||
if not self.storage:
|
||||
error(_("PersistentDict can't be used before memory initialisation"))
|
||||
log.error(_("PersistentDict can't be used before memory initialisation"))
|
||||
raise MemoryNotInitializedError
|
||||
self._cache = {}
|
||||
self.namespace = namespace
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
from sat.core.i18n import _
|
||||
from sat.core import exceptions
|
||||
from logging import debug, info, warning, error
|
||||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from twisted.enterprise import adbapi
|
||||
from twisted.internet import defer
|
||||
from collections import OrderedDict
|
||||
|
|
@ -80,7 +81,7 @@ class SqliteStorage(object):
|
|||
self.initialized = defer.Deferred() # triggered when memory is fully initialised and ready
|
||||
self.profiles = {} # we keep cache for the profiles (key: profile name, value: profile id)
|
||||
|
||||
info(_("Connecting database"))
|
||||
log.info(_("Connecting database"))
|
||||
new_base = not os.path.exists(db_filename) # do we have to create the database ?
|
||||
if new_base: # the dir may not exist if it's not the XDG recommended one
|
||||
dir_ = os.path.dirname(db_filename)
|
||||
|
|
@ -92,10 +93,10 @@ class SqliteStorage(object):
|
|||
# XXX: foreign_keys activation doesn't seem to work, probably because of the multi-threading
|
||||
# All the requests that need to use this feature should be run with runInteraction instead,
|
||||
# so you can set the PRAGMA as it is done in self.deleteProfile
|
||||
init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: error(_("Can't activate foreign keys")))
|
||||
init_defer = self.dbpool.runOperation("PRAGMA foreign_keys = ON").addErrback(lambda x: log.error(_("Can't activate foreign keys")))
|
||||
|
||||
def getNewBaseSql():
|
||||
info(_("The database is new, creating the tables"))
|
||||
log.info(_("The database is new, creating the tables"))
|
||||
database_creation = ["PRAGMA user_version=%d" % CURRENT_DB_VERSION]
|
||||
database_creation.extend(Updater.createData2Raw(DATABASE_SCHEMAS['current']['CREATE']))
|
||||
database_creation.extend(Updater.insertData2Raw(DATABASE_SCHEMAS['current']['INSERT']))
|
||||
|
|
@ -109,7 +110,7 @@ class SqliteStorage(object):
|
|||
|
||||
if statements is None:
|
||||
return defer.succeed(None)
|
||||
debug("===== COMMITING STATEMENTS =====\n%s\n============\n\n" % '\n'.join(statements))
|
||||
log.debug("===== COMMITING STATEMENTS =====\n%s\n============\n\n" % '\n'.join(statements))
|
||||
d = self.dbpool.runInteraction(self._updateDb, tuple(statements))
|
||||
return d
|
||||
|
||||
|
|
@ -166,7 +167,7 @@ class SqliteStorage(object):
|
|||
@param name: name of the profile
|
||||
@return: deferred triggered once profile is actually deleted"""
|
||||
def deletionError(failure):
|
||||
error(_("Can't delete profile [%s]") % name)
|
||||
log.error(_("Can't delete profile [%s]") % name)
|
||||
return failure
|
||||
|
||||
def delete(txn):
|
||||
|
|
@ -176,7 +177,7 @@ class SqliteStorage(object):
|
|||
return None
|
||||
|
||||
d = self.dbpool.runInteraction(delete)
|
||||
d.addCallback(lambda ignore: info(_("Profile [%s] deleted") % name))
|
||||
d.addCallback(lambda ignore: log.info(_("Profile [%s] deleted") % name))
|
||||
d.addErrback(deletionError)
|
||||
return d
|
||||
|
||||
|
|
@ -190,7 +191,7 @@ class SqliteStorage(object):
|
|||
for param in result:
|
||||
category, name, value = param
|
||||
params_gen[(category, name)] = value
|
||||
debug(_("loading general parameters from database"))
|
||||
log.debug(_("loading general parameters from database"))
|
||||
return self.dbpool.runQuery("SELECT category,name,value FROM param_gen").addCallback(fillParams)
|
||||
|
||||
def loadIndParams(self, params_ind, profile):
|
||||
|
|
@ -203,7 +204,7 @@ class SqliteStorage(object):
|
|||
for param in result:
|
||||
category, name, value = param
|
||||
params_ind[(category, name)] = value
|
||||
debug(_("loading individual parameters from database"))
|
||||
log.debug(_("loading individual parameters from database"))
|
||||
d = self.dbpool.runQuery("SELECT category,name,value FROM param_ind WHERE profile_id=?", (self.profiles[profile], ))
|
||||
d.addCallback(fillParams)
|
||||
return d
|
||||
|
|
@ -225,7 +226,7 @@ class SqliteStorage(object):
|
|||
@param value: value to set
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO param_gen(category,name,value) VALUES (?,?,?)", (category, name, value))
|
||||
d.addErrback(lambda ignore: error(_("Can't set general parameter (%(category)s/%(name)s) in database" % {"category": category, "name": name})))
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set general parameter (%(category)s/%(name)s) in database" % {"category": category, "name": name})))
|
||||
return d
|
||||
|
||||
def setIndParam(self, category, name, value, profile):
|
||||
|
|
@ -236,7 +237,7 @@ class SqliteStorage(object):
|
|||
@param profile: a profile which *must* exist
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO param_ind(category,name,profile_id,value) VALUES (?,?,?,?)", (category, name, self.profiles[profile], value))
|
||||
d.addErrback(lambda ignore: error(_("Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category": category, "name": name, "profile": profile})))
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set individual parameter (%(category)s/%(name)s) for [%(profile)s] in database" % {"category": category, "name": name, "profile": profile})))
|
||||
return d
|
||||
|
||||
#History
|
||||
|
|
@ -256,7 +257,7 @@ class SqliteStorage(object):
|
|||
d = self.dbpool.runQuery("INSERT INTO history(source, source_res, dest, dest_res, timestamp, message, type, extra, profile_id) VALUES (?,?,?,?,?,?,?,?,?)",
|
||||
(from_jid.userhost(), from_jid.resource, to_jid.userhost(), to_jid.resource, timestamp or time(),
|
||||
message, _type, extra_, self.profiles[profile]))
|
||||
d.addErrback(lambda ignore: error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't save following message in history: from [%(from_jid)s] to [%(to_jid)s] ==> [%(message)s]" %
|
||||
{"from_jid": from_jid.full(), "to_jid": to_jid.full(), "message": message})))
|
||||
return d
|
||||
|
||||
|
|
@ -321,9 +322,9 @@ class SqliteStorage(object):
|
|||
for private in result:
|
||||
key, value = private
|
||||
private_gen[key] = value
|
||||
debug(_("loading general private values [namespace: %s] from database") % (namespace, ))
|
||||
log.debug(_("loading general private values [namespace: %s] from database") % (namespace, ))
|
||||
d = self.dbpool.runQuery("SELECT key,value FROM private_gen WHERE namespace=?", (namespace, )).addCallback(fillPrivates)
|
||||
return d.addErrback(lambda x: debug(_("No data present in database for namespace %s") % namespace))
|
||||
return d.addErrback(lambda x: log.debug(_("No data present in database for namespace %s") % namespace))
|
||||
|
||||
def loadIndPrivates(self, private_ind, namespace, profile):
|
||||
"""Load individual private values
|
||||
|
|
@ -336,10 +337,10 @@ class SqliteStorage(object):
|
|||
for private in result:
|
||||
key, value = private
|
||||
private_ind[key] = value
|
||||
debug(_("loading individual private values [namespace: %s] from database") % (namespace, ))
|
||||
log.debug(_("loading individual private values [namespace: %s] from database") % (namespace, ))
|
||||
d = self.dbpool.runQuery("SELECT key,value FROM private_ind WHERE namespace=? AND profile_id=?", (namespace, self.profiles[profile]))
|
||||
d.addCallback(fillPrivates)
|
||||
return d.addErrback(lambda x: debug(_("No data present in database for namespace %s") % namespace))
|
||||
return d.addErrback(lambda x: log.debug(_("No data present in database for namespace %s") % namespace))
|
||||
|
||||
def setGenPrivate(self, namespace, key, value):
|
||||
"""Save the general private value in database
|
||||
|
|
@ -348,7 +349,7 @@ class SqliteStorage(object):
|
|||
@param value: value to set
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO private_gen(namespace,key,value) VALUES (?,?,?)", (namespace, key, value))
|
||||
d.addErrback(lambda ignore: error(_("Can't set general private value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set general private value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
{"namespace": namespace, "key": key})))
|
||||
return d
|
||||
|
||||
|
|
@ -360,7 +361,7 @@ class SqliteStorage(object):
|
|||
@param profile: a profile which *must* exist
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO private_ind(namespace,key,profile_id,value) VALUES (?,?,?,?)", (namespace, key, self.profiles[profile], value))
|
||||
d.addErrback(lambda ignore: error(_("Can't set individual private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set individual private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
{"namespace": namespace, "key": key, "profile": profile})))
|
||||
return d
|
||||
|
||||
|
|
@ -370,7 +371,7 @@ class SqliteStorage(object):
|
|||
@param key: key of the private value
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("DELETE FROM private_gen WHERE namespace=? AND key=?", (namespace, key))
|
||||
d.addErrback(lambda ignore: error(_("Can't delete general private value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't delete general private value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
{"namespace": namespace, "key": key})))
|
||||
return d
|
||||
|
||||
|
|
@ -381,7 +382,7 @@ class SqliteStorage(object):
|
|||
@param profile: a profile which *must* exist
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("DELETE FROM private_ind WHERE namespace=? AND key=? AND profile=?)", (namespace, key, self.profiles[profile]))
|
||||
d.addErrback(lambda ignore: error(_("Can't delete individual private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't delete individual private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
{"namespace": namespace, "key": key, "profile": profile})))
|
||||
return d
|
||||
|
||||
|
|
@ -395,9 +396,9 @@ class SqliteStorage(object):
|
|||
for private in result:
|
||||
key, value = private
|
||||
private_gen[key] = pickle.loads(str(value))
|
||||
debug(_("loading general private binary values [namespace: %s] from database") % (namespace, ))
|
||||
log.debug(_("loading general private binary values [namespace: %s] from database") % (namespace, ))
|
||||
d = self.dbpool.runQuery("SELECT key,value FROM private_gen_bin WHERE namespace=?", (namespace, )).addCallback(fillPrivates)
|
||||
return d.addErrback(lambda x: debug(_("No binary data present in database for namespace %s") % namespace))
|
||||
return d.addErrback(lambda x: log.debug(_("No binary data present in database for namespace %s") % namespace))
|
||||
|
||||
def loadIndPrivatesBinary(self, private_ind, namespace, profile):
|
||||
"""Load individual private binary values
|
||||
|
|
@ -410,10 +411,10 @@ class SqliteStorage(object):
|
|||
for private in result:
|
||||
key, value = private
|
||||
private_ind[key] = pickle.loads(str(value))
|
||||
debug(_("loading individual private binary values [namespace: %s] from database") % (namespace, ))
|
||||
log.debug(_("loading individual private binary values [namespace: %s] from database") % (namespace, ))
|
||||
d = self.dbpool.runQuery("SELECT key,value FROM private_ind_bin WHERE namespace=? AND profile_id=?", (namespace, self.profiles[profile]))
|
||||
d.addCallback(fillPrivates)
|
||||
return d.addErrback(lambda x: debug(_("No binary data present in database for namespace %s") % namespace))
|
||||
return d.addErrback(lambda x: log.debug(_("No binary data present in database for namespace %s") % namespace))
|
||||
|
||||
def setGenPrivateBinary(self, namespace, key, value):
|
||||
"""Save the general private binary value in database
|
||||
|
|
@ -422,7 +423,7 @@ class SqliteStorage(object):
|
|||
@param value: value to set
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO private_gen_bin(namespace,key,value) VALUES (?,?,?)", (namespace, key, pickle.dumps(value, 0)))
|
||||
d.addErrback(lambda ignore: error(_("Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
{"namespace": namespace, "key": key})))
|
||||
return d
|
||||
|
||||
|
|
@ -434,7 +435,7 @@ class SqliteStorage(object):
|
|||
@param profile: a profile which *must* exist
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("REPLACE INTO private_ind_bin(namespace,key,profile_id,value) VALUES (?,?,?,?)", (namespace, key, self.profiles[profile], pickle.dumps(value, 0)))
|
||||
d.addErrback(lambda ignore: error(_("Can't set individual binary private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't set individual binary private value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
{"namespace": namespace, "key": key, "profile": profile})))
|
||||
return d
|
||||
|
||||
|
|
@ -444,7 +445,7 @@ class SqliteStorage(object):
|
|||
@param key: key of the private value
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("DELETE FROM private_gen_bin WHERE namespace=? AND key=?", (namespace, key))
|
||||
d.addErrback(lambda ignore: error(_("Can't delete general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't delete general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
|
||||
{"namespace": namespace, "key": key})))
|
||||
return d
|
||||
|
||||
|
|
@ -455,7 +456,7 @@ class SqliteStorage(object):
|
|||
@param profile: a profile which *must* exist
|
||||
@return: deferred"""
|
||||
d = self.dbpool.runQuery("DELETE FROM private_ind_bin WHERE namespace=? AND key=? AND profile=?)", (namespace, key, self.profiles[profile]))
|
||||
d.addErrback(lambda ignore: error(_("Can't delete individual private binary value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
d.addErrback(lambda ignore: log.error(_("Can't delete individual private binary value (%(key)s) [namespace: %(namespace)s] for [%(profile)s] in database" %
|
||||
{"namespace": namespace, "key": key, "profile": profile})))
|
||||
return d
|
||||
##Helper methods##
|
||||
|
|
@ -521,7 +522,7 @@ class Updater(object):
|
|||
|
||||
if local_hash == current_hash:
|
||||
if local_version != CURRENT_DB_VERSION:
|
||||
warning(_("Your local schema is up-to-date, but database versions mismatch, fixing it..."))
|
||||
log.warning(_("Your local schema is up-to-date, but database versions mismatch, fixing it..."))
|
||||
yield self._setLocalVersion(CURRENT_DB_VERSION)
|
||||
else:
|
||||
# an update is needed
|
||||
|
|
@ -531,17 +532,17 @@ class Updater(object):
|
|||
if self._sat_version.endswith('D'):
|
||||
# we are in a development version
|
||||
update_data = self.generateUpdateData(local_sch, current_sch, False)
|
||||
warning(_("There is a schema mismatch, but as we are on a dev version, database will be updated"))
|
||||
log.warning(_("There is a schema mismatch, but as we are on a dev version, database will be updated"))
|
||||
update_raw = self.update2raw(update_data, True)
|
||||
defer.returnValue(update_raw)
|
||||
else:
|
||||
error(_(u"schema version is up-to-date, but local schema differ from expected current schema"))
|
||||
log.error(_(u"schema version is up-to-date, but local schema differ from expected current schema"))
|
||||
update_data = self.generateUpdateData(local_sch, current_sch, True)
|
||||
warning(_(u"Here are the commands that should fix the situation, use at your own risk (do a backup before modifying database), you can go to SàT's MUC room at sat@chat.jabberfr.org for help\n### SQL###\n%s\n### END SQL ###\n") % u'\n'.join(("%s;" % statement for statement in self.update2raw(update_data))))
|
||||
log.warning(_(u"Here are the commands that should fix the situation, use at your own risk (do a backup before modifying database), you can go to SàT's MUC room at sat@chat.jabberfr.org for help\n### SQL###\n%s\n### END SQL ###\n") % u'\n'.join(("%s;" % statement for statement in self.update2raw(update_data))))
|
||||
raise exceptions.DatabaseError("Database mismatch")
|
||||
else:
|
||||
# Database is not up-to-date, we'll do the update
|
||||
info(_("Database schema has changed, local database will be updated"))
|
||||
log.info(_("Database schema has changed, local database will be updated"))
|
||||
update_raw = []
|
||||
for version in xrange(local_version+1, CURRENT_DB_VERSION+1):
|
||||
try:
|
||||
|
|
@ -612,12 +613,12 @@ class Updater(object):
|
|||
schema_dict = {}
|
||||
for create_statement in raw_statements:
|
||||
if not create_statement.startswith("CREATE TABLE "):
|
||||
warning("Unexpected statement, ignoring it")
|
||||
log.warning("Unexpected statement, ignoring it")
|
||||
continue
|
||||
_create_statement = create_statement[13:]
|
||||
table, raw_col_stats = _create_statement.split(' ',1)
|
||||
if raw_col_stats[0] != '(' or raw_col_stats[-1] != ')':
|
||||
warning("Unexpected statement structure, ignoring it")
|
||||
log.warning("Unexpected statement structure, ignoring it")
|
||||
continue
|
||||
col_stats = [stmt.strip() for stmt in self.stmnt_regex.findall(raw_col_stats[1:-1])]
|
||||
col_defs = []
|
||||
|
|
@ -668,7 +669,7 @@ class Updater(object):
|
|||
new_col_defs, new_constraints = new_data[table]
|
||||
for obj in old_col_defs, old_constraints, new_col_defs, new_constraints:
|
||||
if not isinstance(obj, tuple):
|
||||
raise InternalError("Columns definitions must be tuples")
|
||||
raise exceptions.InternalError("Columns definitions must be tuples")
|
||||
defs_create, defs_delete, ignore = getChanges(set(old_col_defs), set(new_col_defs))
|
||||
constraints_create, constraints_delete, ignore = getChanges(set(old_constraints), set(new_constraints))
|
||||
created_col_names = set([name.split(' ',1)[0] for name in defs_create])
|
||||
|
|
@ -706,7 +707,7 @@ class Updater(object):
|
|||
drop.append(self.DROP_SQL % table)
|
||||
if dev_version:
|
||||
if drop:
|
||||
info("Dev version, SQL NOT EXECUTED:\n--\n%s\n--\n" % "\n".join(drop))
|
||||
log.info("Dev version, SQL NOT EXECUTED:\n--\n%s\n--\n" % "\n".join(drop))
|
||||
else:
|
||||
ret.extend(drop)
|
||||
|
||||
|
|
@ -717,7 +718,7 @@ class Updater(object):
|
|||
|
||||
cols_delete = update.get('cols delete', {})
|
||||
for table in cols_delete:
|
||||
info("Following columns in table [%s] are not needed anymore, but are kept for dev version: %s" % (table, ", ".join(cols_delete[table])))
|
||||
log.info("Following columns in table [%s] are not needed anymore, but are kept for dev version: %s" % (table, ", ".join(cols_delete[table])))
|
||||
|
||||
cols_modify = update.get('cols modify', {})
|
||||
for table in cols_modify:
|
||||
|
|
|
|||
Loading…
Reference in a new issue