comparison src/plugins/plugin_xep_0163.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 069ad98b360d
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
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 sat.core import exceptions
21 from sat.core.constants import Const as C 22 from sat.core.constants import Const as C
22 from logging import debug, info, error 23 from sat.core.log import getLogger
23 from twisted.internet import protocol 24 log = getLogger(__name__)
24 from twisted.words.protocols.jabber import client, jid
25 from twisted.words.protocols.jabber import error as jab_error
26 import twisted.internet.error
27 from twisted.words.xish import domish 25 from twisted.words.xish import domish
28 26
29 from wokkel import disco, pubsub 27 from wokkel import disco, pubsub
30 from wokkel.formats import Mood 28 from wokkel.formats import Mood
31 from sat.core import exceptions
32 29
33 NS_USER_MOOD = 'http://jabber.org/protocol/mood' 30 NS_USER_MOOD = 'http://jabber.org/protocol/mood'
34 31
35 PLUGIN_INFO = { 32 PLUGIN_INFO = {
36 "name": "Personal Eventing Protocol Plugin", 33 "name": "Personal Eventing Protocol Plugin",
45 42
46 43
47 class XEP_0163(object): 44 class XEP_0163(object):
48 45
49 def __init__(self, host): 46 def __init__(self, host):
50 info(_("PEP plugin initialization")) 47 log.info(_("PEP plugin initialization"))
51 self.host = host 48 self.host = host
52 self.pep_events = set() 49 self.pep_events = set()
53 self.pep_out_cb = {} 50 self.pep_out_cb = {}
54 host.trigger.add("PubSub Disco Info", self.disoInfoTrigger) 51 host.trigger.add("PubSub Disco Info", self.disoInfoTrigger)
55 host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s') # args: from (jid), type(MOOD, TUNE, etc), data, profile 52 host.bridge.addSignal("personalEvent", ".plugin", signature='ssa{ss}s') # args: from (jid), type(MOOD, TUNE, etc), data, profile
93 @param data: dict of {string:string} of event_type dependant data 90 @param data: dict of {string:string} of event_type dependant data
94 @param profile_key: profile who send the event 91 @param profile_key: profile who send the event
95 """ 92 """
96 profile = self.host.memory.getProfileName(profile_key) 93 profile = self.host.memory.getProfileName(profile_key)
97 if not profile: 94 if not profile:
98 error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key) 95 log.error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key)
99 raise exceptions.ProfileUnknownError 96 raise exceptions.ProfileUnknownError
100 if not event_type in self.pep_out_cb.keys(): 97 if not event_type in self.pep_out_cb.keys():
101 error(_('Trying to send personal event for an unknown type')) 98 log.error(_('Trying to send personal event for an unknown type'))
102 raise DataError('Type unknown') 99 raise exceptions.DataError('Type unknown')
103 return self.pep_out_cb[event_type](data, profile) 100 return self.pep_out_cb[event_type](data, profile)
104 101
105 def userMoodCB(self, itemsEvent, profile): 102 def userMoodCB(self, itemsEvent, profile):
106 if not itemsEvent.items: 103 if not itemsEvent.items:
107 debug(_("No item found")) 104 log.debug(_("No item found"))
108 return 105 return
109 try: 106 try:
110 mood_elt = [child for child in itemsEvent.items[0].elements() if child.name == "mood"][0] 107 mood_elt = [child for child in itemsEvent.items[0].elements() if child.name == "mood"][0]
111 except IndexError: 108 except IndexError:
112 error(_("Can't find mood element in mood event")) 109 log.error(_("Can't find mood element in mood event"))
113 return 110 return
114 mood = Mood.fromXml(mood_elt) 111 mood = Mood.fromXml(mood_elt)
115 if not mood: 112 if not mood:
116 debug(_("No mood found")) 113 log.debug(_("No mood found"))
117 return 114 return
118 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile) 115 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)
119 116
120 def sendMood(self, data, profile): 117 def sendMood(self, data, profile):
121 """Send XEP-0107's User Mood 118 """Send XEP-0107's User Mood