diff src/plugins/plugin_misc_maildir.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 1a759096ccbd
children 3b1c5f723c4b
line wrap: on
line diff
--- a/src/plugins/plugin_misc_maildir.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_misc_maildir.py	Sat Apr 19 19:19:19 2014 +0200
@@ -19,11 +19,12 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
-from logging import debug, info, error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 import warnings
 warnings.filterwarnings('ignore', 'the MimeWriter', DeprecationWarning, 'twisted')  # FIXME: to be removed, see http://twistedmatrix.com/trac/ticket/4038
 from twisted.internet import protocol
-from twisted.words.protocols.jabber import error as jab_error
+from twisted.words.protocols import jabber
 from twisted.cred import portal, checkers
 from twisted.mail import imap4, maildir
 from email.parser import Parser
@@ -58,7 +59,7 @@
 class MaildirBox(object):
 
     def __init__(self, host):
-        info(_("Plugin Maildir initialization"))
+        log.info(_("Plugin Maildir initialization"))
         self.host = host
 
         self.__observed = {}
@@ -126,7 +127,7 @@
         @param mailboxUser: MailboxUser instance"""
         if boxname not in self.__mailboxes:
             err_msg = _("Trying to remove an mailboxUser not referenced")
-            error(_("INTERNAL ERROR: ") + err_msg)
+            log.error(_("INTERNAL ERROR: ") + err_msg)
             raise MaildirError(err_msg)
         assert self.__mailboxes[profile][boxname] == mailboxUser
         del self.__mailboxes[profile][boxname]
@@ -145,7 +146,7 @@
             return self.data[profile][boxname]  # the boxname MUST exist in the data
         except KeyError:
             err_msg = _("Boxname doesn't exist in internal data")
-            error(_("INTERNAL ERROR: ") + err_msg)
+            log.error(_("INTERNAL ERROR: ") + err_msg)
             raise MaildirError(err_msg)
 
     def getUid(self, boxname, message_id, profile):
@@ -284,21 +285,21 @@
         @param signal: which signal was observed by the caller"""
         if (profile, boxname) not in self.__observed:
             err_msg = _("Trying to remove an observer for an inexistant mailbox")
-            error(_("INTERNAL ERROR: ") + err_msg)
+            log.error(_("INTERNAL ERROR: ") + err_msg)
             raise MaildirError(err_msg)
         if signal not in self.__observed[(profile, boxname)]:
             err_msg = _("Trying to remove an inexistant observer, no observer for this signal")
-            error(_("INTERNAL ERROR: ") + err_msg)
+            log.error(_("INTERNAL ERROR: ") + err_msg)
             raise MaildirError(err_msg)
         if not callback in self.__observed[(profile, boxname)][signal]:
             err_msg = _("Trying to remove an inexistant observer")
-            error(_("INTERNAL ERROR: ") + err_msg)
+            log.error(_("INTERNAL ERROR: ") + err_msg)
             raise MaildirError(err_msg)
         self.__observed[(profile, boxname)][signal].remove(callback)
 
     def emitSignal(self, profile, boxname, signal_name):
         """Emit the signal to observer"""
-        debug('emitSignal %s %s %s' % (profile, boxname, signal_name))
+        log.debug('emitSignal %s %s %s' % (profile, boxname, signal_name))
         try:
             for observer_cb in self.__observed[(profile, boxname)][signal_name]:
                 observer_cb()
@@ -334,7 +335,7 @@
            @param profile: real profile (ie not a profile_key)
            THIS OBJECT MUST NOT BE USED DIRECTLY: use MaildirBox.accessMessageBox instead"""
         if _maildir._checkBoxReference(name, profile):
-            error("INTERNAL ERROR: MailboxUser MUST NOT be instancied directly")
+            log.error("INTERNAL ERROR: MailboxUser MUST NOT be instancied directly")
             raise MaildirError('double MailboxUser instanciation')
         if name != "INBOX":
             raise NotImplementedError
@@ -352,7 +353,7 @@
         self.__uid_table_update()
 
         if observer:
-            debug("adding observer for %s (%s)" % (name, profile))
+            log.debug("adding observer for %s (%s)" % (name, profile))
             self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE")
 
     def __uid_table_update(self):
@@ -365,7 +366,7 @@
 
     def __del__(self):
         if self.observer:
-            debug("removing observer for %s" % self.name)
+            log.debug("removing observer for %s" % self.name)
             self._maildir.removeObserver(self.observer, self.name, "NEW_MESSAGE")
         self.maildir._removeBoxAccess(self.name, self, profile=self.profile)