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
57 changed files with 707 additions and 941 deletions

View file

@ -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__)
from twisted.words.protocols.jabber import jid
from twisted.internet import reactor, protocol
@ -47,13 +48,13 @@ class ExportCommandProtocol(protocol.ProcessProtocol):
def _clean(self, data):
if not data:
error ("data should not be empty !")
log.error ("data should not be empty !")
return u""
decoded = data.decode('utf-8', 'ignore')[:-1 if data[-1] == '\n' else None]
return clean_ustr(decoded)
def connectionMade(self):
info("connectionMade :)")
log.info("connectionMade :)")
def outReceived(self, data):
self.parent.host.sendMessage(self.target, self._clean(data), no_trigger=True, profile_key=self.profile)
@ -62,7 +63,7 @@ class ExportCommandProtocol(protocol.ProcessProtocol):
self.parent.host.sendMessage(self.target, self._clean(data), no_trigger=True, profile_key=self.profile)
def processEnded(self, reason):
info (u"process finished: %d" % (reason.value.exitCode,))
log.info (u"process finished: %d" % (reason.value.exitCode,))
self.parent.removeProcess(self.target, self)
def write(self, message):
@ -83,7 +84,7 @@ class CommandExport(object):
# this is specially true if we have other triggers.
def __init__(self, host):
info(_("Plugin command export initialization"))
log.info(_("Plugin command export initialization"))
self.host = host
self.spawned = {} # key = entity
host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=10000)
@ -109,7 +110,7 @@ class CommandExport(object):
body = [e for e in message.elements() if e.name == 'body'][0]
except IndexError:
# do not block message without body (chat state notification...)
warning("No body element found in message, following normal behaviour")
log.warning("No body element found in message, following normal behaviour")
return True
mess_data = unicode(body) + '\n'
@ -141,7 +142,7 @@ class CommandExport(object):
"""
profile = self.host.memory.getProfileName(profile_key)
if not profile:
warning("Unknown profile [%s]" % (profile,))
log.warning("Unknown profile [%s]" % (profile,))
return
for target in targets:
@ -151,7 +152,7 @@ class CommandExport(object):
raise jid.InvalidFormat
_jid = _jid.userhostJID()
except (jid.InvalidFormat, RuntimeError):
info(u"invalid target ignored: %s" % (target,))
log.info(u"invalid target ignored: %s" % (target,))
continue
process_prot = ExportCommandProtocol(self, _jid, options, profile)
self.spawned.setdefault((_jid, profile),set()).add(process_prot)