Mercurial > libervia-backend
annotate src/core/sat_main.py @ 2550:1d754bc14381
jp (base): new confirmOrQuit helper method to ask confirmation to user, and quit if he cancel
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 31 Mar 2018 18:21:56 +0200 |
parents | 27539029a662 |
children |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 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 |
2483 | 5 # Copyright (C) 2009-2018 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 |
1376
28fd9e838f8f
core: getRepositoryData now get the module in argument
Goffi <goffi@goffi.org>
parents:
1375
diff
changeset
|
20 import sat |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
21 from sat.core.i18n import _, languageSwitch |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
22 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
|
23 from twisted.internet import defer |
1037
6e975c6b0faf
core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents:
1032
diff
changeset
|
24 from twisted.words.protocols.jabber import jid |
0 | 25 from twisted.internet import reactor |
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
|
26 from wokkel.xmppim import RosterItem |
332 | 27 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
|
28 from sat.core import exceptions |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
29 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
30 log = getLogger(__name__) |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
31 from sat.core.constants import Const as C |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
32 from sat.memory import memory |
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
33 from sat.memory import cache |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1365
diff
changeset
|
34 from sat.tools import trigger |
1375
3a20312d4012
core: if we are in dev version and it's possible, repository data are now checked and added to SàT version
Goffi <goffi@goffi.org>
parents:
1374
diff
changeset
|
35 from sat.tools import utils |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
36 from sat.tools.common import dynamic_import |
2496
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
37 from sat.tools.common import regex |
1032
b262ae6d53af
stdui: add ui_profile_manager to interact with frontends when profile authentication is needed
souliane <souliane@mailoo.org>
parents:
1030
diff
changeset
|
38 from sat.stdui import ui_contact_list, ui_profile_manager |
2105
c96fe007ca41
core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
39 import sat.plugins |
0 | 40 from glob import glob |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
41 import sys |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
42 import os.path |
1467
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
43 import uuid |
0 | 44 |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
45 try: |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
46 from collections import OrderedDict # only available from python 2.7 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
47 except ImportError: |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
48 from ordereddict import OrderedDict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
49 |
0 | 50 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
51 class SAT(service.Service): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
52 |
0 | 53 def __init__(self): |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
54 self._cb_map = {} # map from callback_id to callbacks |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
55 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) |
2126 | 56 self._menus_paths = {} # path to id. key: (menu_type, lower case tuple of path), value: menu id |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
57 self.initialised = defer.Deferred() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
58 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
|
59 self.plugins = {} |
2496
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
60 self.ns_map = {u'x-data': u'jabber:x:data'} # map for short name to whole namespace, |
2474
e04c874ace79
core: 'x-data' namespace is now registered
Goffi <goffi@goffi.org>
parents:
2445
diff
changeset
|
61 # extended by plugins with registerNamespace |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
62 self.memory = memory.Memory(self) |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1365
diff
changeset
|
63 self.trigger = 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
|
64 |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
65 bridge_name = self.memory.getConfig('', 'bridge', 'dbus') |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
66 |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
67 bridge_module = dynamic_import.bridge(bridge_name) |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
68 if bridge_module is None: |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
69 log.error(u"Can't find bridge module of name {}".format(bridge_name)) |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
70 sys.exit(1) |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
71 log.info(u"using {} bridge".format(bridge_name)) |
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
|
72 try: |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
73 self.bridge = bridge_module.Bridge() |
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
|
74 except exceptions.BridgeInitError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
75 log.error(u"Bridge can't be initialised, can't start SàT core") |
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
|
76 sys.exit(1) |
2086 | 77 self.bridge.register_method("getReady", lambda: self.initialised) |
78 self.bridge.register_method("getVersion", lambda: self.full_version) | |
79 self.bridge.register_method("getFeatures", self.getFeatures) | |
2168
255830fdb80b
core, bridge: renamed getProfileName to profileNameGet according to new conventions
Goffi <goffi@goffi.org>
parents:
2167
diff
changeset
|
80 self.bridge.register_method("profileNameGet", self.memory.getProfileName) |
2146
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
81 self.bridge.register_method("profilesListGet", self.memory.getProfilesList) |
2086 | 82 self.bridge.register_method("getEntityData", lambda jid_, keys, profile: self.memory.getEntityData(jid.JID(jid_), keys, profile)) |
83 self.bridge.register_method("getEntitiesData", self.memory._getEntitiesData) | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
84 self.bridge.register_method("profileCreate", self.memory.createProfile) |
2086 | 85 self.bridge.register_method("asyncDeleteProfile", self.memory.asyncDeleteProfile) |
86 self.bridge.register_method("profileStartSession", self.memory.startSession) | |
87 self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted) | |
88 self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault) | |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
89 self.bridge.register_method("connect", self._connect) |
2086 | 90 self.bridge.register_method("disconnect", self.disconnect) |
91 self.bridge.register_method("getContacts", self.getContacts) | |
92 self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup) | |
93 self.bridge.register_method("getMainResource", self.memory._getMainResource) | |
94 self.bridge.register_method("getPresenceStatuses", self.memory._getPresenceStatuses) | |
95 self.bridge.register_method("getWaitingSub", self.memory.getWaitingSub) | |
96 self.bridge.register_method("messageSend", self._messageSend) | |
97 self.bridge.register_method("getConfig", self._getConfig) | |
98 self.bridge.register_method("setParam", self.setParam) | |
99 self.bridge.register_method("getParamA", self.memory.getStringParamA) | |
100 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA) | |
101 self.bridge.register_method("asyncGetParamsValuesFromCategory", self.memory.asyncGetParamsValuesFromCategory) | |
102 self.bridge.register_method("getParamsUI", self.memory.getParamsUI) | |
103 self.bridge.register_method("getParamsCategories", self.memory.getParamsCategories) | |
104 self.bridge.register_method("paramsRegisterApp", self.memory.paramsRegisterApp) | |
105 self.bridge.register_method("historyGet", self.memory._historyGet) | |
106 self.bridge.register_method("setPresence", self._setPresence) | |
107 self.bridge.register_method("subscription", self.subscription) | |
108 self.bridge.register_method("addContact", self._addContact) | |
109 self.bridge.register_method("updateContact", self._updateContact) | |
110 self.bridge.register_method("delContact", self._delContact) | |
111 self.bridge.register_method("isConnected", self.isConnected) | |
112 self.bridge.register_method("launchAction", self.launchCallback) | |
113 self.bridge.register_method("actionsGet", self.actionsGet) | |
114 self.bridge.register_method("progressGet", self._progressGet) | |
115 self.bridge.register_method("progressGetAll", self._progressGetAll) | |
2126 | 116 self.bridge.register_method("menusGet", self.getMenus) |
117 self.bridge.register_method("menuHelpGet", self.getMenuHelp) | |
118 self.bridge.register_method("menuLaunch", self._launchMenu) | |
2086 | 119 self.bridge.register_method("discoInfos", self.memory.disco._discoInfos) |
120 self.bridge.register_method("discoItems", self.memory.disco._discoItems) | |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
121 self.bridge.register_method("discoFindByFeatures", self._findByFeatures) |
2086 | 122 self.bridge.register_method("saveParamsTemplate", self.memory.save_xml) |
123 self.bridge.register_method("loadParamsTemplate", self.memory.load_xml) | |
2113
9c861d07b5b6
core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents:
2105
diff
changeset
|
124 self.bridge.register_method("sessionInfosGet", self.getSessionInfos) |
2443
81a45e7886c9
core: added a mechanism to associate short names to namespaces:
Goffi <goffi@goffi.org>
parents:
2431
diff
changeset
|
125 self.bridge.register_method("namespacesGet", self.getNamespaces) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
126 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
127 self.memory.initialized.addCallback(self._postMemoryInit) |
0 | 128 |
1550 | 129 @property |
130 def version(self): | |
131 """Return the short version of SàT""" | |
132 return C.APP_VERSION | |
133 | |
134 @property | |
135 def full_version(self): | |
2147
bca699faf416
core: added release name in constants + full version
Goffi <goffi@goffi.org>
parents:
2146
diff
changeset
|
136 """Return the full version of SàT (with release name and extra data when in development mode)""" |
1550 | 137 version = self.version |
138 if version[-1] == 'D': | |
139 # we are in debug version, we add extra data | |
140 try: | |
141 return self._version_cache | |
142 except AttributeError: | |
2147
bca699faf416
core: added release name in constants + full version
Goffi <goffi@goffi.org>
parents:
2146
diff
changeset
|
143 self._version_cache = u"{} « {} » ({})".format(version, C.APP_RELEASE_NAME, utils.getRepositoryData(sat)) |
1550 | 144 return self._version_cache |
145 else: | |
146 return version | |
147 | |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
148 @property |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
149 def bridge_name(self): |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
150 return os.path.splitext(os.path.basename(self.bridge.__file__))[0] |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
151 |
412 | 152 def _postMemoryInit(self, ignore): |
153 """Method called after memory initialization is done""" | |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
154 self.common_cache = cache.Cache(self, None) |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
155 log.info(_("Memory initialised")) |
2262
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
156 try: |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
157 self._import_plugins() |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
158 ui_contact_list.ContactList(self) |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
159 ui_profile_manager.ProfileManager(self) |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
160 except Exception as e: |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
161 log.error(_(u"Could not initialize backend: {reason}").format( |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
162 reason = str(e).decode('utf-8', 'ignore'))) |
24f5a4d5f195
core: check uncatched exceptions during plugin import and stdui init, log error and exit if any found
Goffi <goffi@goffi.org>
parents:
2251
diff
changeset
|
163 sys.exit(1) |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
164 self.initialised.callback(None) |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2088
diff
changeset
|
165 log.info(_(u"Backend is ready")) |
0 | 166 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
167 def _unimport_plugin(self, plugin_path): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
168 """remove a plugin from sys.modules if it is there""" |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
169 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
170 del sys.modules[plugin_path] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
171 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
172 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
173 |
0 | 174 def _import_plugins(self): |
175 """Import all plugins found in plugins directory""" | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
176 # FIXME: module imported but cancelled should be deleted |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
177 # TODO: make this more generic and reusable in tools.common |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
178 # FIXME: should use imp |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
179 # TODO: do not import all plugins if no needed: component plugins are not needed if we |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
180 # just use a client, and plugin blacklisting should be possible in sat.conf |
2105
c96fe007ca41
core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
181 plugins_path = os.path.dirname(sat.plugins.__file__) |
c96fe007ca41
core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents:
2100
diff
changeset
|
182 plugin_glob = "plugin*." + C.PLUGIN_EXT |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2088
diff
changeset
|
183 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename, glob(os.path.join(plugins_path, plugin_glob)))] |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
184 plugins_to_import = {} # plugins we still have to import |
0 | 185 for plug in plug_lst: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
186 plugin_path = 'sat.plugins.' + plug |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
187 try: |
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
188 __import__(plugin_path) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
189 except exceptions.MissingModule as e: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
190 self._unimport_plugin(plugin_path) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
191 log.warning(u"Can't import plugin [{path}] because of an unavailale third party module:\n{msg}".format( |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
192 path=plugin_path, msg=e)) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
193 continue |
2100 | 194 except exceptions.CancelError as e: |
195 log.info(u"Plugin [{path}] cancelled its own import: {msg}".format(path=plugin_path, msg=e)) | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
196 self._unimport_plugin(plugin_path) |
2100 | 197 continue |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
198 except Exception as e: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
199 import traceback |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
200 log.error(_(u"Can't import plugin [{path}]:\n{error}").format(path=plugin_path, error=traceback.format_exc())) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
201 self._unimport_plugin(plugin_path) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
202 continue |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
203 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
204 plugin_info = mod.PLUGIN_INFO |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
205 import_name = plugin_info['import_name'] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
206 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
207 plugin_modes = plugin_info[u'modes'] = set(plugin_info.setdefault(u"modes", C.PLUG_MODE_DEFAULT)) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
208 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
209 # if the plugin is an entry point, it must work in component mode |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
210 if plugin_info[u'type'] == C.PLUG_TYPE_ENTRY_POINT: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
211 # if plugin is an entrypoint, we cache it |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
212 if C.PLUG_MODE_COMPONENT not in plugin_modes: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
213 log.error(_(u"{type} type must be used with {mode} mode, ignoring plugin").format( |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
214 type = C.PLUG_TYPE_ENTRY_POINT, mode = C.PLUG_MODE_COMPONENT)) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
215 self._unimport_plugin(plugin_path) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
216 continue |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
217 |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
218 if import_name in plugins_to_import: |
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
219 log.error(_(u"Name conflict for import name [{import_name}], can't import plugin [{name}]").format(**plugin_info)) |
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
220 continue |
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
221 plugins_to_import[import_name] = (plugin_path, mod, plugin_info) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
222 while True: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
223 try: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
224 self._import_plugins_from_dict(plugins_to_import) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
225 except ImportError: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
226 pass |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
227 if not plugins_to_import: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
228 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
229 |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
230 def _import_plugins_from_dict(self, plugins_to_import, import_name=None, optional=False): |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
231 """Recursively import and their dependencies in the right order |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
232 |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
233 @param plugins_to_import(dict): key=import_name and values=(plugin_path, module, plugin_info) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
234 @param import_name(unicode, None): name of the plugin to import as found in PLUGIN_INFO['import_name'] |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
235 @param optional(bool): if False and plugin is not found, an ImportError exception is raised |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
236 """ |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
237 if import_name in self.plugins: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
238 log.debug(u'Plugin {} already imported, passing'.format(import_name)) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
239 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
240 if not import_name: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
241 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
|
242 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
243 if not import_name in plugins_to_import: |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
244 if optional: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
245 log.warning(_(u"Recommended plugin not found: {}").format(import_name)) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
246 return |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
247 msg = u"Dependency not found: {}".format(import_name) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
248 log.error(msg) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
249 raise ImportError(msg) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
250 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
|
251 dependencies = plugin_info.setdefault("dependencies", []) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
252 recommendations = plugin_info.setdefault("recommendations", []) |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
253 for to_import in dependencies + recommendations: |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
254 if to_import not in self.plugins: |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
255 log.debug(u'Recursively import dependency of [%s]: [%s]' % (import_name, to_import)) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
256 try: |
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
257 self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies) |
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
258 except ImportError as e: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
259 log.warning(_(u"Can't import plugin {name}: {error}").format(name=plugin_info['name'], error=e)) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
260 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
261 return |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
262 raise e |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
263 log.info("importing plugin: {}".format(plugin_info['name'])) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
264 # we instanciate the plugin here |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
265 try: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
266 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
267 except Exception as e: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
268 log.warning(u'Error while loading plugin "{name}", ignoring it: {error}' |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
269 .format(name=plugin_info['name'], error=e)) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
270 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
271 return |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
272 raise ImportError(u"Error during initiation") |
2525
e8e1507049b7
core: use C.bool to detect value of "handler" field in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2509
diff
changeset
|
273 if C.bool(plugin_info.get(C.PI_HANDLER, C.BOOL_FALSE)): |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
274 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
275 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
276 self.plugins[import_name].is_handler = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
277 # we keep metadata as a Class attribute |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
278 self.plugins[import_name]._info = plugin_info |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
279 #TODO: test xmppclient presence and register handler parent |
0 | 280 |
1550 | 281 def pluginsUnload(self): |
282 """Call unload method on every loaded plugin, if exists | |
283 | |
284 @return (D): A deferred which return None when all method have been called | |
285 """ | |
286 # TODO: in the futur, it should be possible to hot unload a plugin | |
287 # pluging depending on the unloaded one should be unloaded too | |
288 # for now, just a basic call on plugin.unload is done | |
289 defers_list = [] | |
290 for plugin in self.plugins.itervalues(): | |
291 try: | |
292 unload = plugin.unload | |
293 except AttributeError: | |
294 continue | |
295 else: | |
296 defers_list.append(defer.maybeDeferred(unload)) | |
297 return defers_list | |
298 | |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
299 def _connect(self, profile_key, password='', options=None): |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
300 profile = self.memory.getProfileName(profile_key) |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
301 return self.connect(profile, password, options) |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
302 |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
303 def connect(self, profile, password='', options=None, max_retries=C.XMPP_MAX_RETRIES): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
304 """Connect a profile (i.e. connect client.component to XMPP server) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
305 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
306 Retrieve the individual parameters, authenticate the profile |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1027
diff
changeset
|
307 and initiate the connection to the associated XMPP server. |
1725
c1be6363bfab
core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents:
1694
diff
changeset
|
308 @param profile: %(doc_profile)s |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1027
diff
changeset
|
309 @param password (string): the SàT profile password |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
310 @param options (dict): connection options. Key can be: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
311 - |
1725
c1be6363bfab
core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents:
1694
diff
changeset
|
312 @param max_retries (int): max number of connection retries |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
313 @return (D(bool)): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
314 - True if the XMPP connection was already established |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
315 - False if the XMPP connection has been initiated (it may still fail) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
316 @raise exceptions.PasswordError: Profile password is wrong |
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
|
317 """ |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
318 if options is None: |
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
319 options={} |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
320 def connectProfile(dummy=None): |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
321 if self.isConnected(profile): |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
322 log.info(_("already connected !")) |
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
323 return True |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
324 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
325 if self.memory.isComponent(profile): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
326 d = xmpp.SatXMPPComponent.startConnection(self, profile, max_retries) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
327 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
328 d = xmpp.SatXMPPClient.startConnection(self, profile, max_retries) |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
329 return d.addCallback(lambda dummy: False) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
330 |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
331 d = self.memory.startSession(password, profile) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
332 d.addCallback(connectProfile) |
1591
0df9c6247474
core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents:
1587
diff
changeset
|
333 return d |
1019 | 334 |
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
|
335 def disconnect(self, profile_key): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
336 """disconnect from jabber server""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
337 # FIXME: client should not be deleted if only disconnected |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
338 # it shoud be deleted only when session is finished |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
339 if not self.isConnected(profile_key): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
340 # isConnected is checked here and not on client |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
341 # because client is deleted when session is ended |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
342 log.info(_(u"not connected !")) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
343 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
344 client = self.getClient(profile_key) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
345 return client.entityDisconnect() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
346 |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
347 def getFeatures(self, profile_key=C.PROF_KEY_NONE): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
348 """Get available features |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
349 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
350 Return list of activated plugins and plugin specific data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
351 @param profile_key: %(doc_profile_key)s |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
352 C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile dependent) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
353 @return (dict)[Deferred]: features data where: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
354 - key is plugin import name, present only for activated plugins |
1650
b08b828a87c9
quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents:
1644
diff
changeset
|
355 - value is a an other dict, when meaning is specific to each plugin. |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
356 this dict is return by plugin's getFeature method. |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
357 If this method doesn't exists, an empty dict is returned. |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
358 """ |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
359 try: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
360 # FIXME: there is no method yet to check profile session |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
361 # as soon as one is implemented, it should be used here |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
362 self.getClient(profile_key) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
363 except KeyError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
364 log.warning("Requesting features for a profile outside a session") |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
365 profile_key = C.PROF_KEY_NONE |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
366 except exceptions.ProfileNotSetError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
367 pass |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
368 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
369 features = [] |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
370 for import_name, plugin in self.plugins.iteritems(): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
371 try: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
372 features_d = defer.maybeDeferred(plugin.getFeatures, profile_key) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
373 except AttributeError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
374 features_d = defer.succeed({}) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
375 features.append(features_d) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
376 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
377 d_list = defer.DeferredList(features) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
378 def buildFeatures(result, import_names): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
379 assert len(result) == len(import_names) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
380 ret = {} |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
381 for name, (success, data) in zip (import_names, result): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
382 if success: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
383 ret[name] = data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
384 else: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
385 log.warning(u"Error while getting features for {name}: {failure}".format( |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
386 name=name, failure=data)) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
387 ret[name] = {} |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
388 return ret |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
389 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
390 d_list.addCallback(buildFeatures, self.plugins.keys()) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
391 return d_list |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
392 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
393 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
|
394 client = self.getClient(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
395 def got_roster(dummy): |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
396 ret = [] |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
397 for item in client.roster.getItems(): # we get all items for client's roster |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
398 # and convert them to expected format |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
399 attr = client.roster.getAttributes(item) |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
400 ret.append([item.jid.userhost(), attr, item.groups]) |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
401 return ret |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
402 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
403 return client.roster.got_roster.addCallback(got_roster) |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
404 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
405 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
|
406 client = self.getClient(profile_key) |
941
c6d8fc63b1db
core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents:
930
diff
changeset
|
407 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
|
408 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
409 def purgeEntity(self, profile): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
410 """Remove reference to a profile client/component and purge cache |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
411 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
412 the garbage collector can then free the memory |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
413 """ |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
414 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
415 del self.profiles[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
416 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
417 log.error(_("Trying to remove reference to a client not referenced")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
418 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
419 self.memory.purgeProfileSession(profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
420 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
421 def startService(self): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
422 log.info(u"Salut à toi ô mon frère !") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
423 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
424 def stopService(self): |
1007
a7d33c7a8277
core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents:
999
diff
changeset
|
425 log.info(u"Salut aussi à Rantanplan") |
1550 | 426 return self.pluginsUnload() |
0 | 427 |
428 def run(self): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
429 log.debug(_("running app")) |
0 | 430 reactor.run() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
431 |
0 | 432 def stop(self): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
433 log.debug(_("stopping app")) |
0 | 434 reactor.stop() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
435 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
436 ## Misc methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
437 |
64 | 438 def getJidNStream(self, profile_key): |
439 """Convenient method to get jid and stream from profile key | |
440 @return: tuple (jid, xmlstream) from profile, can be None""" | |
1573
6338677f3a89
core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents:
1550
diff
changeset
|
441 # TODO: deprecate this method (getClient is enough) |
64 | 442 profile = self.memory.getProfileName(profile_key) |
443 if not profile or not self.profiles[profile].isConnected(): | |
444 return (None, None) | |
445 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
446 | |
447 def getClient(self, profile_key): | |
448 """Convenient method to get client from profile key | |
1624 | 449 |
450 @return: client or None if it doesn't exist | |
451 @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist | |
452 @raise exceptions.NotFound: client is not available | |
2176
61128d260eef
plugin account: removed dependency to Prosody/prosodyctl and properly use in-band registration instead
Goffi <goffi@goffi.org>
parents:
2168
diff
changeset
|
453 This happen if profile has not been used yet |
1624 | 454 """ |
64 | 455 profile = self.memory.getProfileName(profile_key) |
456 if not profile: | |
1624 | 457 raise exceptions.ProfileKeyUnknown |
458 try: | |
459 return self.profiles[profile] | |
460 except KeyError: | |
2445
0199c0bd4c60
core: specify profile on NotFound exception
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
461 raise exceptions.NotFound(profile_key) |
64 | 462 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
463 def getClients(self, profile_key): |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
464 """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
465 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
466 @param profile_key: %(doc_profile_key)s |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
467 @return: list of clients |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
468 """ |
2251
83bcd9ec4782
core: fixed profile key detection in getClients + raise DataError on empty profile
Goffi <goffi@goffi.org>
parents:
2176
diff
changeset
|
469 if not profile_key: |
83bcd9ec4782
core: fixed profile key detection in getClients + raise DataError on empty profile
Goffi <goffi@goffi.org>
parents:
2176
diff
changeset
|
470 raise exceptions.DataError(_(u'profile_key must not be empty')) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
471 try: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
472 profile = self.memory.getProfileName(profile_key, True) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
473 except exceptions.ProfileUnknownError: |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
474 return [] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
475 if profile == C.PROF_KEY_ALL: |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
476 return self.profiles.values() |
2251
83bcd9ec4782
core: fixed profile key detection in getClients + raise DataError on empty profile
Goffi <goffi@goffi.org>
parents:
2176
diff
changeset
|
477 elif profile[0] == '@': # only profile keys can start with "@" |
1624 | 478 raise exceptions.ProfileKeyUnknown |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
479 return [self.profiles[profile]] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
480 |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
481 def _getConfig(self, section, name): |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
482 """Get the main configuration option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
483 |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
484 @param section: section of the config file (None or '' for DEFAULT) |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
485 @param name: name of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
486 @return: unicode representation of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
487 """ |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
488 return unicode(self.memory.getConfig(section, name, '')) |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
489 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
490 def logErrback(self, failure_): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
491 """generic errback logging |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
492 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
493 can be used as last errback to show unexpected error |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
494 """ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
495 log.error(_(u"Unexpected error: {}".format(failure_))) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
496 return failure_ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
497 |
2496
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
498 # namespaces |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
499 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
500 def registerNamespace(self, short_name, namespace): |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
501 """associate a namespace to a short name""" |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
502 if short_name in self.ns_map: |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
503 raise exceptions.ConflictError(u'this short name is already used') |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
504 self.ns_map[short_name] = namespace |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
505 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
506 def getNamespaces(self): |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
507 return self.ns_map |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
508 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
509 def getSessionInfos(self, profile_key): |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
510 """compile interesting data on current profile session""" |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
511 client = self.getClient(profile_key) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
512 data = { |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
513 "jid": client.jid.full(), |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
514 "started": unicode(int(client.started)), |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
515 } |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
516 return defer.succeed(data) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
517 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
518 # local dirs |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
519 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
520 def getLocalPath(self, client, dir_name, *extra_path, **kwargs): |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
521 """retrieve path for local data |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
522 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
523 if path doesn't exist, it will be created |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
524 @param client(SatXMPPClient, None): client instance |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
525 used when profile is set, can be None if profile is False |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
526 @param dir_name(unicode): name of the main path directory |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
527 @param component(bool): if True, path will be prefixed with C.COMPONENTS_DIR |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
528 @param profile(bool): if True, path will be suffixed by profile name |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
529 @param *extra_path: extra path element(s) to use |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
530 @return (unicode): path |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
531 """ |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
532 # FIXME: component and profile are parsed with **kwargs because of python 2 limitations |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
533 # once moved to python 3, this can be fixed |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
534 component = kwargs.pop('component', False) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
535 profile = kwargs.pop('profile', True) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
536 assert not kwargs |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
537 |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
538 path_elts = [self.memory.getConfig('', 'local_dir')] |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
539 if component: |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
540 path_elts.append(C.COMPONENTS_DIR) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
541 path_elts.append(regex.pathEscape(dir_name)) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
542 if extra_path: |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
543 path_elts.extend([regex.pathEscape(p) for p in extra_path]) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
544 if profile: |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
545 regex.pathEscape(client.profile) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
546 path = os.path.join(*path_elts) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
547 if not os.path.exists(path): |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
548 os.makedirs(path) |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
549 return path |
769e8d9d2438
core: new getLocalPath method to retrieve a path in SàT local dir, which may be specific to a profile or component
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
550 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
551 ## Client management ## |
0 | 552 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
553 def setParam(self, name, value, category, security_limit, profile_key): |
0 | 554 """set wanted paramater and notice observers""" |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
555 self.memory.setParam(name, value, category, security_limit, profile_key) |
0 | 556 |
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
|
557 def isConnected(self, profile_key): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
558 """Return connection status of profile |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
559 @param profile_key: key_word or profile name to determine profile name |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1027
diff
changeset
|
560 @return: True if connected |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
561 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
562 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
563 if not profile: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
564 log.error(_('asking connection status for a non-existant profile')) |
1030
15f43b54d697
core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents:
1027
diff
changeset
|
565 raise exceptions.ProfileUnknownError(profile_key) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
566 if profile not in self.profiles: |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
567 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
568 return self.profiles[profile].isConnected() |
0 | 569 |
1052
e88bff4c8b77
core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents:
1043
diff
changeset
|
570 ## XMPP methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
571 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
572 def _messageSend(self, to_jid_s, message, subject=None, mess_type='auto', extra=None, profile_key=C.PROF_KEY_NONE): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
573 client = self.getClient(profile_key) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
574 to_jid = jid.JID(to_jid_s) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
575 #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 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
576 return client.sendMessage(to_jid, message, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
577 |
917
a9401694d2dc
bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
578 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): |
a9401694d2dc
bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
579 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
580 |
917
a9401694d2dc
bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
581 def setPresence(self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE): |
0 | 582 """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
|
583 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
|
584 statuses = {} |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
585 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
586 assert profile |
917
a9401694d2dc
bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents:
916
diff
changeset
|
587 priority = int(self.memory.getParamA("Priority", "Connection", profile_key=profile)) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
588 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
|
589 #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
|
590 if '' in statuses: |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
591 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop('') |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
592 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
|
593 int(priority), statuses, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
594 |
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
|
595 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
|
596 """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
|
597 @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
|
598 @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
|
599 @param profile_key: profile""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
600 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
601 assert profile |
50 | 602 to_jid = jid.JID(raw_jid) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
603 log.debug(_(u'subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()}) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
604 if subs_type == "subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
605 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
|
606 elif subs_type == "subscribed": |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
607 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
|
608 elif subs_type == "unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
609 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
|
610 elif subs_type == "unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
611 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 612 |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
613 def _addContact(self, to_jid_s, profile_key): |
846
59d486726577
core: fix mispelled argument
souliane <souliane@mailoo.org>
parents:
834
diff
changeset
|
614 return self.addContact(jid.JID(to_jid_s), profile_key) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
615 |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
616 def addContact(self, to_jid, profile_key): |
0 | 617 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
618 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
619 assert profile |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
620 # presence is sufficient, as a roster push will be sent according to RFC 6121 §3.1.2 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
621 self.profiles[profile].presence.subscribe(to_jid) |
0 | 622 |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
623 def _updateContact(self, to_jid_s, name, groups, profile_key): |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
624 return self.updateContact(jid.JID(to_jid_s), name, groups, profile_key) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
625 |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
626 def updateContact(self, to_jid, name, groups, profile_key): |
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
|
627 """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
|
628 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
629 assert profile |
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
|
630 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
|
631 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
|
632 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
|
633 roster_item.groups = set(groups) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
634 return self.profiles[profile].roster.setItem(roster_item) |
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
|
635 |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
636 def _delContact(self, to_jid_s, profile_key): |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
637 return self.delContact(jid.JID(to_jid_s), profile_key) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
638 |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
806
diff
changeset
|
639 def delContact(self, to_jid, profile_key): |
0 | 640 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
641 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
642 assert profile |
1355
33a21f06551d
core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents:
1325
diff
changeset
|
643 self.profiles[profile].presence.unsubscribe(to_jid) # is not asynchronous |
33a21f06551d
core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents:
1325
diff
changeset
|
644 return self.profiles[profile].roster.removeItem(to_jid) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
645 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
646 ## Discovery ## |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
647 # discovery methods are shortcuts to self.memory.disco |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
648 # the main difference with client.disco is that self.memory.disco manage cache |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
649 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
650 def hasFeature(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
651 return self.memory.disco.hasFeature(*args, **kwargs) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
652 |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
653 def checkFeature(self, *args, **kwargs): |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
654 return self.memory.disco.checkFeature(*args, **kwargs) |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
655 |
1491
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1482
diff
changeset
|
656 def checkFeatures(self, *args, **kwargs): |
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1482
diff
changeset
|
657 return self.memory.disco.checkFeatures(*args, **kwargs) |
704ca56f5ca9
core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents:
1482
diff
changeset
|
658 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
659 def getDiscoInfos(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
660 return self.memory.disco.getInfos(*args, **kwargs) |
0 | 661 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
662 def getDiscoItems(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
663 return self.memory.disco.getItems(*args, **kwargs) |
0 | 664 |
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
665 def findServiceEntity(self, *args, **kwargs): |
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
666 return self.memory.disco.findServiceEntity(*args, **kwargs) |
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
667 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
668 def findServiceEntities(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
669 return self.memory.disco.findServiceEntities(*args, **kwargs) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
670 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
671 def findFeaturesSet(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
672 return self.memory.disco.findFeaturesSet(*args, **kwargs) |
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
|
673 |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
674 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, profile_key): |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
675 client = self.getClient(profile_key) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
676 return self.findByFeatures(client, namespaces, identities, bare_jids, service, roster, own_jid) |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
677 |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
678 @defer.inlineCallbacks |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
679 def findByFeatures(self, client, namespaces, identities=None, bare_jids=False, service=True, roster=True, own_jid=True): |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
680 """retrieve all services or contacts managing a set a features |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
681 |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
682 @param namespaces(list[unicode]): features which must be handled |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
683 @param identities(list[tuple[unicode,unicode]], None): if not None or empty, only keep those identities |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
684 tuple must by (category, type) |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
685 @param bare_jids(bool): retrieve only bare_jids if True |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
686 if False, retrieve full jid of connected devices |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
687 @param service(bool): if True return service from our roster |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
688 @param roster(bool): if True, return entities in roster |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
689 full jid of all matching resources available will be returned |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
690 @param own_jid(bool): if True, return profile's jid resources |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
691 @return (tuple(dict[jid.JID(), tuple[unicode, unicode, unicode]]*3)): found entities in a tuple with: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
692 - service entities |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
693 - own entities |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
694 - roster entities |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
695 """ |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
696 if not identities: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
697 identities = None |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
698 if not namespaces and not identities: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
699 raise exceptions.DataError("at least one namespace or one identity must be set") |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
700 found_service = {} |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
701 found_own = {} |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
702 found_roster = {} |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
703 if service: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
704 services_jids = yield self.findFeaturesSet(client, namespaces) |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
705 for service_jid in services_jids: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
706 infos = yield self.getDiscoInfos(client, service_jid) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
707 if identities is not None and not set(infos.identities.keys()).issuperset(identities): |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
708 continue |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
709 found_identities = [(cat, type_, name or u'') for (cat, type_), name in infos.identities.iteritems()] |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
710 found_service[service_jid.full()] = found_identities |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
711 |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
712 jids = [] |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
713 if roster: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
714 jids.extend(client.roster.getJids()) |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
715 if own_jid: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
716 jids.append(client.jid.userhostJID()) |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
717 |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
718 for found, jids in ((found_own, [client.jid.userhostJID()]), |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
719 (found_roster, client.roster.getJids())): |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
720 for jid_ in jids: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
721 if jid_.resource: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
722 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
723 continue |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
724 resources = [jid_.resource] |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
725 else: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
726 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
727 resources = [None] |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
728 else: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
729 try: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
730 resources = self.memory.getAllResources(client, jid_) |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
731 except exceptions.UnknownEntityError: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
732 continue |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
733 for resource in resources: |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
734 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
735 infos = yield self.getDiscoInfos(client, full_jid) |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
736 if infos.features.issuperset(namespaces): |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
737 if identities is not None and not set(infos.identities.keys()).issuperset(identities): |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
738 continue |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
739 found_identities = [(cat, type_, name or u'') for (cat, type_), name in infos.identities.iteritems()] |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
740 found[full_jid.full()] = found_identities |
2534
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
741 |
7da86e1633a5
core: new discoFindFeatures method which return all server services/roster entities implementing a set of features.
Goffi <goffi@goffi.org>
parents:
2525
diff
changeset
|
742 defer.returnValue((found_service, found_own, found_roster)) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
743 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
744 ## Generic HMI ## |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
745 |
1622 | 746 def _killAction(self, keep_id, client): |
747 log.debug(u"Killing action {} for timeout".format(keep_id)) | |
748 client.actions[keep_id] | |
749 | |
750 def actionNew(self, action_data, security_limit=C.NO_SECURITY_LIMIT, keep_id=None, profile=C.PROF_KEY_NONE): | |
751 """Shortcut to bridge.actionNew which generate and id and keep for retrieval | |
1467
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
752 |
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
753 @param action_data(dict): action data (see bridge documentation) |
1599
e2ed8009e66e
backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
754 @param security_limit: %(doc_security_limit)s |
1622 | 755 @param keep_id(None, unicode): if not None, used to keep action for differed retrieval |
756 must be set to the callback_id | |
757 action will be deleted after 30 min. | |
1467
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
758 @param profile: %(doc_profile)s |
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
759 """ |
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
760 id_ = unicode(uuid.uuid4()) |
1622 | 761 if keep_id is not None: |
762 client = self.getClient(profile) | |
1644
98a2eb768bb0
core: fixed session cleaning after actionNew timeout
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
763 action_timer = reactor.callLater(60*30, self._killAction, keep_id, client) |
1622 | 764 client.actions[keep_id] = (action_data, id_, security_limit, action_timer) |
765 | |
1599
e2ed8009e66e
backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
766 self.bridge.actionNew(action_data, id_, security_limit, profile) |
1467
ceba6fd77739
core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents:
1417
diff
changeset
|
767 |
1622 | 768 def actionsGet(self, profile): |
769 """Return current non answered actions | |
770 | |
771 @param profile: %(doc_profile)s | |
772 """ | |
773 client = self.getClient(profile) | |
774 return [action_tuple[:-1] for action_tuple in client.actions.itervalues()] | |
775 | |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
776 def registerProgressCb(self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE): |
0 | 777 """Register a callback called when progress is requested for id""" |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
778 if metadata is None: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
779 metadata = {} |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
780 client = self.getClient(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
781 if progress_id in client._progress_cb: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
782 raise exceptions.ConflictError(u"Progress ID is not unique !") |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
783 client._progress_cb[progress_id] = (callback, metadata) |
0 | 784 |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
785 def removeProgressCb(self, progress_id, profile): |
0 | 786 """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
|
787 client = self.getClient(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
788 try: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
789 del client._progress_cb[progress_id] |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
790 except KeyError: |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1573
diff
changeset
|
791 log.error(_(u"Trying to remove an unknow progress callback")) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
792 |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
793 def _progressGet(self, progress_id, profile): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
794 data = self.progressGet(progress_id, profile) |
1598
b144babc2658
core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents:
1595
diff
changeset
|
795 return {k: unicode(v) for k,v in data.iteritems()} |
0 | 796 |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
797 def progressGet(self, progress_id, profile): |
0 | 798 """Return a dict with progress information |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
799 |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
800 @param progress_id(unicode): unique id of the progressing element |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
801 @param profile: %(doc_profile)s |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
802 @return (dict): data with the following keys: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
803 'position' (int): current possition |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
804 'size' (int): end_position |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
805 if id doesn't exists (may be a finished progression), and empty dict is returned |
0 | 806 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
807 client = self.getClient(profile) |
0 | 808 try: |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
809 data = client._progress_cb[progress_id][0](progress_id, profile) |
0 | 810 except KeyError: |
1598
b144babc2658
core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents:
1595
diff
changeset
|
811 data = {} |
0 | 812 return data |
813 | |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
814 def _progressGetAll(self, profile_key): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
815 progress_all = self.progressGetAll(profile_key) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
816 for profile, progress_dict in progress_all.iteritems(): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
817 for progress_id, data in progress_dict.iteritems(): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
818 for key, value in data.iteritems(): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
819 data[key] = unicode(value) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
820 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
821 |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
822 def progressGetAllMetadata(self, profile_key): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
823 """Return all progress metadata at once |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
824 |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
825 @param profile_key: %(doc_profile)s |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
826 if C.PROF_KEY_ALL is used, all progress metadata from all profiles are returned |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
827 @return (dict[dict[dict]]): a dict which map profile to progress_dict |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
828 progress_dict map progress_id to progress_data |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
829 progress_metadata is the same dict as sent by [progressStarted] |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
830 """ |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
831 clients = self.getClients(profile_key) |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
832 progress_all = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
833 for client in clients: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
834 profile = client.profile |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
835 progress_dict = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
836 progress_all[profile] = progress_dict |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
837 for progress_id, (dummy, progress_metadata) in client._progress_cb.iteritems(): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
838 progress_dict[progress_id] = progress_metadata |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
839 return progress_all |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
840 |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
841 def progressGetAll(self, profile_key): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
842 """Return all progress status at once |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
843 |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
844 @param profile_key: %(doc_profile)s |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
845 if C.PROF_KEY_ALL is used, all progress status from all profiles are returned |
1598
b144babc2658
core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents:
1595
diff
changeset
|
846 @return (dict[dict[dict]]): a dict which map profile to progress_dict |
b144babc2658
core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents:
1595
diff
changeset
|
847 progress_dict map progress_id to progress_data |
b144babc2658
core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents:
1595
diff
changeset
|
848 progress_data is the same dict as returned by [progressGet] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
849 """ |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
850 clients = self.getClients(profile_key) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
851 progress_all = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
852 for client in clients: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
853 profile = client.profile |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
854 progress_dict = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
855 progress_all[profile] = progress_dict |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
856 for progress_id, (progress_cb, dummy) in client._progress_cb.iteritems(): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
857 progress_dict[progress_id] = progress_cb(progress_id, profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
858 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
859 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
860 def registerCallback(self, callback, *args, **kwargs): |
1603
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
861 """Register a callback. |
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
862 |
2126 | 863 @param callback(callable): method to call |
864 @param kwargs: can contain: | |
865 with_data(bool): True if the callback use the optional data dict | |
866 force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid if possible | |
867 one_shot(bool): True to delete callback once it have been called | |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
868 @return: id of the registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
869 """ |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
870 callback_id = kwargs.pop('force_id', None) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
871 if callback_id is None: |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2147
diff
changeset
|
872 callback_id = str(uuid.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
|
873 else: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
874 if callback_id in self._cb_map: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
875 raise exceptions.ConflictError(_(u"id already registered")) |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
876 self._cb_map[callback_id] = (callback, args, kwargs) |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
877 |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
878 if "one_shot" in kwargs: # One Shot callback are removed after 30 min |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
879 def purgeCallback(): |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
880 try: |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
881 self.removeCallback(callback_id) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
882 except KeyError: |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
883 pass |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
884 reactor.callLater(1800, purgeCallback) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
885 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
886 return callback_id |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
887 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
888 def removeCallback(self, callback_id): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
889 """ Remove a previously registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
890 @param callback_id: id returned by [registerCallback] """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
891 log.debug("Removing callback [%s]" % callback_id) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
892 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
|
893 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
894 def launchCallback(self, callback_id, data=None, profile_key=C.PROF_KEY_NONE): |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
895 """Launch a specific callback |
2126 | 896 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
897 @param callback_id: id of the action (callback) to launch |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
898 @param data: optional data |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
899 @profile_key: %(doc_profile_key)s |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
900 @return: a deferred which fire a dict where key can be: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
901 - xmlui: a XMLUI need to be displayed |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
902 - validated: if present, can be used to launch a callback, it can have the values |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
903 - C.BOOL_TRUE |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
904 - C.BOOL_FALSE |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
905 """ |
2126 | 906 # FIXME: security limit need to be checked here |
1622 | 907 try: |
1624 | 908 client = self.getClient(profile_key) |
909 except exceptions.NotFound: | |
910 # client is not available yet | |
911 profile = self.memory.getProfileName(profile_key) | |
912 if not profile: | |
2126 | 913 raise exceptions.ProfileUnknownError(_(u'trying to launch action with a non-existant profile')) |
1622 | 914 else: |
1624 | 915 profile = client.profile |
916 # we check if the action is kept, and remove it | |
917 try: | |
918 action_tuple = client.actions[callback_id] | |
919 except KeyError: | |
920 pass | |
921 else: | |
922 action_tuple[-1].cancel() # the last item is the action timer | |
923 del client.actions[callback_id] | |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
924 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
925 try: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
926 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
|
927 except KeyError: |
1603
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
928 raise exceptions.DataError(u"Unknown callback id {}".format(callback_id)) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
929 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
930 if kwargs.get("with_data", False): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
931 if data is None: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
932 raise exceptions.DataError("Required data for this callback is missing") |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
933 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
|
934 args.insert(0, data) |
1624 | 935 kwargs["profile"] = profile |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
936 del kwargs["with_data"] |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
937 |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
938 if kwargs.pop('one_shot', False): |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
939 self.removeCallback(callback_id) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
940 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
941 return defer.maybeDeferred(callback, *args, **kwargs) |
0 | 942 |
101 | 943 #Menus management |
944 | |
2126 | 945 def _getMenuCanonicalPath(self, path): |
946 """give canonical form of path | |
947 | |
948 canonical form is a tuple of the path were every element is stripped and lowercase | |
949 @param path(iterable[unicode]): untranslated path to menu | |
950 @return (tuple[unicode]): canonical form of path | |
951 """ | |
952 return tuple((p.lower().strip() for p in path)) | |
953 | |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
954 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, help_string="", type_=C.MENU_GLOBAL): |
101 | 955 """register a new menu for frontends |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
956 |
2126 | 957 @param path(iterable[unicode]): path to go to the menu (category/subcategory/.../item) (e.g.: ("File", "Open")) |
773 | 958 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open"))) |
2126 | 959 untranslated/lower case path can be used to identity a menu, for this reason it must be unique independently of case. |
960 @param callback(callable): method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback] | |
961 @param security_limit(int): %(doc_security_limit)s | |
809 | 962 /!\ security_limit MUST be added to data in launchCallback if used #TODO |
2126 | 963 @param help_string(unicode): string used to indicate what the menu do (can be show as a tooltip). |
773 | 964 /!\ use D_() instead of _() for translations |
2126 | 965 @param type(unicode): one of: |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
966 - C.MENU_GLOBAL: classical menu, can be shown in a menubar on top (e.g. something like File/Open) |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
967 - C.MENU_ROOM: like a global menu, but only shown in multi-user chat |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
968 menu_data must contain a "room_jid" data |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
969 - C.MENU_SINGLE: like a global menu, but only shown in one2one chat |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
970 menu_data must contain a "jid" data |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
971 - C.MENU_JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc commands, jid is already filled) |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
972 menu_data must contain a "jid" data |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
973 - C.MENU_ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster. |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
974 menu_data must contain a "room_jid" data |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
975 - C.MENU_ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish microblog, group is already filled) |
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
976 menu_data must contain a "group" data |
2126 | 977 @return (unicode): menu_id (same as callback_id) |
755
e3ad48a2aab2
core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents:
752
diff
changeset
|
978 """ |
773 | 979 |
980 if callable(callback): | |
981 callback_id = self.registerCallback(callback, with_data=True) | |
982 elif isinstance(callback, basestring): | |
983 # The callback is already registered | |
984 callback_id = callback | |
985 try: | |
986 callback, args, kwargs = self._cb_map[callback_id] | |
987 except KeyError: | |
988 raise exceptions.DataError("Unknown callback id") | |
989 kwargs["with_data"] = True # we have to be sure that we use extra data | |
990 else: | |
991 raise exceptions.DataError("Unknown callback type") | |
992 | |
993 for menu_data in self._menus.itervalues(): | |
994 if menu_data['path'] == path and menu_data['type'] == type_: | |
995 raise exceptions.ConflictError(_("A menu with the same path and type already exists")) | |
996 | |
2126 | 997 path_canonical = self._getMenuCanonicalPath(path) |
998 menu_key = (type_, path_canonical) | |
999 | |
1000 if menu_key in self._menus_paths: | |
1001 raise exceptions.ConflictError(u"this menu path is already used: {path} ({menu_key})".format( | |
1002 path=path_canonical, menu_key=menu_key)) | |
1003 | |
1004 menu_data = {'path': tuple(path), | |
1005 'path_canonical': path_canonical, | |
773 | 1006 'security_limit': security_limit, |
1007 'help_string': help_string, | |
1008 'type': type_ | |
1009 } | |
1010 | |
1011 self._menus[callback_id] = menu_data | |
2126 | 1012 self._menus_paths[menu_key] = callback_id |
773 | 1013 |
1014 return callback_id | |
101 | 1015 |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
1016 def getMenus(self, language='', security_limit=C.NO_SECURITY_LIMIT): |
773 | 1017 """Return all menus registered |
1365
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1018 |
773 | 1019 @param language: language used for translation, or empty string for default |
1020 @param security_limit: %(doc_security_limit)s | |
1021 @return: array of tuple with: | |
1022 - menu id (same as callback_id) | |
1023 - menu type | |
1024 - raw menu path (array of strings) | |
1025 - translated menu path | |
1365
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1026 - extra (dict(unicode, unicode)): extra data where key can be: |
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1027 - icon: name of the icon to use (TODO) |
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1028 - help_url: link to a page with more complete documentation (TODO) |
773 | 1029 """ |
1030 ret = [] | |
1031 for menu_id, menu_data in self._menus.iteritems(): | |
1032 type_ = menu_data['type'] | |
1033 path = menu_data['path'] | |
809 | 1034 menu_security_limit = menu_data['security_limit'] |
914
1a3ba959f0ab
core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents:
909
diff
changeset
|
1035 if security_limit!=C.NO_SECURITY_LIMIT and (menu_security_limit==C.NO_SECURITY_LIMIT or menu_security_limit>security_limit): |
809 | 1036 continue |
773 | 1037 languageSwitch(language) |
1038 path_i18n = [_(elt) for elt in path] | |
1039 languageSwitch() | |
1365
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1040 extra = {} # TODO: manage extra data like icon |
ba87b940f07a
core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents:
1355
diff
changeset
|
1041 ret.append((menu_id, type_, path, path_i18n, extra)) |
773 | 1042 |
1043 return ret | |
1044 | |
2126 | 1045 def _launchMenu(self, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
1046 client = self.getClient(profile_key) | |
1047 return self.launchMenu(client, menu_type, path, data, security_limit) | |
1048 | |
1049 def launchMenu(self, client, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT): | |
1050 """launch action a menu action | |
1051 | |
1052 @param menu_type(unicode): type of menu to launch | |
1053 @param path(iterable[unicode]): canonical path of the menu | |
1054 @params data(dict): menu data | |
1055 @raise NotFound: this path is not known | |
1056 """ | |
1057 # FIXME: manage security_limit here | |
1058 # defaut security limit should be high instead of C.NO_SECURITY_LIMIT | |
1059 canonical_path = self._getMenuCanonicalPath(path) | |
1060 menu_key = (menu_type, canonical_path) | |
1061 try: | |
1062 callback_id = self._menus_paths[menu_key] | |
1063 except KeyError: | |
1064 raise exceptions.NotFound(u"Can't find menu {path} ({menu_type})".format( | |
1065 path=canonical_path, menu_type=menu_type)) | |
1066 return self.launchCallback(callback_id, data, client.profile) | |
1067 | |
773 | 1068 def getMenuHelp(self, menu_id, language=''): |
2113
9c861d07b5b6
core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents:
2105
diff
changeset
|
1069 """return the help string of the menu |
9c861d07b5b6
core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents:
2105
diff
changeset
|
1070 |
773 | 1071 @param menu_id: id of the menu (same as callback_id) |
1072 @param language: language used for translation, or empty string for default | |
1073 @param return: translated help | |
1074 | |
1075 """ | |
101 | 1076 try: |
773 | 1077 menu_data = self._menus[menu_id] |
101 | 1078 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
|
1079 raise exceptions.DataError("Trying to access an unknown menu") |
773 | 1080 languageSwitch(language) |
1081 help_string = _(menu_data['help_string']) | |
1082 languageSwitch() | |
1083 return help_string |