Mercurial > libervia-backend
comparison src/plugins/plugin_tmp_demo_directory.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 | 0d1a17375bf5 |
children | 9c17bd37e6e5 |
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 _, D_ | 20 from sat.core.i18n import _, D_ |
21 from logging import debug, info, warning, error | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | |
22 from twisted.internet import defer | 23 from twisted.internet import defer |
23 from twisted.words.protocols.jabber.xmlstream import IQ | 24 from twisted.words.protocols.jabber.xmlstream import IQ |
24 from twisted.words.protocols.jabber import jid | 25 from twisted.words.protocols.jabber import jid |
25 from wokkel import data_form | 26 from wokkel import data_form |
26 | 27 |
72 'sub': PARAM_NAME_SUB[0], | 73 'sub': PARAM_NAME_SUB[0], |
73 'sub_label': _(PARAM_NAME_SUB[1]), | 74 'sub_label': _(PARAM_NAME_SUB[1]), |
74 } | 75 } |
75 | 76 |
76 def __init__(self, host): | 77 def __init__(self, host): |
77 info(_(u"Plugin demo directory initialization")) | 78 log.info(_(u"Plugin demo directory initialization")) |
78 activate = host.memory.getConfig(CONFIG_SECTION, CONFIG_ACTIVATE) or 'false' | 79 activate = host.memory.getConfig(CONFIG_SECTION, CONFIG_ACTIVATE) or 'false' |
79 if not activate.lower() in ('true', 'yes', '1'): | 80 if not activate.lower() in ('true', 'yes', '1'): |
80 info("not activated") | 81 log.info("not activated") |
81 return | 82 return |
82 service_str = host.memory.getConfig(CONFIG_SECTION, CONFIG_SERVICE) or 'salut.libervia.org' | 83 service_str = host.memory.getConfig(CONFIG_SECTION, CONFIG_SERVICE) or 'salut.libervia.org' |
83 self.service = jid.JID(service_str) | 84 self.service = jid.JID(service_str) |
84 self.host = host | 85 self.host = host |
85 host.memory.updateParams(self.params) | 86 host.memory.updateParams(self.params) |
93 @param profile: %(doc_profile)s | 94 @param profile: %(doc_profile)s |
94 | 95 |
95 """ | 96 """ |
96 client = self.host.getClient(profile) | 97 client = self.host.getClient(profile) |
97 if not subscribe: | 98 if not subscribe: |
98 info ("Unsubscribing [%s] from directory" % profile) | 99 log.info ("Unsubscribing [%s] from directory" % profile) |
99 unsub_req = IQ(client.xmlstream, 'set') | 100 unsub_req = IQ(client.xmlstream, 'set') |
100 unsub_req['from'] = client.jid.full() | 101 unsub_req['from'] = client.jid.full() |
101 unsub_req['to'] = self.service.userhost() | 102 unsub_req['to'] = self.service.userhost() |
102 command_elt = unsub_req.addElement('command', NS_COMMANDS) | 103 command_elt = unsub_req.addElement('command', NS_COMMANDS) |
103 command_elt['node'] = 'unsubscribe' | 104 command_elt['node'] = 'unsubscribe' |
104 command_elt['action'] = 'execute' | 105 command_elt['action'] = 'execute' |
105 yield unsub_req.send(self.service.userhost()) | 106 yield unsub_req.send(self.service.userhost()) |
106 else: | 107 else: |
107 info ("Subscribing [%s] to directory" % profile) | 108 log.info ("Subscribing [%s] to directory" % profile) |
108 sub_req = IQ(client.xmlstream, 'set') | 109 sub_req = IQ(client.xmlstream, 'set') |
109 sub_req['from'] = client.jid.full() | 110 sub_req['from'] = client.jid.full() |
110 sub_req['to'] = self.service.userhost() | 111 sub_req['to'] = self.service.userhost() |
111 command_elt = sub_req.addElement('command', NS_COMMANDS) | 112 command_elt = sub_req.addElement('command', NS_COMMANDS) |
112 command_elt['node'] = 'subscribe' | 113 command_elt['node'] = 'subscribe' |