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

@ -19,7 +19,8 @@
from sat.core.i18n import _
from sat.core.constants import Const as C
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 defer
from sat.core import exceptions
@ -56,7 +57,7 @@ class NodeAccessChangeException(Exception):
class XEP_0277(object):
def __init__(self, host):
info(_("Microblogging plugin initialization"))
log.info(_("Microblogging plugin initialization"))
self.host = host
self.host.plugins["XEP-0163"].addPEPEvent("MICROBLOG", NS_MICROBLOG, self.microblogCB, self.sendMicroblog)
host.bridge.addMethod("getLastMicroblogs", ".plugin",
@ -153,7 +154,7 @@ class XEP_0277(object):
microblog_data['updated'] = date2float(entry_elt, 'updated')
assert('title' in microblog_data) # has been processed already
except IndexError:
error(_("Atom entry %s misses a required element") % item_elt.get('id', ''))
log.error(_("Atom entry %s misses a required element") % item_elt.get('id', ''))
raise exceptions.DataError
if 'content' not in microblog_data: # use the atom title data as the microblog body content
@ -179,7 +180,7 @@ class XEP_0277(object):
microblog_data['comments_service'] = service.full()
microblog_data['comments_node'] = node
except (exceptions.DataError, RuntimeError, KeyError):
warning(_("Can't parse the link element of pubsub entry %s") % microblog_data['id'])
log.warning(_("Can't parse the link element of pubsub entry %s") % microblog_data['id'])
except:
pass
try:
@ -188,7 +189,7 @@ class XEP_0277(object):
try: # XXX: workaround for Jappix behaviour
microblog_data['author'] = xpath(entry_elt, 'author/nick')[0].text
except IndexError:
warning(_("Can't find author element in pubsub entry %s") % microblog_data['id'])
log.warning(_("Can't find author element in pubsub entry %s") % microblog_data['id'])
defer.returnValue(microblog_data)
@ -300,11 +301,11 @@ class XEP_0277(object):
@param data: must include content
@param profile: profile which send the mood"""
if 'content' not in data:
error(_("Microblog data must contain at least 'content' key"))
log.error(_("Microblog data must contain at least 'content' key"))
raise exceptions.DataError('no "content" key found')
content = data['content']
if not content:
error(_("Microblog data's content value must not be empty"))
log.error(_("Microblog data's content value must not be empty"))
raise exceptions.DataError('empty content')
item = yield self.data2entry(data, profile)
ret = yield self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile)
@ -322,7 +323,7 @@ class XEP_0277(object):
if success:
ret.append(value)
else:
error('Error while getting last microblog')
log.error('Error while getting last microblog')
return ret
d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key)
@ -338,18 +339,18 @@ class XEP_0277(object):
_jid, xmlstream = self.host.getJidNStream(profile_key)
if not _jid:
error(_("Can't find profile's jid"))
log.error(_("Can't find profile's jid"))
return
C = self.host.plugins["XEP-0060"]
_options = {C.OPT_ACCESS_MODEL: access, C.OPT_PERSIST_ITEMS: 1, C.OPT_MAX_ITEMS: -1, C.OPT_DELIVER_PAYLOADS: 1, C.OPT_SEND_ITEM_SUBSCRIBE: 1}
def cb(result):
#Node is created with right permission
debug(_("Microblog node has now access %s") % access)
log.debug(_("Microblog node has now access %s") % access)
def fatal_err(s_error):
#Something went wrong
error(_("Can't set microblog access"))
log.error(_("Can't set microblog access"))
raise NodeAccessChangeException()
def err_cb(s_error):