Mercurial > libervia-backend
annotate src/core/sat_main.py @ 768:e1c64a5b4588
core: fix bridge method getContactsFromGroup return value (list of jids --> list of strings)
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 18 Dec 2013 10:39:19 +0100 |
parents | 93bd868b8fb6 |
children | bfabeedbf32e |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
4 # SAT: a jabber client |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
20 from twisted.application import service |
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
21 from twisted.internet import defer |
0 | 22 |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
23 from twisted.words.protocols.jabber import jid, xmlstream |
0 | 24 from twisted.words.xish import domish |
25 | |
26 from twisted.internet import reactor | |
27 | |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
28 from wokkel import compat |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
29 from wokkel.xmppim import RosterItem |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
30 |
223 | 31 from sat.bridge.DBus import DBusBridge |
0 | 32 import logging |
460
fb1abc0f8c6a
backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
33 from logging import debug, info, warning, error |
0 | 34 |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
35 import sys |
0 | 36 import os.path |
37 | |
579
133078b82ca8
removed CONST from sat_main as it is already in default_config
Goffi <goffi@goffi.org>
parents:
572
diff
changeset
|
38 from sat.core.default_config import CONST |
332 | 39 from sat.core import xmpp |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
40 from sat.core import exceptions |
434
d7e5df876a04
core: path update for Memory import
Goffi <goffi@goffi.org>
parents:
427
diff
changeset
|
41 from sat.memory.memory import Memory |
223 | 42 from sat.tools.xml_tools import tupleList2dataForm |
252
c09aa319712e
Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents:
245
diff
changeset
|
43 from sat.tools.misc import TriggerManager |
0 | 44 from glob import glob |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
45 from uuid import uuid4 |
0 | 46 |
15
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
47 try: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
48 from twisted.words.protocols.xmlstream import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
49 except ImportError: |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
50 from wokkel.subprotocols import XMPPHandler |
218ec9984fa5
wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
51 |
0 | 52 ### logging configuration FIXME: put this elsewhere ### |
53 logging.basicConfig(level=logging.DEBUG, | |
54 format='%(message)s') | |
55 ### | |
56 | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
57 sat_id = 0 |
0 | 58 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
59 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
60 def sat_next_id(): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
61 global sat_id |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
62 sat_id += 1 |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
63 return "sat_id_" + str(sat_id) |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
64 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
65 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
66 class MessageSentAndStored(Exception): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
67 """ Exception to raise if the message has been already sent and stored in the |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
68 history by the trigger, so the rest of the process should be stopped. This |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
69 should normally be raised by the trigger with the minimal priority """ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
70 pass |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
71 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
72 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
73 class AbortSendMessage(Exception): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
74 """ Exception to raise if sending the message should be aborted. This can be |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
75 raised by any trigger but a side action should be planned by the trigger |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
76 to inform the user about what happened """ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
77 pass |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
78 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
79 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
80 class SAT(service.Service): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
81 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
82 def get_next_id(self): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
83 return sat_next_id() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
84 |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
85 def get_const(self, name): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
86 """Return a constant""" |
358
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
87 try: |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
88 _const = os.environ['SAT_CONST_%s' % name] |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
89 if _const: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
90 debug(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const}) |
358
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
91 return _const |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
92 except KeyError: |
f147b778511a
core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
93 pass |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
94 if name not in CONST: |
69 | 95 error(_('Trying to access an undefined constant')) |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
96 raise Exception |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
97 return CONST[name] |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
98 |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
99 def set_const(self, name, value): |
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
100 """Save a constant""" |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
101 if name in CONST: |
69 | 102 error(_('Trying to redefine a constant')) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
103 raise Exception |
41
d24629c631fc
SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
104 CONST[name] = value |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
105 |
0 | 106 def __init__(self): |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
107 self._cb_map = {} # map from callback_id to callbacks |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
108 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
109 self.profiles = {} |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
110 self.plugins = {} |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
111 self.menus = {} # dynamic menus. key: (type, category, name), value: menu data (dictionnary) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
112 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
113 self.memory = Memory(self) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
114 |
365
efbfccfed623
core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents:
364
diff
changeset
|
115 local_dir = self.memory.getConfig('', 'local_dir') |
364 | 116 if not os.path.exists(local_dir): |
117 os.makedirs(local_dir) | |
118 | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
119 self.trigger = TriggerManager() # trigger are used to change SàT behaviour |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
120 |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
121 try: |
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
122 self.bridge = DBusBridge() |
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
123 except exceptions.BridgeInitError: |
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
124 print (u"Bridge can't be initialised, can't start SàT core") # reactor is not launched yet, so we can't use error log |
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
125 sys.exit(1) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
107
diff
changeset
|
126 self.bridge.register("getVersion", lambda: self.get_const('client_version')) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
127 self.bridge.register("getProfileName", self.memory.getProfileName) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
128 self.bridge.register("getProfilesList", self.memory.getProfilesList) |
550
f25eef861b43
core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents:
541
diff
changeset
|
129 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile)) |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
58
diff
changeset
|
130 self.bridge.register("createProfile", self.memory.createProfile) |
420
acd908528ef7
core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents:
416
diff
changeset
|
131 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile) |
68 | 132 self.bridge.register("deleteProfile", self.memory.deleteProfile) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
133 self.bridge.register("registerNewAccount", self.registerNewAccount) |
0 | 134 self.bridge.register("connect", self.connect) |
341 | 135 self.bridge.register("asyncConnect", self.asyncConnect) |
1 | 136 self.bridge.register("disconnect", self.disconnect) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
137 self.bridge.register("getContacts", self.getContacts) |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
138 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup) |
399 | 139 self.bridge.register("getLastResource", self.memory.getLastResource) |
0 | 140 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus) |
50 | 141 self.bridge.register("getWaitingSub", self.memory.getWaitingSub) |
541
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
142 self.bridge.register("getWaitingConf", self.getWaitingConf) |
602 | 143 self.bridge.register("sendMessage", self._sendMessage) |
364 | 144 self.bridge.register("getConfig", self.memory.getConfig) |
0 | 145 self.bridge.register("setParam", self.setParam) |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
146 self.bridge.register("getParamA", self.memory.getStringParamA) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
147 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA) |
105 | 148 self.bridge.register("getParamsUI", self.memory.getParamsUI) |
0 | 149 self.bridge.register("getParams", self.memory.getParams) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
150 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory) |
0 | 151 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) |
152 self.bridge.register("getHistory", self.memory.getHistory) | |
153 self.bridge.register("setPresence", self.setPresence) | |
50 | 154 self.bridge.register("subscription", self.subscription) |
0 | 155 self.bridge.register("addContact", self.addContact) |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
156 self.bridge.register("updateContact", self.updateContact) |
0 | 157 self.bridge.register("delContact", self.delContact) |
158 self.bridge.register("isConnected", self.isConnected) | |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
159 self.bridge.register("launchAction", self.launchCallback) |
0 | 160 self.bridge.register("confirmationAnswer", self.confirmationAnswer) |
161 self.bridge.register("getProgress", self.getProgress) | |
101 | 162 self.bridge.register("getMenus", self.getMenus) |
163 self.bridge.register("getMenuHelp", self.getMenuHelp) | |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
164 self.bridge.register("asyncCallMenu", self.callMenu) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
165 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
166 self.memory.initialized.addCallback(self._postMemoryInit) |
0 | 167 |
412 | 168 def _postMemoryInit(self, ignore): |
169 """Method called after memory initialization is done""" | |
170 info(_("Memory initialised")) | |
64 | 171 self._import_plugins() |
0 | 172 |
173 def _import_plugins(self): | |
174 """Import all plugins found in plugins directory""" | |
226
d8bb72f00eec
distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
175 import sat.plugins |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
176 plugins_path = os.path.dirname(sat.plugins.__file__) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
177 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename, glob(os.path.join(plugins_path, "plugin*.py")))] |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
178 __plugins_to_import = {} # plugins we still have to import |
0 | 179 for plug in plug_lst: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
180 plugin_path = 'sat.plugins.' + plug |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
181 __import__(plugin_path) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
182 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
183 plugin_info = mod.PLUGIN_INFO |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
184 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
185 while True: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
186 self._import_plugins_from_dict(__plugins_to_import) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
187 if not __plugins_to_import: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
188 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
189 |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
190 def _import_plugins_from_dict(self, plugins_to_import, import_name=None): |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
191 """Recursively import and their dependencies in the right order |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
192 @param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)""" |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
193 if import_name in self.plugins: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
194 debug('Plugin [%s] already imported, passing' % import_name) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
195 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
196 if not import_name: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
197 import_name, (plugin_path, mod, plugin_info) = plugins_to_import.popitem() |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
198 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
199 if not import_name in plugins_to_import: |
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
200 raise ImportError(_('Dependency plugin not found: [%s]') % import_name) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
201 plugin_path, mod, plugin_info = plugins_to_import.pop(import_name) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
202 dependencies = plugin_info.setdefault("dependencies", []) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
203 for dependency in dependencies: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
204 if dependency not in self.plugins: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
205 debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency)) |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
206 self._import_plugins_from_dict(plugins_to_import, dependency) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
207 info(_("importing plugin: %s"), plugin_info['name']) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
208 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
209 if 'handler' in plugin_info and plugin_info['handler'] == 'yes': |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
210 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
211 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
212 self.plugins[import_name].is_handler = False |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
213 #TODO: test xmppclient presence and register handler parent |
0 | 214 |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
215 def connect(self, profile_key='@NONE@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
216 """Connect to jabber server""" |
341 | 217 self.asyncConnect(profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
218 |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
219 def asyncConnect(self, profile_key='@NONE@'): |
341 | 220 """Connect to jabber server with asynchronous reply |
221 @param profile_key: %(doc_profile)s | |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
222 """ |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
223 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
224 profile = self.memory.getProfileName(profile_key) |
324
b069055320b1
core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents:
313
diff
changeset
|
225 if not profile: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
226 error(_('Trying to connect a non-exsitant profile')) |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
227 raise exceptions.ProfileUnknownError(profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
228 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
229 if self.isConnected(profile): |
69 | 230 info(_("already connected !")) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
231 return defer.succeed("None") |
412 | 232 |
233 def afterMemoryInit(ignore): | |
234 """This part must be called when we have loaded individual parameters from memory""" | |
558 | 235 try: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
236 port = int(self.memory.getParamA("Port", "Connection", profile_key=profile)) |
558 | 237 except ValueError: |
238 error(_("Can't parse port value, using default value")) | |
239 port = 5222 | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
240 current = self.profiles[profile] = xmpp.SatXMPPClient( |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
241 self, profile, |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
242 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile), profile), |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
243 self.memory.getParamA("Password", "Connection", profile_key=profile), |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
244 self.memory.getParamA("Server", "Connection", profile_key=profile), |
558 | 245 port) |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
246 |
412 | 247 current.messageProt = xmpp.SatMessageProtocol(self) |
248 current.messageProt.setHandlerParent(current) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
249 |
412 | 250 current.roster = xmpp.SatRosterProtocol(self) |
251 current.roster.setHandlerParent(current) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
252 |
412 | 253 current.presence = xmpp.SatPresenceProtocol(self) |
254 current.presence.setHandlerParent(current) | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
255 |
412 | 256 current.fallBack = xmpp.SatFallbackHandler(self) |
257 current.fallBack.setHandlerParent(current) | |
258 | |
259 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'), | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
260 self.get_const('client_version')) |
412 | 261 current.versionHandler.setHandlerParent(current) |
14 | 262 |
666
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
263 current.identityHandler = xmpp.SatIdentityHandler() |
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
264 current.identityHandler.setHandlerParent(current) |
2a7185b8452c
core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents:
641
diff
changeset
|
265 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
266 debug(_("setting plugins parents")) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
267 |
412 | 268 for plugin in self.plugins.iteritems(): |
269 if plugin[1].is_handler: | |
270 plugin[1].getHandler(profile).setHandlerParent(current) | |
438
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
271 connected_cb = getattr(plugin[1], "profileConnected", None) |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
272 if connected_cb: |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
273 connected_cb(profile) |
14 | 274 |
412 | 275 current.startService() |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
276 |
550
f25eef861b43
core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents:
541
diff
changeset
|
277 d = current.getConnectionDeferred() |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
278 d.addCallback(lambda x: current.roster.got_roster) # we want to be sure that we got the roster |
550
f25eef861b43
core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents:
541
diff
changeset
|
279 return d |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
280 |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
281 self.memory.startProfileSession(profile) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
420
diff
changeset
|
282 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit) |
341 | 283 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
284 def disconnect(self, profile_key): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
285 """disconnect from jabber server""" |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
286 if not self.isConnected(profile_key): |
69 | 287 info(_("not connected !")) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
288 return |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
289 profile = self.memory.getProfileName(profile_key) |
69 | 290 info(_("Disconnecting...")) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
291 self.profiles[profile].stopService() |
438
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
292 for plugin in self.plugins.iteritems(): |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
293 disconnected_cb = getattr(plugin[1], "profileDisconnected", None) |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
294 if disconnected_cb: |
62145e50eae5
core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents:
434
diff
changeset
|
295 disconnected_cb(profile) |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
296 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
297 def getContacts(self, profile_key): |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
298 client = self.getClient(profile_key) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
299 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
300 raise exceptions.ProfileUnknownError(_('Asking contacts for a non-existant profile')) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
301 ret = [] |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
302 for item in client.roster.getItems(): # we get all items for client's roster |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
303 # and convert them to expected format |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
304 attr = client.roster.getAttributes(item) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
305 ret.append([item.jid.userhost(), attr, item.groups]) |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
306 return ret |
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
307 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
308 def getContactsFromGroup(self, group, profile_key): |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
309 client = self.getClient(profile_key) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
310 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
311 raise exceptions.ProfileUnknownError(_("Asking group's contacts for a non-existant profile")) |
768
e1c64a5b4588
core: fix bridge method getContactsFromGroup return value (list of jids --> list of strings)
souliane <souliane@mailoo.org>
parents:
759
diff
changeset
|
312 return [jid.full() for jid in client.roster.getJidsFromGroup(group)] |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
313 |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
314 def purgeClient(self, profile): |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
315 """Remove reference to a profile client and purge cache |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
316 the garbage collector can then free the memory""" |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
317 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
318 del self.profiles[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
319 except KeyError: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
320 error(_("Trying to remove reference to a client not referenced")) |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
321 self.memory.purgeProfileSession(profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
322 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
323 def startService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
324 info("Salut à toi ô mon frère !") |
213
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
325 #TODO: manage autoconnect |
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
326 #self.connect() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
327 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
328 def stopService(self): |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
329 info("Salut aussi à Rantanplan") |
0 | 330 |
331 def run(self): | |
69 | 332 debug(_("running app")) |
0 | 333 reactor.run() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
334 |
0 | 335 def stop(self): |
69 | 336 debug(_("stopping app")) |
0 | 337 reactor.stop() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
338 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
339 ## Misc methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
340 |
64 | 341 def getJidNStream(self, profile_key): |
342 """Convenient method to get jid and stream from profile key | |
343 @return: tuple (jid, xmlstream) from profile, can be None""" | |
344 profile = self.memory.getProfileName(profile_key) | |
345 if not profile or not self.profiles[profile].isConnected(): | |
346 return (None, None) | |
347 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
348 | |
349 def getClient(self, profile_key): | |
350 """Convenient method to get client from profile key | |
351 @return: client or None if it doesn't exist""" | |
352 profile = self.memory.getProfileName(profile_key) | |
353 if not profile: | |
354 return None | |
355 return self.profiles[profile] | |
356 | |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
357 def getClients(self, profile_key): |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
358 """Convenient method to get list of clients from profile key (manage list through profile_key like @ALL@) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
359 @param profile_key: %(doc_profile_key)s |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
360 @return: list of clients""" |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
361 profile = self.memory.getProfileName(profile_key, True) |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
362 if not profile: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
363 return [] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
364 if profile == "@ALL@": |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
365 return self.profiles.values() |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
366 if profile.count('@') > 1: |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
367 raise exceptions.ProfileKeyUnknownError |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
368 return [self.profiles[profile]] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
369 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
370 def getClientHostJid(self, profile_key): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
371 """Convenient method to get the client host from profile key |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
372 @return: host jid or None if it doesn't exist""" |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
373 profile = self.memory.getProfileName(profile_key) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
374 if not profile: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
375 return None |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
376 return self.profiles[profile].getHostJid() |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
377 |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
378 def registerNewAccount(self, login, password, email, server, port=5222, id=None, profile_key='@NONE@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
379 """Connect to a server and create a new account using in-band registration""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
380 profile = self.memory.getProfileName(profile_key) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
381 assert(profile) |
0 | 382 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
383 next_id = id or sat_next_id() # the id is used to send server's answer |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
384 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id, profile)) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
385 connector = reactor.connectTCP(server, port, serverRegistrer) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
386 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
387 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
388 return next_id |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
389 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
390 def registerNewAccountCB(self, data, profile): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
391 # FIXME: to be removed/redone elsewhere |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
392 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
393 password = self.memory.getParamA("Password", "Connection", profile_key=profile) |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
394 server = self.memory.getParamA("Server", "Connection", profile_key=profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
395 |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
396 if not user or not password or not server: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
397 info(_('No user or server given')) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
398 #TODO: a proper error message must be sent to frontend |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
399 self.actionResult(id, "ERROR", {'message': _("No user, password or server given, can't register new account.")}, profile) |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
400 return |
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
401 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
402 confirm_id = sat_next_id() |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
403 self.__private_data[confirm_id] = (id, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
404 |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
405 self.askConfirmation( |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
406 confirm_id, "YES/NO", |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
407 {"message": _("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user': user, 'server': server, 'profile': profile}}, |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
408 self.regisConfirmCB, profile) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
409 print "===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============" |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
410 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
411 def regisConfirmCB(self, id, accepted, data, profile): |
69 | 412 print _("register Confirmation CB ! (%s)") % str(accepted) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
413 action_id, profile = self.__private_data[id] |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
414 del self.__private_data[id] |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
415 if accepted: |
135
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
416 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0] |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
417 password = self.memory.getParamA("Password", "Connection", profile_key=profile) |
7452ac3818e7
Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents:
119
diff
changeset
|
418 server = self.memory.getParamA("Server", "Connection", profile_key=profile) |
336
953536246d9d
core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
419 self.registerNewAccount(user, password, None, server, id=action_id) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
420 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
421 self.actionResult(action_id, "SUPPRESS", {}, profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
422 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
423 def submitForm(self, action, target, fields, profile_key): |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
424 """submit a form |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
425 @param target: target jid where we are submitting |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
426 @param fields: list of tuples (name, value) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
427 @return: tuple: (id, deferred) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
428 """ |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
429 # FIXME: to be removed |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
430 |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
431 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
432 assert(profile) |
36 | 433 to_jid = jid.JID(target) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
434 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
435 iq = compat.IQ(self.profiles[profile].xmlstream, 'set') |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
436 iq["to"] = target |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
437 iq["from"] = self.profiles[profile].jid.full() |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
438 query = iq.addElement(('jabber:iq:register', 'query')) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
439 if action == 'SUBMIT': |
102 | 440 form = tupleList2dataForm(fields) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
441 query.addChild(form.toElement()) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
442 elif action == 'CANCEL': |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
443 query.addElement('remove') |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
444 else: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
445 error(_("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm") % action) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
446 raise NotImplementedError |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
447 |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
448 deferred = iq.send(target) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
449 return (iq['id'], deferred) |
36 | 450 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
451 ## Client management ## |
0 | 452 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
453 def setParam(self, name, value, category, security_limit, profile_key): |
0 | 454 """set wanted paramater and notice observers""" |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
455 info(_("setting param: %(name)s=%(value)s in category %(category)s") % {'name': name, 'value': value, 'category': category}) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
456 self.memory.setParam(name, value, category, security_limit, profile_key) |
0 | 457 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
458 def isConnected(self, profile_key): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
459 """Return connection status of profile |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
460 @param profile_key: key_word or profile name to determine profile name |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
461 @return True if connected |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
462 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
463 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
464 if not profile: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
465 error(_('asking connection status for a non-existant profile')) |
213
5c420b1f1df4
removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents:
210
diff
changeset
|
466 return |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
467 if profile not in self.profiles: |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
468 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
469 return self.profiles[profile].isConnected() |
0 | 470 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
471 |
0 | 472 ## jabber methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
473 |
541
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
474 def getWaitingConf(self, profile_key=None): |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
475 assert(profile_key) |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
476 client = self.getClient(profile_key) |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
477 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
478 raise exceptions.ProfileNotInCacheError |
541
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
479 ret = [] |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
480 for conf_id in client._waiting_conf: |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
481 conf_type, data = client._waiting_conf[conf_id][:2] |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
482 ret.append((conf_id, conf_type, data)) |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
483 return ret |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
484 |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
485 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key='@NONE@'): |
602 | 486 to_jid = jid.JID(to_s) |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
487 #XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way |
752
f49945d728de
core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents:
748
diff
changeset
|
488 return self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
627
diff
changeset
|
489 |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
490 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key='@NONE@'): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
491 #FIXME: check validity of recipient |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
492 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
493 assert(profile) |
489 | 494 client = self.profiles[profile] |
495 current_jid = client.jid | |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
496 if extra is None: |
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
497 extra = {} |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
498 mess_data = { # we put data in a dict, so trigger methods can change them |
602 | 499 "to": to_jid, |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
500 "message": msg, |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
501 "subject": subject, |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
627
diff
changeset
|
502 "type": mess_type, |
698
d731ae066158
core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents:
697
diff
changeset
|
503 "extra": extra, |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
504 } |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
505 treatments = defer.Deferred() # XXX: plugin can add their treatments to this deferred |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
506 |
489 | 507 if mess_data["type"] == "auto": |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
508 # we try to guess the type |
489 | 509 if mess_data["subject"]: |
510 mess_data["type"] = 'normal' | |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
511 elif not mess_data["to"].resource: # if to JID has a resource, the type is not 'groupchat' |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
512 # we may have a groupchat message, we check if the we know this jid |
489 | 513 try: |
514 entity_type = self.memory.getEntityData(mess_data["to"], ['type'], profile)["type"] | |
515 #FIXME: should entity_type manage ressources ? | |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
516 except (exceptions.UnknownEntityError, KeyError): |
489 | 517 entity_type = "contact" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
518 |
489 | 519 if entity_type == "chatroom": |
520 mess_data["type"] = 'groupchat' | |
521 else: | |
522 mess_data["type"] = 'chat' | |
523 else: | |
524 mess_data["type"] == 'chat' | |
525 mess_data["type"] == "chat" if mess_data["subject"] else "normal" | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
526 |
602 | 527 if not no_trigger: |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
528 if not self.trigger.point("sendMessage", mess_data, treatments, profile): |
752
f49945d728de
core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents:
748
diff
changeset
|
529 return defer.succeed(None) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
530 |
602 | 531 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()}) |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
532 mess_data['xml'] = domish.Element((None, 'message')) |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
533 mess_data['xml']["to"] = mess_data["to"].full() |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
534 mess_data['xml']["from"] = current_jid.full() |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
535 mess_data['xml']["type"] = mess_data["type"] |
489 | 536 if mess_data["subject"]: |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
537 mess_data['xml'].addElement("subject", None, subject) |
636
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
627
diff
changeset
|
538 # message without body are used to send chat states |
7ea6d5a86e58
plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents:
627
diff
changeset
|
539 if mess_data["message"]: |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
540 mess_data['xml'].addElement("body", None, mess_data["message"]) |
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
541 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
542 def sendErrback(e): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
543 text = '%s: %s' % (e.value.__class__.__name__, e.getErrorMessage()) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
544 if e.check(MessageSentAndStored): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
545 debug(text) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
546 elif e.check(AbortSendMessage): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
547 warning(text) |
752
f49945d728de
core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents:
748
diff
changeset
|
548 return e |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
549 else: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
550 error("Unmanaged exception: %s" % text) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
551 return e |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
552 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
553 treatments.addCallbacks(self.sendAndStoreMessage, sendErrback, [False, profile]) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
554 treatments.callback(mess_data) |
752
f49945d728de
core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents:
748
diff
changeset
|
555 return treatments |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
556 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
557 def sendAndStoreMessage(self, mess_data, skip_send=False, profile=None): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
558 """Actually send and store the message to history, after all the treatments |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
559 have been done. This has been moved outside the main sendMessage method |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
560 because it is used by XEP-0033 to complete a server-side feature not yet |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
561 implemented by the prosody plugin. |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
562 @param mess_data: message data dictionary |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
563 @param skip_send: set to True to skip sending the message to only store it |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
564 @param profile: profile |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
565 """ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
566 try: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
567 client = self.profiles[profile] |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
568 except KeyError: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
569 error(_("Trying to send a message with no profile")) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
570 return |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
571 current_jid = client.jid |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
572 if not skip_send: |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
573 client.xmlstream.send(mess_data['xml']) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
574 if mess_data["type"] != "groupchat": |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
575 # we don't add groupchat message to history, as we get them back |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
576 # and they will be added then |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
577 if mess_data['message']: # we need a message to save something |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
578 self.memory.addToHistory(current_jid, mess_data['to'], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
579 unicode(mess_data["message"]), |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
580 unicode(mess_data["type"]), |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
581 mess_data['extra'], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
582 profile=profile) |
697
0c84fb112d70
core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents:
677
diff
changeset
|
583 # We send back the message, so all clients are aware of it |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
584 self.bridge.newMessage(mess_data['xml']['from'], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
585 unicode(mess_data["message"]), |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
586 mess_type=mess_data["type"], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
587 to_jid=mess_data['xml']['to'], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
588 extra=mess_data['extra'], |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
589 profile=profile) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
590 |
727
c1cd6c0c2c38
core: fixed statuses parameter in setPresence, and using @NONE@ instead of @DEFAULT@ for default profile_key
Goffi <goffi@goffi.org>
parents:
700
diff
changeset
|
591 def setPresence(self, to="", show="", priority=0, statuses=None, profile_key='@NONE@'): |
0 | 592 """Send our presence information""" |
727
c1cd6c0c2c38
core: fixed statuses parameter in setPresence, and using @NONE@ instead of @DEFAULT@ for default profile_key
Goffi <goffi@goffi.org>
parents:
700
diff
changeset
|
593 if statuses is None: |
c1cd6c0c2c38
core: fixed statuses parameter in setPresence, and using @NONE@ instead of @DEFAULT@ for default profile_key
Goffi <goffi@goffi.org>
parents:
700
diff
changeset
|
594 statuses = {} |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
595 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
596 assert(profile) |
50 | 597 to_jid = jid.JID(to) if to else None |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
598 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
313
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
599 #XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
600 if '' in statuses: |
313
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
601 statuses['default'] = statuses[''] |
cc8ffbfe938c
QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents:
305
diff
changeset
|
602 del statuses[''] |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
603 self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show, |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
604 int(priority), statuses, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
605 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
606 def subscription(self, subs_type, raw_jid, profile_key): |
187
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
607 """Called to manage subscription |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
608 @param subs_type: subsciption type (cf RFC 3921) |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
609 @param raw_jid: unicode entity's jid |
12544ea2951f
Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents:
155
diff
changeset
|
610 @param profile_key: profile""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
611 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
612 assert(profile) |
50 | 613 to_jid = jid.JID(raw_jid) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
614 debug(_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()}) |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
615 if subs_type == "subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
616 self.profiles[profile].presence.subscribe(to_jid) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
617 elif subs_type == "subscribed": |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
618 self.profiles[profile].presence.subscribed(to_jid) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
619 elif subs_type == "unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
620 self.profiles[profile].presence.unsubscribe(to_jid) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
621 elif subs_type == "unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
622 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 623 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
624 def addContact(self, to, profile_key): |
0 | 625 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
626 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
627 assert(profile) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
628 to_jid = jid.JID(to) |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
629 #self.profiles[profile].roster.addItem(to_jid) #XXX: disabled (cf http://wokkel.ik.nu/ticket/56)) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
630 self.profiles[profile].presence.subscribe(to_jid) |
0 | 631 |
346
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
632 def updateContact(self, to, name, groups, profile_key): |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
633 """update a contact in roster list""" |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
634 profile = self.memory.getProfileName(profile_key) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
635 assert(profile) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
636 to_jid = jid.JID(to) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
637 groups = set(groups) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
638 roster_item = RosterItem(to_jid) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
639 roster_item.name = name or None |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
640 roster_item.groups = set(groups) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
641 self.profiles[profile].roster.updateItem(roster_item) |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
642 |
ca3a041fed30
core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents:
341
diff
changeset
|
643 def delContact(self, to, profile_key): |
0 | 644 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
645 profile = self.memory.getProfileName(profile_key) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
646 assert(profile) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
647 to_jid = jid.JID(to) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
648 self.profiles[profile].roster.removeItem(to_jid) |
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
649 self.profiles[profile].presence.unsubscribe(to_jid) |
0 | 650 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
651 def requestServerDisco(self, feature, jid_=None, cache_only=False, profile_key="@NONE"): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
652 """Discover if a server or its items offer a given feature |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
653 @param feature: the feature to check |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
654 @param jid_: the jid of the server |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
655 @param cache_only: expect the result to be in cache and don't actually |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
656 make any request to avoid returning a Deferred. This can be used anytime |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
657 for requesting the local server because the data are cached for sure. |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
658 @result: the Deferred entity jid offering the feature, or None |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
659 """ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
660 profile = self.memory.getProfileName(profile_key) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
661 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
662 if not profile: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
663 return defer.succeed(None) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
664 if jid_ is None: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
665 jid_ = self.getClientHostJid(profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
666 cache_only = True |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
667 hasServerFeature = lambda entity: entity if self.memory.hasServerFeature(feature, entity, profile) else None |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
668 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
669 def haveItemsFeature(dummy=None): |
747
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
670 entities = self.memory.getAllServerIdentities(jid_, profile) |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
671 if entities is None: |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
672 return None # no cached data for this server |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
673 for entity in entities: |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
674 if hasServerFeature(entity): |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
675 return entity |
5aff0beddb28
core: bug fix for requestServerDisco in sat_main.py + added getAllServerIdentities method in memory.py
souliane <souliane@mailoo.org>
parents:
742
diff
changeset
|
676 return None # data are cached but no entity was found |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
677 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
678 entity = hasServerFeature(jid_) or haveItemsFeature() |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
679 if entity: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
680 return defer.succeed(entity) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
681 elif entity is False or cache_only: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
682 return defer.succeed(None) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
683 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
684 # data for this server are not in cache |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
685 disco = self.profiles[profile].disco |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
686 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
687 def errback(failure, method, jid_, profile): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
688 # the target server is not reachable |
748
a0f4a80a6536
core: bug fix for serverDiscoItems (bad use of addCallbacks)
souliane <souliane@mailoo.org>
parents:
747
diff
changeset
|
689 logging.error("disco.%s on %s failed! [%s]" % (method.func_name, jid_.userhost(), profile)) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
690 logging.error("reason: %s" % failure.getErrorMessage()) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
691 if method == disco.requestInfo: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
692 features = self.memory.server_features.setdefault(profile, {}) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
693 features.setdefault(jid_, []) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
694 elif method == disco.requestItems: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
695 identities = self.memory.server_identities.setdefault(profile, {}) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
696 identities.setdefault(jid_, {}) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
697 return failure |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
698 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
699 def callback(d): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
700 if hasServerFeature(jid_): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
701 return jid_ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
702 else: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
703 d2 = disco.requestItems(jid_).addCallback(self.serverDiscoItems, disco, jid_, profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
704 d2.addErrback(errback, disco.requestItems, jid_, profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
705 return d2.addCallback(haveItemsFeature) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
706 |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
707 d = disco.requestInfo(jid_).addCallback(self.serverDisco, jid_, profile) |
748
a0f4a80a6536
core: bug fix for serverDiscoItems (bad use of addCallbacks)
souliane <souliane@mailoo.org>
parents:
747
diff
changeset
|
708 d.addCallbacks(callback, errback, [], errbackArgs=[disco.requestInfo, jid_, profile]) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
709 return d |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
710 |
0 | 711 ## callbacks ## |
712 | |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
713 def serverDisco(self, disco, jid_=None, profile=None): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
714 """xep-0030 Discovery Protocol. |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
715 @param disco: result of the disco info query |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
716 @param jid_: the jid of the target server |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
717 @param profile: profile of the user |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
718 """ |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
719 if jid_ is None: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
720 jid_ = self.getClientHostJid(profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
721 debug(_("Requested disco info on %s") % jid_) |
14 | 722 for feature in disco.features: |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
723 debug(_("Feature found: %s") % feature) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
724 self.memory.addServerFeature(feature, jid_, profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
725 for cat, type_ in disco.identities: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
726 debug(_("Identity found: [%(category)s/%(type)s] %(identity)s") |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
727 % {'category': cat, 'type': type_, 'identity': disco.identities[(cat, type_)]}) |
0 | 728 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
729 def serverDiscoItems(self, disco_result, disco_client, jid_, profile, initialized=None): |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
730 """xep-0030 Discovery Protocol. |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
731 @param disco_result: result of the disco item querry |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
732 @param disco_client: SatDiscoProtocol instance |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
733 @param jid_: the jid of the target server |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
734 @param profile: profile of the user |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
735 @param initialized: deferred which must be chained when everything is done""" |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
736 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
737 def _check_entity_cb(result, entity, jid_, profile): |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
738 debug(_("Requested disco info on %s") % entity) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
739 for category, type_ in result.identities: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
740 debug(_('Identity added: (%(category)s,%(type)s) ==> %(entity)s [%(profile)s]') |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
741 % {'category': category, 'type': type_, 'entity': entity, 'profile': profile}) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
742 self.memory.addServerIdentity(category, type_, entity, jid_, profile) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
743 for feature in result.features: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
744 self.memory.addServerFeature(feature, entity, profile) |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
745 |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
746 def _errback(result, entity, jid_, profile): |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
747 warning(_("Can't get information on identity [%(entity)s] for profile [%(profile)s]") % {'entity': entity, 'profile': profile}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
748 |
305
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
749 defer_list = [] |
15a12bf2bb62
core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents:
292
diff
changeset
|
750 for item in disco_result._items: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
751 if item.entity.full().count('.') == 1: # XXX: workaround for a bug on jabberfr, tmp |
460
fb1abc0f8c6a
backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
752 warning(_('Using jabberfr workaround, be sure your domain has at least two levels (e.g. "example.tld", not "example" alone)')) |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
753 continue |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
754 args = [item.entity, jid_, profile] |
397
ccfd69d090c3
core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents:
391
diff
changeset
|
755 defer_list.append(disco_client.requestInfo(item.entity).addCallbacks(_check_entity_cb, _errback, args, None, args)) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
756 if initialized: |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
757 defer.DeferredList(defer_list).chainDeferred(initialized) |
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
758 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
759 ## Generic HMI ## |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
760 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
761 def actionResult(self, action_id, action_type, data, profile): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
762 """Send the result of an action |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
763 @param action_id: same action_id used with action |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
764 @param action_type: result action_type ("PARAM", "SUCCESS", "ERROR", "XMLUI") |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
765 @param data: dictionary |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
766 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
767 self.bridge.actionResult(action_type, action_id, data, profile) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
768 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
769 def actionResultExt(self, action_id, action_type, data, profile): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
770 """Send the result of an action, extended version |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
771 @param action_id: same action_id used with action |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
772 @param action_type: result action_type /!\ only "DICT_DICT" for this method |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
773 @param data: dictionary of dictionaries |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
774 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
775 if action_type != "DICT_DICT": |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
776 error(_("action_type for actionResultExt must be DICT_DICT, fixing it")) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
777 action_type = "DICT_DICT" |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
778 self.bridge.actionResultExt(action_type, action_id, data, profile) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
779 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
780 def askConfirmation(self, conf_id, conf_type, data, cb, profile): |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
781 """Add a confirmation callback |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
782 @param conf_id: conf_id used to get answer |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
783 @param conf_type: confirmation conf_type ("YES/NO", "FILE_TRANSFER") |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
784 @param data: data (depend of confirmation conf_type) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
785 @param cb: callback called with the answer |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
786 """ |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
787 # FIXME: use XMLUI and *callback methods for dialog |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
788 client = self.getClient(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
789 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
790 raise exceptions.ProfileUnknownError(_("Asking confirmation a non-existant profile")) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
791 if conf_id in client._waiting_conf: |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
792 error(_("Attempt to register two callbacks for the same confirmation")) |
0 | 793 else: |
541
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
794 client._waiting_conf[conf_id] = (conf_type, data, cb) |
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
795 self.bridge.askConfirmation(conf_id, conf_type, data, profile) |
0 | 796 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
797 def confirmationAnswer(self, conf_id, accepted, data, profile): |
0 | 798 """Called by frontends to answer confirmation requests""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
799 client = self.getClient(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
800 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
801 raise exceptions.ProfileUnknownError(_("Confirmation answer from a non-existant profile")) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
802 debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")}) |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
803 if conf_id not in client._waiting_conf: |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
804 error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile}) |
0 | 805 else: |
541
8b116fa42a31
core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
806 cb = client._waiting_conf[conf_id][-1] |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
807 del client._waiting_conf[conf_id] |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
808 cb(conf_id, accepted, data, profile) |
0 | 809 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
810 def registerProgressCB(self, progress_id, CB, profile): |
0 | 811 """Register a callback called when progress is requested for id""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
812 client = self.getClient(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
813 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
814 raise exceptions.ProfileUnknownError |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
815 client._progress_cb_map[progress_id] = CB |
0 | 816 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
817 def removeProgressCB(self, progress_id, profile): |
0 | 818 """Remove a progress callback""" |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
819 client = self.getClient(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
820 if not client: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
821 raise exceptions.ProfileUnknownError |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
822 if progress_id not in client._progress_cb_map: |
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
823 error(_("Trying to remove an unknow progress callback")) |
0 | 824 else: |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
825 del client._progress_cb_map[progress_id] |
0 | 826 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
827 def getProgress(self, progress_id, profile): |
0 | 828 """Return a dict with progress information |
829 data['position'] : current possition | |
830 data['size'] : end_position | |
831 """ | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
832 client = self.getClient(profile) |
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
833 if not profile: |
627
d207c2186519
core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
834 raise exceptions.ProfileNotInCacheError |
0 | 835 data = {} |
836 try: | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
837 client._progress_cb_map[progress_id](progress_id, data, profile) |
0 | 838 except KeyError: |
839 pass | |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
840 #debug("Requested progress for unknown progress_id") |
0 | 841 return data |
842 | |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
843 def registerCallback(self, callback, *args, **kwargs): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
844 """ Register a callback. |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
845 Use with_data=True in kwargs if the callback use the optional data dict |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
846 use force_id=id to avoid generated id. Can lead to name conflict, avoid if possible |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
847 @param callback: any callable |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
848 @return: id of the registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
849 """ |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
850 callback_id = kwargs.pop('force_id', None) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
851 if callback_id is None: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
852 callback_id = str(uuid4()) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
853 else: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
854 if callback_id in self._cb_map: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
855 raise exceptions.ConflictError(_(u"id already registered")) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
856 self._cb_map[callback_id] = (callback, args, kwargs) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
857 return callback_id |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
858 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
859 def removeCallback(self, callback_id): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
860 """ Remove a previously registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
861 @param callback_id: id returned by [registerCallback] """ |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
862 del self._cb_map[callback_id] |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
863 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
864 def launchCallback(self, callback_id, data=None, profile_key="@NONE@"): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
865 """Launch a specific callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
866 @param callback_id: id of the action (callback) to launch |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
867 @param data: optional data |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
868 @profile_key: %(doc_profile_key)s |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
869 @return: a deferred which fire a dict where key can be: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
870 - xmlui: a XMLUI need to be displayed |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
871 """ |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
872 profile = self.memory.getProfileName(profile_key) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
873 if not profile: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
874 raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile')) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
875 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
876 try: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
877 callback, args, kwargs = self._cb_map[callback_id] |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
878 except KeyError: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
879 raise exceptions.DataError("Unknown callback id") |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
880 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
881 if kwargs.get("with_data", False): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
882 if data is None: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
883 raise exceptions.DataError("Required data for this callback is missing") |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
884 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
885 args.insert(0, data) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
886 kwargs["profile"] = profile |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
887 del kwargs["with_data"] |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
888 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
889 return defer.maybeDeferred(callback, *args, **kwargs) |
0 | 890 |
101 | 891 #Menus management |
892 | |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
893 def importMenu(self, category, name, callback, callback_args=None, callback_kwargs=None, help_string="", type_="NORMAL"): |
101 | 894 """register a new menu for frontends |
895 @param category: category of the menu | |
896 @param name: menu item entry | |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
897 @param callback: method to be called when menuitem is selected |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
898 @param callback_args: optional arguments to forward to callback |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
899 @param callback_kwargs: optional keywords arguments to forward to callback |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
900 """ |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
901 # TODO: manage translations |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
902 if (type_, category, name) in self.menus: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
903 raise exceptions.ConflictError("Menu already exists") |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
904 menu_data = {'callback': callback, 'help_string': help_string} |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
905 if callback_args is not None: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
906 assert(isinstance(callback_args, list)) |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
907 menu_data['callback_args'] = callback_args |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
908 if callback_kwargs is not None: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
909 assert(isinstance(callback_kwargs, dict)) |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
910 menu_data['callback_kwargs'] = callback_kwargs |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
911 self.menus[(type_, category, name)] = menu_data |
101 | 912 |
913 def getMenus(self): | |
914 """Return all menus registered""" | |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
915 # TODO: manage translations |
101 | 916 return self.menus.keys() |
917 | |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
918 def getMenuHelp(self, category, name, type_="NORMAL"): |
101 | 919 """return the help string of the menu""" |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
920 # TODO: manage translations |
101 | 921 try: |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
922 return self.menus[(type_, category, name)]['help_string'] |
101 | 923 except KeyError: |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
924 raise exceptions.DataError("Trying to access an unknown menu") |
101 | 925 |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
926 def callMenu(self, category, name, type_="NORMAL", profile_key='@NONE@'): |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
927 """ Call a dynamic menu |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
928 @param category: category of the menu to call |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
929 @param name: name of the menu to call |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
930 @param type_: type of the menu to call |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
931 @param profile_key: %(doc_profile_key)s |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
932 @return: XMLUI or empty string if it's a one shot menu |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
933 """ |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
934 # TODO: menus should use launchCallback |
101 | 935 profile = self.memory.getProfileName(profile_key) |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
936 if not profile: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
937 raise exceptions.ProfileUnknownError |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
938 menu_data = self.menus[(type_, category, name)] |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
939 callback = menu_data['callback'] |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
940 args = menu_data.get('callback_args', ()) |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
941 kwargs = menu_data.get('callback_kwargs', {}).copy() |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
942 kwargs["profile"] = profile |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
943 try: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
944 return defer.maybeDeferred(callback, *args, **kwargs) |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
945 except KeyError: |
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
946 raise exceptions.DataError("Trying to access an unknown menu (%(type)s/%(category)s/%(name)s)" % {'type': type_, 'category': category, 'name': name}) |