diff src/plugins/plugin_misc_tarot.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 83ed877541e3
line wrap: on
line diff
--- a/src/plugins/plugin_misc_tarot.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_misc_tarot.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, info, warning, error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.words.xish import domish
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
@@ -28,7 +29,6 @@
 from sat.memory import memory
 from sat.tools import xml_tools
 from sat_frontends.tools.games import TarotCard
-from time import time
 import random
 
 
@@ -55,7 +55,7 @@
         self.__class__ = type(self.__class__.__name__, (self.__class__, RoomGame, object), {})
 
     def __init__(self, host):
-        info(_("Plugin Tarot initialization"))
+        log.info(_("Plugin Tarot initialization"))
         self._sessions = memory.Sessions()
         self.inheritFromRoomGame(host)
         RoomGame._init_(self, host, PLUGIN_INFO, (NS_CG, CG_TAG),
@@ -199,7 +199,7 @@
                             pl_waiting = players_data[player]['wait_for_low']
                             played.remove(card)
                             players_data[pl_waiting]['levees'].append(card)
-                            debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": player, "card_waited": card, "player_waiting": pl_waiting})
+                            log.debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": player, "card_waited": card, "player_waiting": pl_waiting})
                             return
                 return
 
@@ -230,12 +230,12 @@
                 low_card = owner_levees[card_idx]
                 del owner_levees[card_idx]
                 players_data[winner]['levees'].append(low_card)
-                debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": excuse_player, "card_waited": low_card, "player_waiting": winner})
+                log.debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": excuse_player, "card_waited": low_card, "player_waiting": winner})
                 break
         if not low_card:  # The player has no low card yet
             #TODO: manage case when player never win a trick with low card
             players_data[excuse_player]['wait_for_low'] = winner
-            debug(_("%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner': excuse_player, 'winner': winner})
+            log.debug(_("%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner': excuse_player, 'winner': winner})
 
     def __draw_game(self, game_data):
         """The game is draw, no score change
@@ -246,7 +246,7 @@
         scores_str += '\n'
         for player in game_data['players']:
             scores_str += _("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': 0, 'total_score': players_data[player]['score']}
-        debug(scores_str)
+        log.debug(scores_str)
 
         return (scores_str, [], [])
 
@@ -295,7 +295,7 @@
         elif game_data['contrat'] == 'Garde Contre':
             contrat_mult = 6
         else:
-            error(_('INTERNAL ERROR: contrat not managed (mispelled ?)'))
+            log.error(_('INTERNAL ERROR: contrat not managed (mispelled ?)'))
             assert(False)
 
         victory = (score >= point_limit)
@@ -318,7 +318,7 @@
         scores_str += '\n'
         for player in game_data['players']:
             scores_str += _("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player': player, 'score_game': player_score[player], 'total_score': players_data[player]['score']}
-        debug(scores_str)
+        log.debug(scores_str)
 
         return (scores_str, winners, loosers)
 
@@ -375,7 +375,7 @@
             if card.suit == "atout" and card < biggest_atout and biggest_hand_atout > biggest_atout and card.value != "excuse":
                 forbidden_cards.append(card)
         else:
-            error(_('Internal error: unmanaged game stage'))
+            log.error(_('Internal error: unmanaged game stage'))
         return forbidden_cards
 
     def __start_play(self, room_jid, game_data, profile):
@@ -394,7 +394,7 @@
         try:
             session_data = self._sessions.profileGet(raw_data["session_id"], profile)
         except KeyError:
-            warning(_("session id doesn't exist, session has probably expired"))
+            log.warning(_("session id doesn't exist, session has probably expired"))
             # TODO: send error dialog
             return defer.succeed({})
 
@@ -403,7 +403,7 @@
         player = self.host.plugins["XEP-0045"].getRoomNick(room_jid_s, profile)
         data = xml_tools.XMLUIResult2DataFormResult(raw_data)
         contrat = data['contrat']
-        debug(_('contrat [%(contrat)s] choosed by %(profile)s') % {'contrat': contrat, 'profile': profile})
+        log.debug(_('contrat [%(contrat)s] choosed by %(profile)s') % {'contrat': contrat, 'profile': profile})
         d = self.send(jid.JID(referee), ('', 'contrat_choosed'), {'player': player}, content=contrat, profile=profile)
         d.addCallback(lambda ignore: {})
         del self._sessions[raw_data["session_id"]]
@@ -417,7 +417,7 @@
         try:
             session_data = self._sessions.profileGet(raw_data["session_id"], profile)
         except KeyError:
-            warning(_("session id doesn't exist, session has probably expired"))
+            log.warning(_("session id doesn't exist, session has probably expired"))
             # TODO: send error dialog
             return defer.succeed({})
 
@@ -436,9 +436,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(_('Cards played by %(profile)s: [%(cards)s]') % {'profile': profile, 'cards': cards})
+        log.debug(_('Cards played by %(profile)s: [%(cards)s]') % {'profile': profile, 'cards': cards})
         elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), 'cards_played')
         self.send(jid.JID(referee), elem, {'player': player}, profile=profile)
 
@@ -504,7 +504,7 @@
                 status = self.games[room_jid.userhost()]['status']
                 nb_players = len(self.games[room_jid.userhost()]['players'])
                 status[player] = 'ready'
-                debug(_('Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status})
+                log.debug(_('Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status})
                 if status.values().count('ready') == nb_players:  # everybody is ready, we can start the game
                     self.newRound(room_jid, profile)
 
@@ -539,14 +539,14 @@
                             best_contrat[0] = player
                             best_contrat[1] = contrat
                     if best_contrat[1] == "Passe":
-                        debug(_("Everybody is passing, round ended"))
+                        log.debug(_("Everybody is passing, round ended"))
                         to_jid = jid.JID(room_jid.userhost())
                         self.send(to_jid, self.__give_scores(*self.__draw_game(game_data)), profile=profile)
                         game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players'])  # we change the dealer
                         for player in game_data['players']:
                             game_data['status'][player] = "init"
                         return
-                    debug(_("%(player)s win the bid with %(contrat)s") % {'player': best_contrat[0], 'contrat': best_contrat[1]})
+                    log.debug(_("%(player)s win the bid with %(contrat)s") % {'player': best_contrat[0], 'contrat': best_contrat[1]})
                     game_data['contrat'] = best_contrat[1]
 
                     if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre":
@@ -567,7 +567,7 @@
                         del game_data['chien'][:]
 
             elif elt.name == 'chien':  # we have received the chien
-                debug(_("tarot: chien received"))
+                log.debug(_("tarot: chien received"))
                 data = {"attaquant": elt['attaquant']}
                 game_data['stage'] = "ecart"
                 game_data['attaquant'] = elt['attaquant']
@@ -618,7 +618,7 @@
                         if all(played):
                             #everybody has played
                             winner = self.__winner(game_data)
-                            debug(_('The winner of this trick is %s') % winner)
+                            log.debug(_('The winner of this trick is %s') % winner)
                             #the winner win the trick
                             self.__excuse_hack(game_data, played, winner)
                             players_data[elt['player']]['levees'].extend(played)
@@ -664,9 +664,9 @@
                     invalid_cards = self.__xml_to_list(elt.elements(name='invalid', uri=NS_CG).next())
                     self.host.bridge.tarotGameInvalidCards(room_jid.userhost(), elt['phase'], played_cards, invalid_cards, profile)
                 else:
-                    error(_('Unmanaged error type: %s') % elt['type'])
+                    log.error(_('Unmanaged error type: %s') % elt['type'])
             else:
-                error(_('Unmanaged card game element: %s') % elt.name)
+                log.error(_('Unmanaged card game element: %s') % elt.name)
 
     def getSyncDataForPlayer(self, room_jid_s, nick):
         return []