comparison frontends/src/quick_frontend/quick_chat.py @ 1009:d1084f7e56a5

quick_frontend: use of new logging system
author Goffi <goffi@goffi.org>
date Mon, 05 May 2014 18:58:34 +0200
parents cd02f5ef30df
children d6c3fea5ecfe
comparison
equal deleted inserted replaced
1008:d70d4fe5c5f8 1009:d1084f7e56a5
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, info, warning, error 21 from sat.core.log import getLogger
22 log = getLogger(__name__)
22 from sat.tools.jid import JID 23 from sat.tools.jid import JID
23 from sat_frontends.quick_frontend.quick_utils import unescapePrivate 24 from sat_frontends.quick_frontend.quick_utils import unescapePrivate
24 from sat_frontends.quick_frontend.constants import Const 25 from sat_frontends.quick_frontend.constants import Const
25 26
26 27
42 43
43 def setPresents(self, nicks): 44 def setPresents(self, nicks):
44 """Set the users presents in the contact list for a group chat 45 """Set the users presents in the contact list for a group chat
45 @param nicks: list of nicknames 46 @param nicks: list of nicknames
46 """ 47 """
47 debug (_("Adding users %s to room") % nicks) 48 log.debug (_("Adding users %s to room") % nicks)
48 if self.type != "group": 49 if self.type != "group":
49 error (_("[INTERNAL] trying to set presents nicks for a non group chat window")) 50 log.error (_("[INTERNAL] trying to set presents nicks for a non group chat window"))
50 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 51 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
51 self.occupants.update(nicks) 52 self.occupants.update(nicks)
52 53
53 def replaceUser(self, nick, show_info=True): 54 def replaceUser(self, nick, show_info=True):
54 """Add user if it is not in the group list""" 55 """Add user if it is not in the group list"""
55 debug (_("Replacing user %s") % nick) 56 log.debug (_("Replacing user %s") % nick)
56 if self.type != "group": 57 if self.type != "group":
57 error (_("[INTERNAL] trying to replace user for a non group chat window")) 58 log.error (_("[INTERNAL] trying to replace user for a non group chat window"))
58 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 59 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
59 len_before = len(self.occupants) 60 len_before = len(self.occupants)
60 self.occupants.add(nick) 61 self.occupants.add(nick)
61 if len_before != len(self.occupants) and show_info: 62 if len_before != len(self.occupants) and show_info:
62 self.printInfo("=> %s has joined the room" % nick) 63 self.printInfo("=> %s has joined the room" % nick)
63 64
64 def removeUser(self, nick, show_info=True): 65 def removeUser(self, nick, show_info=True):
65 """Remove a user from the group list""" 66 """Remove a user from the group list"""
66 debug(_("Removing user %s") % nick) 67 log.debug(_("Removing user %s") % nick)
67 if self.type != "group": 68 if self.type != "group":
68 error (_("[INTERNAL] trying to remove user for a non group chat window")) 69 log.error (_("[INTERNAL] trying to remove user for a non group chat window"))
69 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 70 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
70 self.occupants.remove(nick) 71 self.occupants.remove(nick)
71 if show_info: 72 if show_info:
72 self.printInfo("<= %s has left the room" % nick) 73 self.printInfo("<= %s has left the room" % nick)
73 74
78 def getUserNick(self): 79 def getUserNick(self):
79 return unicode(self.nick) 80 return unicode(self.nick)
80 81
81 def changeUserNick(self, old_nick, new_nick): 82 def changeUserNick(self, old_nick, new_nick):
82 """Change nick of a user in group list""" 83 """Change nick of a user in group list"""
83 debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick}) 84 log.debug(_("Changing nick of user %(old_nick)s to %(new_nick)s") % {"old_nick": old_nick, "new_nick": new_nick})
84 if self.type != "group": 85 if self.type != "group":
85 error (_("[INTERNAL] trying to change user nick for a non group chat window")) 86 log.error (_("[INTERNAL] trying to change user nick for a non group chat window"))
86 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 87 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
87 self.removeUser(old_nick, show_info=False) 88 self.removeUser(old_nick, show_info=False)
88 self.replaceUser(new_nick, show_info=False) 89 self.replaceUser(new_nick, show_info=False)
89 self.printInfo("%s is now known as %s" % (old_nick, new_nick)) 90 self.printInfo("%s is now known as %s" % (old_nick, new_nick))
90 91
91 def setSubject(self, subject): 92 def setSubject(self, subject):
92 """Set title for a group chat""" 93 """Set title for a group chat"""
93 debug(_("Setting subject to %s") % subject) 94 log.debug(_("Setting subject to %s") % subject)
94 if self.type != "group": 95 if self.type != "group":
95 error (_("[INTERNAL] trying to set subject for a non group chat window")) 96 log.error (_("[INTERNAL] trying to set subject for a non group chat window"))
96 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here 97 raise Exception("INTERNAL ERROR") #TODO: raise proper Exception here
97 98
98 def historyPrint(self, size=20, profile='@NONE@'): 99 def historyPrint(self, size=20, profile='@NONE@'):
99 """Print the initial history""" 100 """Print the initial history"""
100 debug (_("now we print history")) 101 log.debug (_("now we print history"))
101 def onHistory(history): 102 def onHistory(history):
102 for line in history: 103 for line in history:
103 timestamp, from_jid, to_jid, message, _type, extra = line 104 timestamp, from_jid, to_jid, message, _type, extra = line
104 if ((self.type == 'group' and _type != 'groupchat') or 105 if ((self.type == 'group' and _type != 'groupchat') or
105 (self.type == 'one2one' and _type == 'groupchat')): 106 (self.type == 'one2one' and _type == 'groupchat')):
106 continue 107 continue
107 self.printMessage(JID(from_jid), message, profile, timestamp) 108 self.printMessage(JID(from_jid), message, profile, timestamp)
108 109
109 def onHistoryError(err): 110 def onHistoryError(err):
110 error (_("Can't get history")) 111 log.error (_("Can't get history"))
111 112
112 if self.target.startswith(Const.PRIVATE_PREFIX): 113 if self.target.startswith(Const.PRIVATE_PREFIX):
113 target = unescapePrivate(self.target) 114 target = unescapePrivate(self.target)
114 else: 115 else:
115 target = self.target.bare 116 target = self.target.bare
144 raise NotImplementedError 145 raise NotImplementedError
145 146
146 def startGame(self, game_type, referee, players): 147 def startGame(self, game_type, referee, players):
147 """Configure the chat window to start a game""" 148 """Configure the chat window to start a game"""
148 #No need to raise an error as game are not mandatory 149 #No need to raise an error as game are not mandatory
149 warning(_('startGame is not implemented in this frontend')) 150 log.warning(_('startGame is not implemented in this frontend'))
150 151
151 def getGame(self, game_type): 152 def getGame(self, game_type):
152 """Return class managing the game type""" 153 """Return class managing the game type"""
153 #No need to raise an error as game are not mandatory 154 #No need to raise an error as game are not mandatory
154 warning(_('getGame is not implemented in this frontend')) 155 log.warning(_('getGame is not implemented in this frontend'))
155 156
156 def updateChatState(self, state, nick=None): 157 def updateChatState(self, state, nick=None):
157 """Set the chat state (XEP-0085) of the contact. Leave nick to None 158 """Set the chat state (XEP-0085) of the contact. Leave nick to None
158 to set the state for a one2one conversation, or give a nickname or 159 to set the state for a one2one conversation, or give a nickname or
159 Const.ALL_OCCUPANTS to set the state of a participant within a MUC. 160 Const.ALL_OCCUPANTS to set the state of a participant within a MUC.