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:
Goffi 2014-04-19 19:19:19 +02:00
commit 501bc92528

View file

@ -21,7 +21,8 @@ from sat.core.i18n import _, D_
from sat.core.constants import Const as C
from sat.core import exceptions
from sat.tools import xml_tools
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.internet import reactor, defer
@ -55,7 +56,7 @@ TYPE_DESCRIPTIONS = { 'irc': D_("Internet Relay Chat"),
class XEP_0100(object):
def __init__(self, host):
info(_("Gateways plugin initialization"))
log.info(_("Gateways plugin initialization"))
self.host = host
self.__gateways = {} # dict used to construct the answer to findGateways. Key = target jid
host.bridge.addMethod("findGateways", ".plugin", in_sign='ss', out_sign='s', method=self._findGateways)
@ -111,7 +112,7 @@ class XEP_0100(object):
try:
target_jid = jid.JID(data['index'])
except (KeyError, RuntimeError):
warning(_("No gateway index selected"))
log.warning(_("No gateway index selected"))
return {}
d = self.gatewayRegister(target_jid, profile)
@ -125,7 +126,7 @@ class XEP_0100(object):
"""
category, type_ = identity
if category != 'gateway':
error(_('INTERNAL ERROR: identity category should always be "gateway" in _getTypeString, got "%s"') % category)
log.error(_('INTERNAL ERROR: identity category should always be "gateway" in _getTypeString, got "%s"') % category)
try:
return _(TYPE_DESCRIPTIONS[type_])
except KeyError:
@ -133,7 +134,7 @@ class XEP_0100(object):
def _registrationSuccessful(self, jid_, profile):
"""Called when in_band registration is ok, we must now follow the rest of procedure"""
debug(_("Registration successful, doing the rest"))
log.debug(_("Registration successful, doing the rest"))
self.host.addContact(jid_, profile_key=profile)
self.host.setPresence(jid_, profile_key=profile)
@ -167,22 +168,22 @@ class XEP_0100(object):
entity = items[idx].entity
gateways = [(identity, result.identities[identity]) for identity in result.identities if identity[0] == 'gateway']
if gateways:
info (_("Found gateway [%(jid)s]: %(identity_name)s") % {'jid': entity.full(), 'identity_name': ' - '.join([gateway[1] for gateway in gateways])})
log.info (_("Found gateway [%(jid)s]: %(identity_name)s") % {'jid': entity.full(), 'identity_name': ' - '.join([gateway[1] for gateway in gateways])})
ret.append((success, (entity, gateways)))
else:
info(_("Skipping [%(jid)s] which is not a gateway") % {'jid': entity.full()})
log.info(_("Skipping [%(jid)s] which is not a gateway") % {'jid': entity.full()})
return ret
def _itemsReceived(self, disco, target, client):
"""Look for items with disco protocol, and ask infos for each one"""
if len(disco._items) == 0:
debug(_("No gateway found"))
log.debug(_("No gateway found"))
return []
_defers = []
for item in disco._items:
debug(_("item found: %s"), item.entity)
log.debug(_("item found: %s"), item.entity)
_defers.append(client.disco.requestInfo(item.entity))
dl = defer.DeferredList(_defers)
dl.addCallback(self._infosReceived, items=disco._items, target=target, client=client)
@ -205,7 +206,7 @@ class XEP_0100(object):
"""Find gateways in the target JID, using discovery protocol
"""
client = self.host.getClient(profile)
debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile})
log.debug(_("find gateways (target = %(target)s, profile = %(profile)s)") % {'target': target.full(), 'profile': profile})
d = client.disco.requestItems(target)
d.addCallback(self._itemsReceived , target=target, client=client)
return d