diff src/plugins/plugin_misc_room_game.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 e1842ebcb2f3
children 83ed877541e3
line wrap: on
line diff
--- a/src/plugins/plugin_misc_room_game.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_misc_room_game.py	Sat Apr 19 19:19:19 2014 +0200
@@ -19,7 +19,8 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
-from logging import debug, warning, error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.words.protocols.jabber.jid import JID
 from twisted.words.xish import domish
 from twisted.internet import defer
@@ -199,7 +200,7 @@
                         break
 
         if not auth and (verbose or _DEBUG):
-            debug(_("%(user)s not allowed to join the game %(game)s in %(room)s") % {'user': user_jid_s or nick, 'game': self.name, 'room': room_jid_s})
+            log.debug(_("%(user)s not allowed to join the game %(game)s in %(room)s") % {'user': user_jid_s or nick, 'game': self.name, 'room': room_jid_s})
         return auth
 
     def _updatePlayers(self, room_jid_s, nicks, sync, profile):
@@ -335,7 +336,7 @@
         elif self.invite_mode == self.FROM_PLAYERS:
             auth = self.isPlayer(room_jid_s, nick)
         if not auth and (verbose or _DEBUG):
-            debug(_("%(user)s not allowed to invite for the game %(game)s in %(room)s") % {'user': nick, 'game': self.name, 'room': room_jid_s})
+            log.debug(_("%(user)s not allowed to invite for the game %(game)s in %(room)s") % {'user': nick, 'game': self.name, 'room': room_jid_s})
         return auth
 
     def isReferee(self, room_jid_s, nick):
@@ -381,7 +382,7 @@
             (nicks, missing) = self.host.plugins["XEP-0045"].getRoomNicksOfUsers(room, other_players, secure=False)
             result = (len(nicks) == len(other_players), nicks, missing)
         if not result[0] and (verbose or _DEBUG):
-            debug(_("Still waiting for %(users)s before starting the game %(game)s in %(room)s") % {'users': result[2], 'game': self.name, 'room': room.occupantJID.userhost()})
+            log.debug(_("Still waiting for %(users)s before starting the game %(game)s in %(room)s") % {'users': result[2], 'game': self.name, 'room': room.occupantJID.userhost()})
         return result
 
     def getUniqueName(self, muc_service=None, profile_key=C.PROF_KEY_NONE):
@@ -402,10 +403,10 @@
         @param room_jid_s: JID userhost of the room, or None to generate a unique name
         @param profile_key
         """
-        debug(_('Preparing room for %s game') % self.name)
+        log.debug(_('Preparing room for %s game') % self.name)
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            error(_("Unknown profile"))
+            log.error(_("Unknown profile"))
             return
         if other_players is None:
             other_players = []
@@ -446,7 +447,7 @@
             # considering the last batch of invitations
             batch = len(self.invitations[room_jid_s]) - 1
             if batch < 0:
-                error("Invitations from %s to play %s in %s have been lost!" % (profile_nick, self.name, room_jid_s))
+                log.error("Invitations from %s to play %s in %s have been lost!" % (profile_nick, self.name, room_jid_s))
                 return True
             other_players = self.invitations[room_jid_s][batch][1]
             (auth, nicks, dummy) = self._checkWaitAuth(room, other_players)
@@ -500,15 +501,15 @@
         """
         user_nick = self.host.plugins["XEP-0045"].getRoomNick(room_jid_s, profile)
         if not user_nick:
-            error('Internal error: profile %s has not joined the room %s' % (profile, room_jid_s))
+            log.error('Internal error: profile %s has not joined the room %s' % (profile, room_jid_s))
             return False, False
         if self._gameExists(room_jid_s):
             is_referee = self.isReferee(room_jid_s, user_nick)
             if self._gameExists(room_jid_s, started=True):
-                warning(_("%(game)s game already created in room %(room)s") % {'game': self.name, 'room': room_jid_s})
+                log.warning(_("%(game)s game already created in room %(room)s") % {'game': self.name, 'room': room_jid_s})
                 return False, is_referee
             elif not is_referee:
-                warning(_("%(game)s game in room %(room)s can only be created by %(user)s") % {'game': self.name, 'room': room_jid_s, 'user': user_nick})
+                log.warning(_("%(game)s game in room %(room)s can only be created by %(user)s") % {'game': self.name, 'room': room_jid_s, 'user': user_nick})
                 return False, False
         else:
             self._initGame(room_jid_s, user_nick)
@@ -523,10 +524,10 @@
         @param nicks: list of players nicks in the room (referee included, in first position)
         @param profile_key: %(doc_profile_key)s
         """
-        debug(_("Creating %(game)s game in room %(room)s") % {'game': self.name, 'room': room_jid_s})
+        log.debug(_("Creating %(game)s game in room %(room)s") % {'game': self.name, 'room': room_jid_s})
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            error(_("profile %s is unknown") % profile_key)
+            log.error(_("profile %s is unknown") % profile_key)
             return
         (create, sync) = self._checkCreateGameAndInit(room_jid_s, profile)
         if nicks is None:
@@ -552,9 +553,9 @@
         """
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            error(_("profile %s is unknown") % profile_key)
+            log.error(_("profile %s is unknown") % profile_key)
             return
-        debug('new player ready: %s' % profile)
+        log.debug('new player ready: %s' % profile)
         # TODO: we probably need to add the game and room names in the sent message
         self.send(JID(referee), 'player_ready', {'player': player}, profile=profile)
 
@@ -567,7 +568,7 @@
                     - msg_elts: dict to map each user to his specific initialization message
         @param profile
         """
-        debug(_('new round for %s game') % self.name)
+        log.debug(_('new round for %s game') % self.name)
         game_data = self.games[room_jid.userhost()]
         players = game_data['players']
         players_data = game_data['players_data']
@@ -635,7 +636,7 @@
         @return: a Deferred instance
         """
         if profile is None:
-            error(_("Message can not be sent without a sender profile"))
+            log.error(_("Message can not be sent without a sender profile"))
             return defer.fail(None)
         msg = self._createGameElt(to_jid)
         for elem, attrs, content in data: