Mercurial > libervia-backend
diff src/plugins/plugin_xep_0045.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 | 5e8e8a034411 |
children | 291eb8216f6e |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py Sat Apr 19 16:48:26 2014 +0200 +++ b/src/plugins/plugin_xep_0045.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.internet import defer from twisted.words.protocols.jabber import jid @@ -55,7 +56,7 @@ # TODO: this plugin is messy, need a big cleanup/refactoring def __init__(self, host): - info(_("Plugin XEP_0045 initialization")) + log.info(_("Plugin XEP_0045 initialization")) self.host = host self.clients = {} self._sessions = memory.Sessions() @@ -77,7 +78,7 @@ self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100) except KeyError: - info(_("Text commands not available")) + log.info(_("Text commands not available")) def profileConnected(self, profile): def assign_service(service): @@ -92,7 +93,7 @@ @param profile: profile to check @return: True if the profile is known and connected, else False""" if not profile or profile not in self.clients or not self.host.isConnected(profile): - error(_('Unknown or disconnected profile (%s)') % profile) + log.error(_('Unknown or disconnected profile (%s)') % profile) if profile in self.clients: del self.clients[profile] return False @@ -112,7 +113,7 @@ #and send the signal only when the room is unlocked #a proper configuration management should be done print "room locked !" - self.clients[profile].configure(room.roomJID, {}).addCallbacks(_sendBridgeSignal, lambda x: error(_('Error while configuring the room'))) + self.clients[profile].configure(room.roomJID, {}).addCallbacks(_sendBridgeSignal, lambda x: log.error(_('Error while configuring the room'))) else: _sendBridgeSignal() return room @@ -124,7 +125,7 @@ nick += '_' return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile': profile}, errbackArgs=[room_jid, nick, history_options, password, profile]) mess = _("Error while joining the room %s" % room_jid.userhost()) - error(mess) + log.error(mess) self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) raise failure @@ -224,7 +225,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({}) @@ -286,7 +287,7 @@ except AttributeError: raise NotReadyYet("Main server MUC service has not been checked yet") if muc_service is None: - warning(_("No MUC service found on main server")) + log.warning(_("No MUC service found on main server")) raise exceptions.FeatureNotFound muc_service = muc_service.userhost() @@ -302,9 +303,9 @@ if not self.__check_profile(profile): return _errDeferred() if room_jid.userhost() in self.clients[profile].joined_rooms: - warning(_('%(profile)s is already in room %(room_jid)s') % {'profile': profile, 'room_jid': room_jid.userhost()}) + log.warning(_('%(profile)s is already in room %(room_jid)s') % {'profile': profile, 'room_jid': room_jid.userhost()}) return _errDeferred() - info(_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile': profile, 'room': room_jid.userhost(), 'nick': nick}) + log.info(_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile': profile, 'room': room_jid.userhost(), 'nick': nick}) history_options = options["history"] == "True" if "history" in options else None password = options["password"] if "password" in options else None @@ -328,7 +329,7 @@ room_jid = jid.JID(room_jid_s) except: mess = _("Invalid room jid: %s") % room_jid_s - warning(mess) + log.warning(mess) self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile) return self.join(room_jid, nick, options, profile) @@ -375,11 +376,11 @@ def cmd_nick(self, mess_data, profile): """change nickname""" - debug("Catched nick command") + log.debug("Catched nick command") if mess_data['type'] != "groupchat": #/nick command does nothing if we are not on a group chat - info("Ignoring /nick command on a non groupchat message") + log.info("Ignoring /nick command on a non groupchat message") return True @@ -392,11 +393,11 @@ def cmd_join(self, mess_data, profile): """join a new room (on the same service if full jid is not specified)""" - debug("Catched join command") + log.debug("Catched join command") if mess_data['type'] != "groupchat": #/leave command does nothing if we are not on a group chat - info("Ignoring /join command on a non groupchat message") + log.info("Ignoring /join command on a non groupchat message") return True if mess_data["unparsed"].strip(): @@ -409,11 +410,11 @@ def cmd_leave(self, mess_data, profile): """quit a room""" - debug("Catched leave command") + log.debug("Catched leave command") if mess_data['type'] != "groupchat": #/leave command does nothing if we are not on a group chat - info("Ignoring /leave command on a non groupchat message") + log.info("Ignoring /leave command on a non groupchat message") return True if mess_data["unparsed"].strip(): @@ -431,11 +432,11 @@ def cmd_title(self, mess_data, profile): """change room's subject""" - debug("Catched title command") + log.debug("Catched title command") if mess_data['type'] != "groupchat": #/leave command does nothing if we are not on a group chat - info("Ignoring /title command on a non groupchat message") + log.info("Ignoring /title command on a non groupchat message") return True subject = mess_data["unparsed"].strip() @@ -455,7 +456,7 @@ if mess_data['type'] != "groupchat": return if target_jid.userhost() not in self.clients[profile].joined_rooms: - warning(_("This room has not been joined")) + log.warning(_("This room has not been joined")) return user = self.clients[profile].joined_rooms[target_jid.userhost()].getUser(target_jid.resource) whois_msg.append(_("Nickname: %s") % user.nick) @@ -511,13 +512,13 @@ self.userLeftRoom(room, user) def receivedGroupChat(self, room, user, body): - debug('receivedGroupChat: room=%s user=%s body=%s', room, user, body) + log.debug('receivedGroupChat: room=%s user=%s body=%s', room, user, body) def userJoinedRoom(self, room, user): if user.nick in self.__changing_nicks: self.__changing_nicks.remove(user.nick) else: - debug(_("user %(nick)s has joined room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) + log.debug(_("user %(nick)s has joined room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile): return user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role} @@ -529,13 +530,13 @@ if user.nick == room.nick: # we left the room room_jid_s = room.roomJID.userhost() - info(_("Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s, + log.info(_("Room [%(room)s] left (%(profile)s))") % {"room": room_jid_s, "profile": self.parent.profile}) self.host.memory.delEntityCache(room.roomJID, self.parent.profile) del self.plugin_parent.clients[self.parent.profile].joined_rooms[room_jid_s] self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile) else: - debug(_("user %(nick)s left room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) + log.debug(_("user %(nick)s left room (%(room_id)s)") % {'nick': user.nick, 'room_id': room.occupantJID.userhost()}) user_data = {'entity': user.entity.full() if user.entity else '', 'affiliation': user.affiliation, 'role': user.role} self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile) @@ -547,6 +548,6 @@ #FIXME: def receivedSubject(self, room, user, subject): - debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject}) + log.debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject}) self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject) self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)