Mercurial > libervia-backend
annotate sat/core/sat_main.py @ 3635:7bc443253b7c
merge branche "@"
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Aug 2021 15:32:58 +0200 |
parents | 888109774673 3c7a64d6f49f |
children | cbb988a6f507 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
0 | 2 |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3 # Libervia: an XMPP client |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
0 | 5 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
6 # 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
|
7 # 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
|
8 # 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
|
9 # (at your option) any later version. |
0 | 10 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 # GNU Affero General Public License for more details. |
0 | 15 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
605
diff
changeset
|
16 # 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
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
19 import sys |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
20 import os.path |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
21 import uuid |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
22 import hashlib |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
23 import copy |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
24 from pathlib import Path |
3295 | 25 from typing import Optional, List, Tuple, Dict |
1376
28fd9e838f8f
core: getRepositoryData now get the module in argument
Goffi <goffi@goffi.org>
parents:
1375
diff
changeset
|
26 import sat |
3120 | 27 from sat.core.i18n import _, D_, languageSwitch |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2666
diff
changeset
|
28 from sat.core import patches |
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2666
diff
changeset
|
29 patches.apply() |
331
0a8eb0461f31
core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents:
330
diff
changeset
|
30 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
|
31 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
|
32 from twisted.words.protocols.jabber import jid |
0 | 33 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
|
34 from wokkel.xmppim import RosterItem |
332 | 35 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
|
36 from sat.core import exceptions |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
37 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
38 |
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
|
39 from sat.core.constants import Const as C |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
40 from sat.memory import memory |
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
41 from sat.memory import cache |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
42 from sat.memory import encryption |
2645 | 43 from sat.tools import async_trigger as 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
|
44 from sat.tools import utils |
3220 | 45 from sat.tools import image |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
46 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
|
47 from sat.tools.common import regex |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
48 from sat.tools.common import data_format |
1032
b262ae6d53af
stdui: add ui_profile_manager to interact with frontends when profile authentication is needed
souliane <souliane@mailoo.org>
parents:
1030
diff
changeset
|
49 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
|
50 import sat.plugins |
0 | 51 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
52 |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
972
diff
changeset
|
53 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
54 from collections import OrderedDict # only available from python 2.7 |
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 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
|
56 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
|
57 |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
58 log = getLogger(__name__) |
0 | 59 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
60 class SAT(service.Service): |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
61 |
3110
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
62 def _init(self): |
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
63 # we don't use __init__ to avoid doule initialisation with twistd |
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
64 # this _init is called in startService |
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
65 log.info(f"{C.APP_NAME} {self.full_version}") |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
66 self._cb_map = {} # map from callback_id to callbacks |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
67 self._menus = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
68 OrderedDict() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
69 ) # dynamic menus. key: callback_id, value: menu data (dictionnary) |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
70 self._menus_paths = {} # path to id. key: (menu_type, lower case tuple of path), |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
71 # 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
|
72 self.initialised = defer.Deferred() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
73 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
|
74 self.plugins = {} |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
75 # map for short name to whole namespace, |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
76 # extended by plugins with registerNamespace |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
77 self.ns_map = { |
3028 | 78 "x-data": xmpp.NS_X_DATA, |
79 "disco#info": xmpp.NS_DISCO_INFO, | |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
80 } |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
81 |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
82 self.memory = memory.Memory(self) |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
83 |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
84 # trigger are used to change Libervia behaviour |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
85 self.trigger = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
86 trigger.TriggerManager() |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
87 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
88 |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
89 bridge_name = ( |
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
90 os.getenv("LIBERVIA_BRIDGE_NAME") |
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
91 or self.memory.getConfig("", "bridge", "dbus") |
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
92 ) |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
93 |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
94 bridge_module = dynamic_import.bridge(bridge_name) |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
95 if bridge_module is None: |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
96 log.error(f"Can't find bridge module of name {bridge_name}") |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
97 sys.exit(1) |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
98 log.info(f"using {bridge_name} 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
|
99 try: |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
100 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
|
101 except exceptions.BridgeInitError: |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
102 log.error("Bridge can't be initialised, can't start Libervia Backend") |
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
|
103 sys.exit(1) |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
104 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
105 defer.ensureDeferred(self._postInit()) |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
106 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
107 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
108 def version(self): |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
109 """Return the short version of Libervia""" |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
110 return C.APP_VERSION |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
111 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
112 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
113 def full_version(self): |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
114 """Return the full version of Libervia |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
115 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
116 In developement mode, release name and extra data are returned too |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
117 """ |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
118 version = self.version |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
119 if version[-1] == "D": |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
120 # we are in debug version, we add extra data |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
121 try: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
122 return self._version_cache |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
123 except AttributeError: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
124 self._version_cache = "{} « {} » ({})".format( |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
125 version, C.APP_RELEASE_NAME, utils.getRepositoryData(sat) |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
126 ) |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
127 return self._version_cache |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
128 else: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
129 return version |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
130 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
131 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
132 def bridge_name(self): |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
133 return os.path.splitext(os.path.basename(self.bridge.__file__))[0] |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
134 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
135 async def _postInit(self): |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
136 try: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
137 bridge_pi = self.bridge.postInit |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
138 except AttributeError: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
139 pass |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
140 else: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
141 await bridge_pi() |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
142 |
2086 | 143 self.bridge.register_method("getReady", lambda: self.initialised) |
144 self.bridge.register_method("getVersion", lambda: self.full_version) | |
145 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
|
146 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
|
147 self.bridge.register_method("profilesListGet", self.memory.getProfilesList) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
148 self.bridge.register_method("getEntityData", self.memory._getEntityData) |
2086 | 149 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
|
150 self.bridge.register_method("profileCreate", self.memory.createProfile) |
2086 | 151 self.bridge.register_method("asyncDeleteProfile", self.memory.asyncDeleteProfile) |
152 self.bridge.register_method("profileStartSession", self.memory.startSession) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
153 self.bridge.register_method( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
154 "profileIsSessionStarted", self.memory._isSessionStarted |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
155 ) |
2086 | 156 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
|
157 self.bridge.register_method("connect", self._connect) |
2086 | 158 self.bridge.register_method("disconnect", self.disconnect) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
159 self.bridge.register_method("contactGet", self._contactGet) |
2086 | 160 self.bridge.register_method("getContacts", self.getContacts) |
161 self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup) | |
162 self.bridge.register_method("getMainResource", self.memory._getMainResource) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
163 self.bridge.register_method( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
164 "getPresenceStatuses", self.memory._getPresenceStatuses |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
165 ) |
2086 | 166 self.bridge.register_method("getWaitingSub", self.memory.getWaitingSub) |
167 self.bridge.register_method("messageSend", self._messageSend) | |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
168 self.bridge.register_method("messageEncryptionStart", |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
169 self._messageEncryptionStart) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
170 self.bridge.register_method("messageEncryptionStop", |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
171 self._messageEncryptionStop) |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
172 self.bridge.register_method("messageEncryptionGet", |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
173 self._messageEncryptionGet) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
174 self.bridge.register_method("encryptionNamespaceGet", |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
175 self._encryptionNamespaceGet) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
176 self.bridge.register_method("encryptionPluginsGet", self._encryptionPluginsGet) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
177 self.bridge.register_method("encryptionTrustUIGet", self._encryptionTrustUIGet) |
2086 | 178 self.bridge.register_method("getConfig", self._getConfig) |
179 self.bridge.register_method("setParam", self.setParam) | |
180 self.bridge.register_method("getParamA", self.memory.getStringParamA) | |
3163
d10b2368684e
bridge: added methods to let frontends store/retrieve/delete private data
Goffi <goffi@goffi.org>
parents:
3140
diff
changeset
|
181 self.bridge.register_method("privateDataGet", self.memory._privateDataGet) |
d10b2368684e
bridge: added methods to let frontends store/retrieve/delete private data
Goffi <goffi@goffi.org>
parents:
3140
diff
changeset
|
182 self.bridge.register_method("privateDataSet", self.memory._privateDataSet) |
d10b2368684e
bridge: added methods to let frontends store/retrieve/delete private data
Goffi <goffi@goffi.org>
parents:
3140
diff
changeset
|
183 self.bridge.register_method("privateDataDelete", self.memory._privateDataDelete) |
2086 | 184 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
185 self.bridge.register_method( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
186 "asyncGetParamsValuesFromCategory", |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
187 self.memory._getParamsValuesFromCategory, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
188 ) |
3123
130f9cb6e0ab
core (memory/params): added `extra` argument to filter out params notably in `getParamsUI`:
Goffi <goffi@goffi.org>
parents:
3120
diff
changeset
|
189 self.bridge.register_method("getParamsUI", self.memory._getParamsUI) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
190 self.bridge.register_method( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
191 "getParamsCategories", self.memory.getParamsCategories |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
192 ) |
2086 | 193 self.bridge.register_method("paramsRegisterApp", self.memory.paramsRegisterApp) |
194 self.bridge.register_method("historyGet", self.memory._historyGet) | |
195 self.bridge.register_method("setPresence", self._setPresence) | |
196 self.bridge.register_method("subscription", self.subscription) | |
197 self.bridge.register_method("addContact", self._addContact) | |
198 self.bridge.register_method("updateContact", self._updateContact) | |
199 self.bridge.register_method("delContact", self._delContact) | |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
200 self.bridge.register_method("rosterResync", self._rosterResync) |
2086 | 201 self.bridge.register_method("isConnected", self.isConnected) |
202 self.bridge.register_method("launchAction", self.launchCallback) | |
203 self.bridge.register_method("actionsGet", self.actionsGet) | |
204 self.bridge.register_method("progressGet", self._progressGet) | |
205 self.bridge.register_method("progressGetAll", self._progressGetAll) | |
2126 | 206 self.bridge.register_method("menusGet", self.getMenus) |
207 self.bridge.register_method("menuHelpGet", self.getMenuHelp) | |
208 self.bridge.register_method("menuLaunch", self._launchMenu) | |
2086 | 209 self.bridge.register_method("discoInfos", self.memory.disco._discoInfos) |
210 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
|
211 self.bridge.register_method("discoFindByFeatures", self._findByFeatures) |
2086 | 212 self.bridge.register_method("saveParamsTemplate", self.memory.save_xml) |
213 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
|
214 self.bridge.register_method("sessionInfosGet", self.getSessionInfos) |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
215 self.bridge.register_method("devicesInfosGet", self._getDevicesInfos) |
2443
81a45e7886c9
core: added a mechanism to associate short names to namespaces:
Goffi <goffi@goffi.org>
parents:
2431
diff
changeset
|
216 self.bridge.register_method("namespacesGet", self.getNamespaces) |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
217 self.bridge.register_method("imageCheck", self._imageCheck) |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
218 self.bridge.register_method("imageResize", self._imageResize) |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
219 self.bridge.register_method("imageGeneratePreview", self._imageGeneratePreview) |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
220 self.bridge.register_method("imageConvert", self._imageConvert) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
221 |
0 | 222 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
223 await self.memory.initialise() |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 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
|
230 except Exception as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
231 log.error( |
3028 | 232 _("Could not initialize backend: {reason}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
233 reason=str(e).decode("utf-8", "ignore") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
234 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
235 ) |
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
|
236 sys.exit(1) |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
237 self._addBaseMenus() |
3120 | 238 |
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
|
239 self.initialised.callback(None) |
3028 | 240 log.info(_("Backend is ready")) |
0 | 241 |
3120 | 242 # profile autoconnection must be done after self.initialised is called because |
243 # startSession waits for it. | |
244 autoconnect_dict = await self.memory.storage.getIndParamValues( | |
245 category='Connection', name='autoconnect_backend', | |
246 ) | |
247 profiles_autoconnect = [p for p, v in autoconnect_dict.items() if C.bool(v)] | |
248 if not self.trigger.point("profilesAutoconnect", profiles_autoconnect): | |
249 return | |
250 if profiles_autoconnect: | |
251 log.info(D_( | |
252 "Following profiles will be connected automatically: {profiles}" | |
253 ).format(profiles= ', '.join(profiles_autoconnect))) | |
254 connect_d_list = [] | |
255 for profile in profiles_autoconnect: | |
256 connect_d_list.append(defer.ensureDeferred(self.connect(profile))) | |
257 | |
258 if connect_d_list: | |
259 results = await defer.DeferredList(connect_d_list) | |
260 for idx, (success, result) in enumerate(results): | |
261 if not success: | |
262 profile = profiles_autoconnect[0] | |
263 log.warning( | |
264 _("Can't autoconnect profile {profile}: {reason}").format( | |
265 profile = profile, | |
266 reason = result) | |
267 ) | |
268 | |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
269 def _addBaseMenus(self): |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
270 """Add base menus""" |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
271 encryption.EncryptionHandler._importMenus(self) |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
272 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
273 def _unimport_plugin(self, plugin_path): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
274 """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
|
275 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
276 del sys.modules[plugin_path] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
277 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
278 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
279 |
0 | 280 def _import_plugins(self): |
281 """Import all plugins found in plugins directory""" | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
282 # FIXME: module imported but cancelled should be deleted |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
283 # 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
|
284 # FIXME: should use imp |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
285 # TODO: do not import all plugins if no needed: component plugins are not needed |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
286 # if we just use a client, and plugin blacklisting should be possible in |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
287 # sat.conf |
3370
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
288 plugins_path = Path(sat.plugins.__file__).parent |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
289 plugins_to_import = {} # plugins we still have to import |
3370
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
290 for plug_path in plugins_path.glob("plugin_*"): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
291 if plug_path.is_dir(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
292 init_path = plug_path / f"__init__.{C.PLUGIN_EXT}" |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
293 if not init_path.exists(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
294 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
295 f"{plug_path} doesn't appear to be a package, can't load it") |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
296 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
297 plug_name = plug_path.name |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
298 elif plug_path.is_file(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
299 if plug_path.suffix != f".{C.PLUGIN_EXT}": |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
300 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
301 plug_name = plug_path.stem |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
302 else: |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
303 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
304 f"{plug_path} is not a file or a dir, ignoring it") |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
305 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
306 if not plug_name.isidentifier(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
307 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
308 f"{plug_name!r} is not a valid name for a plugin, ignoring it") |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
309 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
310 plugin_path = f"sat.plugins.{plug_name}" |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
311 try: |
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
312 __import__(plugin_path) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
313 except exceptions.MissingModule as e: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
314 self._unimport_plugin(plugin_path) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
315 log.warning( |
3028 | 316 "Can't import plugin [{path}] because of an unavailale third party " |
317 "module:\n{msg}".format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
318 path=plugin_path, msg=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
319 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
320 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
321 continue |
2100 | 322 except exceptions.CancelError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
323 log.info( |
3028 | 324 "Plugin [{path}] cancelled its own import: {msg}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
325 path=plugin_path, msg=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
326 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
327 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
328 self._unimport_plugin(plugin_path) |
2100 | 329 continue |
3040 | 330 except Exception: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
331 import traceback |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
332 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
333 log.error( |
3028 | 334 _("Can't import plugin [{path}]:\n{error}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
335 path=plugin_path, error=traceback.format_exc() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
336 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
337 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
338 self._unimport_plugin(plugin_path) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
339 continue |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
340 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
341 plugin_info = mod.PLUGIN_INFO |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
342 import_name = plugin_info["import_name"] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
343 |
3028 | 344 plugin_modes = plugin_info["modes"] = set( |
345 plugin_info.setdefault("modes", C.PLUG_MODE_DEFAULT) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
346 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
347 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
348 # if the plugin is an entry point, it must work in component mode |
3028 | 349 if plugin_info["type"] == C.PLUG_TYPE_ENTRY_POINT: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
350 # if plugin is an entrypoint, we cache it |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
351 if C.PLUG_MODE_COMPONENT not in plugin_modes: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
352 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
353 _( |
3028 | 354 "{type} type must be used with {mode} mode, ignoring plugin" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
355 ).format(type=C.PLUG_TYPE_ENTRY_POINT, mode=C.PLUG_MODE_COMPONENT) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
356 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
357 self._unimport_plugin(plugin_path) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
358 continue |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
359 |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
360 if import_name in plugins_to_import: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
361 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
362 _( |
3028 | 363 "Name conflict for import name [{import_name}], can't import " |
364 "plugin [{name}]" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
365 ).format(**plugin_info) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
366 ) |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
367 continue |
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
368 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
|
369 while True: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
370 try: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
371 self._import_plugins_from_dict(plugins_to_import) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
372 except ImportError: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
373 pass |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
374 if not plugins_to_import: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
375 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
376 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
377 def _import_plugins_from_dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
378 self, plugins_to_import, import_name=None, optional=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
379 ): |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
380 """Recursively import and their dependencies in the right order |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
381 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
382 @param plugins_to_import(dict): key=import_name and values=(plugin_path, module, |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
383 plugin_info) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
384 @param import_name(unicode, None): name of the plugin to import as found in |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
385 PLUGIN_INFO['import_name'] |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
386 @param optional(bool): if False and plugin is not found, an ImportError exception |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
387 is raised |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
388 """ |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
389 if import_name in self.plugins: |
3028 | 390 log.debug("Plugin {} already imported, passing".format(import_name)) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
391 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
392 if not import_name: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
393 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
|
394 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
395 if not import_name in plugins_to_import: |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
396 if optional: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
397 log.warning( |
3028 | 398 _("Recommended plugin not found: {}").format(import_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
399 ) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
400 return |
3028 | 401 msg = "Dependency not found: {}".format(import_name) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
402 log.error(msg) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
403 raise ImportError(msg) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
404 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
|
405 dependencies = plugin_info.setdefault("dependencies", []) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
406 recommendations = plugin_info.setdefault("recommendations", []) |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
407 for to_import in dependencies + recommendations: |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
408 if to_import not in self.plugins: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
409 log.debug( |
3028 | 410 "Recursively import dependency of [%s]: [%s]" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
411 % (import_name, to_import) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
412 ) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
413 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
414 self._import_plugins_from_dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
415 plugins_to_import, to_import, to_import not in dependencies |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
416 ) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
417 except ImportError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
418 log.warning( |
3028 | 419 _("Can't import plugin {name}: {error}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
420 name=plugin_info["name"], error=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
421 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
422 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
423 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
424 return |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
425 raise e |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
426 log.info("importing plugin: {}".format(plugin_info["name"])) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
427 # we instanciate the plugin here |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
428 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
429 self.plugins[import_name] = getattr(mod, plugin_info["main"])(self) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
430 except Exception as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
431 log.warning( |
3028 | 432 'Error while loading plugin "{name}", ignoring it: {error}'.format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
433 name=plugin_info["name"], error=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
434 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
435 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
436 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
437 return |
3028 | 438 raise ImportError("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
|
439 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
|
440 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
441 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
442 self.plugins[import_name].is_handler = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
443 # we keep metadata as a Class attribute |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
444 self.plugins[import_name]._info = plugin_info |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
445 # TODO: test xmppclient presence and register handler parent |
0 | 446 |
1550 | 447 def pluginsUnload(self): |
448 """Call unload method on every loaded plugin, if exists | |
449 | |
450 @return (D): A deferred which return None when all method have been called | |
451 """ | |
452 # TODO: in the futur, it should be possible to hot unload a plugin | |
453 # pluging depending on the unloaded one should be unloaded too | |
454 # for now, just a basic call on plugin.unload is done | |
455 defers_list = [] | |
3028 | 456 for plugin in self.plugins.values(): |
1550 | 457 try: |
458 unload = plugin.unload | |
459 except AttributeError: | |
460 continue | |
461 else: | |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3539
diff
changeset
|
462 defers_list.append(utils.asDeferred(unload)) |
1550 | 463 return defers_list |
464 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
465 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
|
466 profile = self.memory.getProfileName(profile_key) |
3120 | 467 return defer.ensureDeferred(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
|
468 |
3120 | 469 async def connect( |
470 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
|
471 """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
|
472 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
473 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
|
474 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
|
475 @param profile: %(doc_profile)s |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3539
diff
changeset
|
476 @param password (string): the Libervia profile password |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
477 @param options (dict): connection options. Key can be: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
478 - |
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
|
479 @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
|
480 @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
|
481 - 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
|
482 - 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
|
483 @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
|
484 """ |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
485 if options is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
486 options = {} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
487 |
3120 | 488 await self.memory.startSession(password, profile) |
489 | |
490 if self.isConnected(profile): | |
491 log.info(_("already connected !")) | |
492 return True | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
493 |
3120 | 494 if self.memory.isComponent(profile): |
495 await xmpp.SatXMPPComponent.startConnection(self, profile, max_retries) | |
496 else: | |
497 await xmpp.SatXMPPClient.startConnection(self, profile, max_retries) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
498 |
3120 | 499 return False |
1019 | 500 |
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
|
501 def disconnect(self, profile_key): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
502 """disconnect from jabber server""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
503 # 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
|
504 # 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
|
505 if not self.isConnected(profile_key): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
506 # isConnected is checked here and not on client |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
507 # because client is deleted when session is ended |
3028 | 508 log.info(_("not connected !")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
509 return defer.succeed(None) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
510 client = self.getClient(profile_key) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
511 return client.entityDisconnect() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
512 |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
513 def getFeatures(self, profile_key=C.PROF_KEY_NONE): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
514 """Get available features |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
515 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
516 Return list of activated plugins and plugin specific data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
517 @param profile_key: %(doc_profile_key)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
518 C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
519 dependent) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
520 @return (dict)[Deferred]: features data where: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
521 - 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
|
522 - 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
|
523 this dict is return by plugin's getFeature method. |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
524 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
|
525 """ |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
526 try: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
527 # FIXME: there is no method yet to check profile session |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
528 # 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
|
529 self.getClient(profile_key) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
530 except KeyError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
531 log.warning("Requesting features for a profile outside a session") |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
532 profile_key = C.PROF_KEY_NONE |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
533 except exceptions.ProfileNotSetError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
534 pass |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
535 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
536 features = [] |
3028 | 537 for import_name, plugin in self.plugins.items(): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
538 try: |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3539
diff
changeset
|
539 features_d = utils.asDeferred(plugin.getFeatures, profile_key) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
540 except AttributeError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
541 features_d = defer.succeed({}) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
542 features.append(features_d) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
543 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
544 d_list = defer.DeferredList(features) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
545 |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
546 def buildFeatures(result, import_names): |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
547 assert len(result) == len(import_names) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
548 ret = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
549 for name, (success, data) in zip(import_names, result): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
550 if success: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
551 ret[name] = data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
552 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
553 log.warning( |
3028 | 554 "Error while getting features for {name}: {failure}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
555 name=name, failure=data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
556 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
557 ) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
558 ret[name] = {} |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
559 return ret |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
560 |
3028 | 561 d_list.addCallback(buildFeatures, list(self.plugins.keys())) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
562 return d_list |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
563 |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
564 def _contactGet(self, entity_jid_s, profile_key): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
565 client = self.getClient(profile_key) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
566 entity_jid = jid.JID(entity_jid_s) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
567 return defer.ensureDeferred(self.getContact(client, entity_jid)) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
568 |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
569 async def getContact(self, client, entity_jid): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
570 # we want to be sure that roster has been received |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
571 await client.roster.got_roster |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
572 item = client.roster.getItem(entity_jid) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
573 if item is None: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
574 raise exceptions.NotFound(f"{entity_jid} is not in roster!") |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
575 return (client.roster.getAttributes(item), list(item.groups)) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
576 |
466
448ce3c9e2ac
core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents:
460
diff
changeset
|
577 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
|
578 client = self.getClient(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
579 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
580 def got_roster(__): |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
581 ret = [] |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
582 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
|
583 # and convert them to expected format |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
584 attr = client.roster.getAttributes(item) |
2977
06f30ad8e110
core: return full jid in bridge's getContacts:
Goffi <goffi@goffi.org>
parents:
2914
diff
changeset
|
585 # we use full() and not userhost() because jid with resources are allowed |
06f30ad8e110
core: return full jid in bridge's getContacts:
Goffi <goffi@goffi.org>
parents:
2914
diff
changeset
|
586 # in roster, even if it's not common. |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3539
diff
changeset
|
587 ret.append([item.entity.full(), attr, list(item.groups)]) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
588 return ret |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
589 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
590 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
|
591 |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
592 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
|
593 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
|
594 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
|
595 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
596 def purgeEntity(self, profile): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
597 """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
|
598 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
599 the garbage collector can then free the memory |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
600 """ |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
601 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
602 del self.profiles[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
603 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
604 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
|
605 else: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
606 self.memory.purgeProfileSession(profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
607 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
608 def startService(self): |
3110
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
609 self._init() |
3028 | 610 log.info("Salut à toi ô mon frère !") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
611 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
612 def stopService(self): |
3028 | 613 log.info("Salut aussi à Rantanplan") |
1550 | 614 return self.pluginsUnload() |
0 | 615 |
616 def run(self): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
617 log.debug(_("running app")) |
0 | 618 reactor.run() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
619 |
0 | 620 def stop(self): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
621 log.debug(_("stopping app")) |
0 | 622 reactor.stop() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
623 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
624 ## Misc methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
625 |
64 | 626 def getJidNStream(self, profile_key): |
627 """Convenient method to get jid and stream from profile key | |
628 @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
|
629 # TODO: deprecate this method (getClient is enough) |
64 | 630 profile = self.memory.getProfileName(profile_key) |
631 if not profile or not self.profiles[profile].isConnected(): | |
632 return (None, None) | |
633 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
634 | |
635 def getClient(self, profile_key): | |
636 """Convenient method to get client from profile key | |
1624 | 637 |
638 @return: client or None if it doesn't exist | |
639 @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist | |
640 @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
|
641 This happen if profile has not been used yet |
1624 | 642 """ |
64 | 643 profile = self.memory.getProfileName(profile_key) |
644 if not profile: | |
1624 | 645 raise exceptions.ProfileKeyUnknown |
646 try: | |
647 return self.profiles[profile] | |
648 except KeyError: | |
2445
0199c0bd4c60
core: specify profile on NotFound exception
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
649 raise exceptions.NotFound(profile_key) |
64 | 650 |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
651 def getClients(self, profile_key): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
652 """Convenient method to get list of clients from profile key |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
653 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
654 Manage list through profile_key like C.PROF_KEY_ALL |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
655 @param profile_key: %(doc_profile_key)s |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
656 @return: list of clients |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
657 """ |
2251
83bcd9ec4782
core: fixed profile key detection in getClients + raise DataError on empty profile
Goffi <goffi@goffi.org>
parents:
2176
diff
changeset
|
658 if not profile_key: |
3028 | 659 raise exceptions.DataError(_("profile_key must not be empty")) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
660 try: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
661 profile = self.memory.getProfileName(profile_key, True) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
662 except exceptions.ProfileUnknownError: |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
663 return [] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
664 if profile == C.PROF_KEY_ALL: |
3028 | 665 return list(self.profiles.values()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
666 elif profile[0] == "@": # only profile keys can start with "@" |
1624 | 667 raise exceptions.ProfileKeyUnknown |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
668 return [self.profiles[profile]] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
669 |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
670 def _getConfig(self, section, name): |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
671 """Get the main configuration option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
672 |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
673 @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
|
674 @param name: name of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
675 @return: unicode representation of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
676 """ |
3028 | 677 return str(self.memory.getConfig(section, name, "")) |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
678 |
3028 | 679 def logErrback(self, failure_, msg=_("Unexpected error: {failure_}")): |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
680 """Generic errback logging |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
681 |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
682 @param msg(unicode): error message ("failure_" key will be use for format) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
683 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
|
684 """ |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
685 log.error(msg.format(failure_=failure_)) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
686 return failure_ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
687 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
688 # namespaces |
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
|
689 |
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
|
690 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
|
691 """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
|
692 if short_name in self.ns_map: |
3028 | 693 raise exceptions.ConflictError("this short name is already used") |
3117
385fdd684f87
core: added a debug log when a namespace is registered
Goffi <goffi@goffi.org>
parents:
3110
diff
changeset
|
694 log.debug(f"registering namespace {short_name} => {namespace}") |
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
|
695 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
|
696 |
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
|
697 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
|
698 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
|
699 |
2914
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
700 def getNamespace(self, short_name): |
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
701 try: |
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
702 return self.ns_map[short_name] |
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
703 except KeyError: |
3028 | 704 raise exceptions.NotFound("namespace {short_name} is not registered" |
2914
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
705 .format(short_name=short_name)) |
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
706 |
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
|
707 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
|
708 """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
|
709 client = self.getClient(profile_key) |
2689
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
710 data = { |
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
711 "jid": client.jid.full(), |
3028 | 712 "started": str(int(client.started)) |
2689
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
713 } |
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
|
714 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
|
715 |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
716 def _getDevicesInfos(self, bare_jid, profile_key): |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
717 client = self.getClient(profile_key) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
718 if not bare_jid: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
719 bare_jid = None |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
720 d = defer.ensureDeferred(self.getDevicesInfos(client, bare_jid)) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
721 d.addCallback(lambda data: data_format.serialise(data)) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
722 return d |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
723 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
724 async def getDevicesInfos(self, client, bare_jid=None): |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
725 """compile data on an entity devices |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
726 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
727 @param bare_jid(jid.JID, None): bare jid of entity to check |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
728 None to use client own jid |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
729 @return (list[dict]): list of data, one item per resource. |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
730 Following keys can be set: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
731 - resource(str): resource name |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
732 """ |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
733 own_jid = client.jid.userhostJID() |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
734 if bare_jid is None: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
735 bare_jid = own_jid |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
736 else: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
737 bare_jid = jid.JID(bare_jid) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
738 resources = self.memory.getAllResources(client, bare_jid) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
739 if bare_jid == own_jid: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
740 # our own jid is not stored in memory's cache |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
741 resources.add(client.jid.resource) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
742 ret_data = [] |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
743 for resource in resources: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
744 res_jid = copy.copy(bare_jid) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
745 res_jid.resource = resource |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
746 cache_data = self.memory.getEntityData(client, res_jid) |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
747 res_data = { |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
748 "resource": resource, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
749 } |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
750 try: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
751 presence = cache_data['presence'] |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
752 except KeyError: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
753 pass |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
754 else: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
755 res_data['presence'] = { |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
756 "show": presence.show, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
757 "priority": presence.priority, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
758 "statuses": presence.statuses, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
759 } |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
760 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
761 disco = await self.getDiscoInfos(client, res_jid) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
762 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
763 for (category, type_), name in disco.identities.items(): |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
764 identities = res_data.setdefault('identities', []) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
765 identities.append({ |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
766 "name": name, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
767 "category": category, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
768 "type": type_, |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
769 }) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
770 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
771 ret_data.append(res_data) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
772 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
773 return ret_data |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
774 |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
775 # images |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
776 |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
777 def _imageCheck(self, path): |
3220 | 778 report = image.check(self, path) |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
779 return data_format.serialise(report) |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
780 |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
781 def _imageResize(self, path, width, height): |
3220 | 782 d = image.resize(path, (width, height)) |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
783 d.addCallback(lambda new_image_path: str(new_image_path)) |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
784 return d |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
785 |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
786 def _imageGeneratePreview(self, path, profile_key): |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
787 client = self.getClient(profile_key) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
788 d = defer.ensureDeferred(self.imageGeneratePreview(client, Path(path))) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
789 d.addCallback(lambda preview_path: str(preview_path)) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
790 return d |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
791 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
792 async def imageGeneratePreview(self, client, path): |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
793 """Helper method to generate in cache a preview of an image |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
794 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
795 @param path(Path): path to the image |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
796 @return (Path): path to the generated preview |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
797 """ |
3220 | 798 report = image.check(self, path, max_size=(300, 300)) |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
799 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
800 if not report['too_large']: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
801 # in the unlikely case that image is already smaller than a preview |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
802 preview_path = path |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
803 else: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
804 # we use hash as id, to re-use potentially existing preview |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
805 path_hash = hashlib.sha256(str(path).encode()).hexdigest() |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
806 uid = f"{path.stem}_{path_hash}_preview" |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
807 filename = f"{uid}{path.suffix.lower()}" |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
808 metadata = client.cache.getMetadata(uid=uid) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
809 if metadata is not None: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
810 preview_path = metadata['path'] |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
811 else: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
812 with client.cache.cacheData( |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
813 source='HOST_PREVIEW', |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
814 uid=uid, |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
815 filename=filename) as cache_f: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
816 |
3220 | 817 preview_path = await image.resize( |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
818 path, |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
819 new_size=report['recommended_size'], |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
820 dest=cache_f |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
821 ) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
822 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
823 return preview_path |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
824 |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
825 def _imageConvert(self, source, dest, extra, profile_key): |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
826 client = self.getClient(profile_key) if profile_key else None |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
827 source = Path(source) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
828 dest = None if not dest else Path(dest) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
829 extra = data_format.deserialise(extra) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
830 d = defer.ensureDeferred(self.imageConvert(client, source, dest, extra)) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
831 d.addCallback(lambda dest_path: str(dest_path)) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
832 return d |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
833 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
834 async def imageConvert(self, client, source, dest=None, extra=None): |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
835 """Helper method to convert an image from one format to an other |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
836 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
837 @param client(SatClient, None): client to use for caching |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
838 this parameter is only used if dest is None |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
839 if client is None, common cache will be used insted of profile cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
840 @param source(Path): path to the image to convert |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
841 @param dest(None, Path, file): where to save the converted file |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
842 - None: use a cache file (uid generated from hash of source) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
843 file will be converted to PNG |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
844 - Path: path to the file to create/overwrite |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
845 - file: a file object which must be opened for writing in binary mode |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
846 @param extra(dict, None): conversion options |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
847 see [image.convert] for details |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
848 @return (Path): path to the converted image |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
849 @raise ValueError: an issue happened with source of dest |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
850 """ |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
851 if not source.is_file: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
852 raise ValueError(f"Source file {source} doesn't exist!") |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
853 if dest is None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
854 # we use hash as id, to re-use potentially existing conversion |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
855 path_hash = hashlib.sha256(str(source).encode()).hexdigest() |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
856 uid = f"{source.stem}_{path_hash}_convert_png" |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
857 filename = f"{uid}.png" |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
858 if client is None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
859 cache = self.common_cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
860 else: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
861 cache = client.cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
862 metadata = cache.getMetadata(uid=uid) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
863 if metadata is not None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
864 # there is already a conversion for this image in cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
865 return metadata['path'] |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
866 else: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
867 with cache.cacheData( |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
868 source='HOST_IMAGE_CONVERT', |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
869 uid=uid, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
870 filename=filename) as cache_f: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
871 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
872 converted_path = await image.convert( |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
873 source, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
874 dest=cache_f, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
875 extra=extra |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
876 ) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
877 return converted_path |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
878 else: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
879 return await image.convert(source, dest, extra) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
880 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
881 |
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
|
882 # 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
|
883 |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
884 def getLocalPath( |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
885 self, |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
886 client, |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
887 dir_name: str, |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
888 *extra_path, |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
889 **kwargs |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
890 ) -> Path: |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
891 """Retrieve path for local data |
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
|
892 |
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
|
893 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
|
894 @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
|
895 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
|
896 @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
|
897 @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
|
898 @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
|
899 @param *extra_path: extra path element(s) to use |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
900 @return: path |
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
|
901 """ |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
902 # FIXME: component and profile are parsed with **kwargs because of python 2 |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
903 # limitations. Once moved to python 3, this can be fixed |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
904 component = kwargs.pop("component", False) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
905 profile = kwargs.pop("profile", True) |
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
|
906 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
|
907 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
908 path_elts = [self.memory.getConfig("", "local_dir")] |
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
|
909 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
|
910 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
|
911 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
|
912 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
|
913 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
|
914 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
|
915 regex.pathEscape(client.profile) |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
916 local_path = Path(*path_elts) |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
917 local_path.mkdir(0o700, parents=True, exist_ok=True) |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
918 return local_path |
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
|
919 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
920 ## Client management ## |
0 | 921 |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
922 def setParam(self, name, value, category, security_limit, profile_key): |
0 | 923 """set wanted paramater and notice observers""" |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
636
diff
changeset
|
924 self.memory.setParam(name, value, category, security_limit, profile_key) |
0 | 925 |
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
|
926 def isConnected(self, profile_key): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
927 """Return connection status of profile |
3125
c3ce8c997fdf
plugin android: reconnect profiles with autoconnect if network is activated:
Goffi <goffi@goffi.org>
parents:
3123
diff
changeset
|
928 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
929 @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
|
930 @return: True if connected |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
931 """ |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
932 profile = self.memory.getProfileName(profile_key) |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
933 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
934 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
|
935 raise exceptions.ProfileUnknownError(profile_key) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
936 if profile not in self.profiles: |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
937 return False |
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
938 return self.profiles[profile].isConnected() |
0 | 939 |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
940 ## Encryption ## |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
941 |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
942 def registerEncryptionPlugin(self, *args, **kwargs): |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
943 return encryption.EncryptionHandler.registerPlugin(*args, **kwargs) |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
944 |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
945 def _messageEncryptionStart(self, to_jid_s, namespace, replace=False, |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
946 profile_key=C.PROF_KEY_NONE): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
947 client = self.getClient(profile_key) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
948 to_jid = jid.JID(to_jid_s) |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
949 return defer.ensureDeferred( |
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
950 client.encryption.start(to_jid, namespace or None, replace)) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
951 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
952 def _messageEncryptionStop(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
953 client = self.getClient(profile_key) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
954 to_jid = jid.JID(to_jid_s) |
3226
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
955 return defer.ensureDeferred( |
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
956 client.encryption.stop(to_jid)) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
957 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
958 def _messageEncryptionGet(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
959 client = self.getClient(profile_key) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
960 to_jid = jid.JID(to_jid_s) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
961 session_data = client.encryption.getSession(to_jid) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
962 return client.encryption.getBridgeData(session_data) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
963 |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
964 def _encryptionNamespaceGet(self, name): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
965 return encryption.EncryptionHandler.getNSFromName(name) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
966 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
967 def _encryptionPluginsGet(self): |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
968 plugins = encryption.EncryptionHandler.getPlugins() |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
969 ret = [] |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
970 for p in plugins: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
971 ret.append({ |
3028 | 972 "name": p.name, |
973 "namespace": p.namespace, | |
3102
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3088
diff
changeset
|
974 "priority": p.priority, |
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3088
diff
changeset
|
975 "directed": p.directed, |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
976 }) |
3102
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3088
diff
changeset
|
977 return data_format.serialise(ret) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
978 |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
979 def _encryptionTrustUIGet(self, to_jid_s, namespace, profile_key): |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
980 client = self.getClient(profile_key) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
981 to_jid = jid.JID(to_jid_s) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3226
diff
changeset
|
982 d = defer.ensureDeferred( |
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3226
diff
changeset
|
983 client.encryption.getTrustUI(to_jid, namespace=namespace or None)) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
984 d.addCallback(lambda xmlui: xmlui.toXml()) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
985 return d |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
986 |
1052
e88bff4c8b77
core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents:
1043
diff
changeset
|
987 ## XMPP methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
988 |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
989 def _messageSend( |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
990 self, to_jid_s, message, subject=None, mess_type="auto", extra_s="", |
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
991 profile_key=C.PROF_KEY_NONE): |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
992 client = self.getClient(profile_key) |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
993 to_jid = jid.JID(to_jid_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
994 return client.sendMessage( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
995 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
996 message, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
997 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
998 mess_type, |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
999 data_format.deserialise(extra_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1000 ) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
1001 |
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
|
1002 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
|
1003 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
|
1004 |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
1005 def setPresence(self, to_jid=None, show="", statuses=None, |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
1006 profile_key=C.PROF_KEY_NONE): |
0 | 1007 """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
|
1008 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
|
1009 statuses = {} |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1010 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1011 assert profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1012 priority = int( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1013 self.memory.getParamA("Priority", "Connection", profile_key=profile) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1014 ) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1015 self.profiles[profile].presence.available(to_jid, show, statuses, priority) |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1016 # XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1017 # broadcasted to generating resource) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1018 if "" in statuses: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1019 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop("") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1020 self.bridge.presenceUpdate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1021 self.profiles[profile].jid.full(), show, int(priority), statuses, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1022 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1023 |
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
|
1024 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
|
1025 """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
|
1026 @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
|
1027 @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
|
1028 @param profile_key: profile""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1029 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1030 assert profile |
50 | 1031 to_jid = jid.JID(raw_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1032 log.debug( |
3028 | 1033 _("subsciption request [%(subs_type)s] for %(jid)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1034 % {"subs_type": subs_type, "jid": to_jid.full()} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1035 ) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1036 if subs_type == "subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1037 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
|
1038 elif subs_type == "subscribed": |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
1039 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
|
1040 elif subs_type == "unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1041 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
|
1042 elif subs_type == "unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1043 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 1044 |
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
|
1045 def _addContact(self, to_jid_s, profile_key): |
846
59d486726577
core: fix mispelled argument
souliane <souliane@mailoo.org>
parents:
834
diff
changeset
|
1046 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
|
1047 |
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
|
1048 def addContact(self, to_jid, profile_key): |
0 | 1049 """Add a contact in roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1050 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1051 assert profile |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1052 # presence is sufficient, as a roster push will be sent according to |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1053 # RFC 6121 §3.1.2 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1054 self.profiles[profile].presence.subscribe(to_jid) |
0 | 1055 |
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
|
1056 def _updateContact(self, to_jid_s, name, groups, profile_key): |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1057 client = self.getClient(profile_key) |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1058 return self.updateContact(client, jid.JID(to_jid_s), name, groups) |
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
|
1059 |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1060 def updateContact(self, client, to_jid, name, groups): |
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
|
1061 """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
|
1062 roster_item = RosterItem(to_jid) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1063 roster_item.name = name or u'' |
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
|
1064 roster_item.groups = set(groups) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1065 if not self.trigger.point("roster_update", client, roster_item): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1066 return |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1067 return client.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
|
1068 |
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
|
1069 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
|
1070 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
|
1071 |
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
|
1072 def delContact(self, to_jid, profile_key): |
0 | 1073 """Remove contact from roster list""" |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1074 profile = self.memory.getProfileName(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1075 assert profile |
1355
33a21f06551d
core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents:
1325
diff
changeset
|
1076 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
|
1077 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
|
1078 |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1079 def _rosterResync(self, profile_key): |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1080 client = self.getClient(profile_key) |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1081 return client.roster.resync() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1082 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1083 ## Discovery ## |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1084 # discovery methods are shortcuts to self.memory.disco |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1085 # 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
|
1086 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1087 def hasFeature(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1088 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
|
1089 |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
1090 def checkFeature(self, *args, **kwargs): |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
1091 return self.memory.disco.checkFeature(*args, **kwargs) |
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
1092 |
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
|
1093 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
|
1094 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
|
1095 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1096 def getDiscoInfos(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1097 return self.memory.disco.getInfos(*args, **kwargs) |
0 | 1098 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1099 def getDiscoItems(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1100 return self.memory.disco.getItems(*args, **kwargs) |
0 | 1101 |
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
1102 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
|
1103 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
|
1104 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1105 def findServiceEntities(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1106 return self.memory.disco.findServiceEntities(*args, **kwargs) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1107 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1108 def findFeaturesSet(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1109 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
|
1110 |
2666 | 1111 def _findByFeatures(self, namespaces, identities, bare_jids, service, roster, own_jid, |
1112 local_device, 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
|
1113 client = self.getClient(profile_key) |
3541
888109774673
core: various changes and fixes to work with new storage and D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3539
diff
changeset
|
1114 identities = [tuple(i) for i in identities] if identities else None |
3140 | 1115 return defer.ensureDeferred(self.findByFeatures( |
1116 client, namespaces, identities, bare_jids, service, roster, own_jid, | |
1117 local_device)) | |
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
|
1118 |
3140 | 1119 async def findByFeatures( |
3295 | 1120 self, |
1121 client: xmpp.SatXMPPEntity, | |
1122 namespaces: List[str], | |
1123 identities: Optional[List[Tuple[str, str]]]=None, | |
1124 bare_jids: bool=False, | |
1125 service: bool=True, | |
1126 roster: bool=True, | |
1127 own_jid: bool=True, | |
1128 local_device: bool=False | |
1129 ) -> Tuple[ | |
1130 Dict[jid.JID, Tuple[str, str, str]], | |
1131 Dict[jid.JID, Tuple[str, str, str]], | |
1132 Dict[jid.JID, Tuple[str, str, str]] | |
1133 ]: | |
3140 | 1134 """Retrieve all services or contacts managing a set a features |
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
|
1135 |
3295 | 1136 @param namespaces: features which must be handled |
1137 @param identities: if not None or empty, | |
1138 only keep those identities | |
1139 tuple must be (category, type) | |
1140 @param bare_jids: retrieve only bare_jids if True | |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1141 if False, retrieve full jid of connected devices |
3295 | 1142 @param service: if True return service from our server |
1143 @param roster: if True, return entities in roster | |
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
|
1144 full jid of all matching resources available will be returned |
3295 | 1145 @param own_jid: if True, return profile's jid resources |
1146 @param local_device: if True, return profile's jid local resource | |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1147 (i.e. client.jid) |
3295 | 1148 @return: found entities in a tuple with: |
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
|
1149 - 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
|
1150 - 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
|
1151 - roster entities |
3295 | 1152 Each element is a dict mapping from jid to a tuple with category, type and |
1153 name of the entity | |
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
|
1154 """ |
2666 | 1155 assert isinstance(namespaces, list) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1156 if not identities: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1157 identities = None |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1158 if not namespaces and not identities: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1159 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1160 "at least one namespace or one identity must be set" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1161 ) |
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
|
1162 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
|
1163 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
|
1164 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
|
1165 if service: |
3140 | 1166 services_jids = await self.findFeaturesSet(client, namespaces) |
2791
034c88e9cd93
core (findByFeatures): fixed services discovery
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1167 services_jids = list(services_jids) # we need a list to map results below |
3140 | 1168 services_infos = await defer.DeferredList( |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1169 [self.getDiscoInfos(client, service_jid) for service_jid in services_jids] |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1170 ) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1171 |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1172 for idx, (success, infos) in enumerate(services_infos): |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1173 service_jid = services_jids[idx] |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1174 if not success: |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1175 log.warning( |
3028 | 1176 _("Can't find features for service {service_jid}, ignoring") |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1177 .format(service_jid=service_jid.full())) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1178 continue |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1179 if (identities is not None |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1180 and not set(infos.identities.keys()).issuperset(identities)): |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1181 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1182 found_identities = [ |
3028 | 1183 (cat, type_, name or "") |
1184 for (cat, type_), name in infos.identities.items() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1185 ] |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1186 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
|
1187 |
2666 | 1188 to_find = [] |
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
|
1189 if own_jid: |
2666 | 1190 to_find.append((found_own, [client.jid.userhostJID()])) |
1191 if roster: | |
1192 to_find.append((found_roster, client.roster.getJids())) | |
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
|
1193 |
3140 | 1194 for found, jids in to_find: |
1195 full_jids = [] | |
1196 disco_defers = [] | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1197 |
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
|
1198 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
|
1199 if jid_.resource: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1200 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1201 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
|
1202 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
|
1203 else: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1204 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1205 resources = [None] |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1206 else: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1207 try: |
2597
9446f1ea9eac
core: discoFindByFeatures now return only available resources
Goffi <goffi@goffi.org>
parents:
2595
diff
changeset
|
1208 resources = self.memory.getAvailableResources(client, jid_) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1209 except exceptions.UnknownEntityError: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1210 continue |
2666 | 1211 if not resources and jid_ == client.jid.userhostJID() and own_jid: |
1212 # small hack to avoid missing our own resource when this | |
1213 # method is called at the very beginning of the session | |
1214 # and our presence has not been received yet | |
1215 resources = [client.jid.resource] | |
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
|
1216 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
|
1217 full_jid = jid.JID(tuple=(jid_.user, jid_.host, resource)) |
2595
973d4551ffae
core: added local_device argument to discoFindByFeatures
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1218 if full_jid == client.jid and not local_device: |
973d4551ffae
core: added local_device argument to discoFindByFeatures
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1219 continue |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1220 full_jids.append(full_jid) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1221 |
3140 | 1222 disco_defers.append(self.getDiscoInfos(client, full_jid)) |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1223 |
3140 | 1224 d_list = defer.DeferredList(disco_defers) |
1225 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) | |
1226 # but for discovery, that's also the time the user will wait the first time | |
1227 # before seing the page, if something goes wrong. | |
1228 d_list.addTimeout(10, reactor) | |
1229 infos_data = await d_list | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1230 |
3140 | 1231 for idx, (success, infos) in enumerate(infos_data): |
1232 full_jid = full_jids[idx] | |
1233 if not success: | |
1234 log.warning( | |
1235 _("Can't retrieve {full_jid} infos, ignoring") | |
1236 .format(full_jid=full_jid.full())) | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1237 continue |
3140 | 1238 if infos.features.issuperset(namespaces): |
1239 if identities is not None and not set( | |
1240 infos.identities.keys() | |
1241 ).issuperset(identities): | |
1242 continue | |
1243 found_identities = [ | |
1244 (cat, type_, name or "") | |
1245 for (cat, type_), name in infos.identities.items() | |
1246 ] | |
1247 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
|
1248 |
3140 | 1249 return (found_service, found_own, found_roster) |
742
03744d9ebc13
plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
728
diff
changeset
|
1250 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1251 ## Generic HMI ## |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1252 |
1622 | 1253 def _killAction(self, keep_id, client): |
3028 | 1254 log.debug("Killing action {} for timeout".format(keep_id)) |
1622 | 1255 client.actions[keep_id] |
1256 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1257 def actionNew( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1258 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1259 action_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1260 security_limit=C.NO_SECURITY_LIMIT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1261 keep_id=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1262 profile=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1263 ): |
1622 | 1264 """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
|
1265 |
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
|
1266 @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
|
1267 @param security_limit: %(doc_security_limit)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1268 @param keep_id(None, unicode): if not None, used to keep action for differed |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1269 retrieval. Must be set to the callback_id. |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1270 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
|
1271 @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
|
1272 """ |
3028 | 1273 id_ = str(uuid.uuid4()) |
1622 | 1274 if keep_id is not None: |
1275 client = self.getClient(profile) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1276 action_timer = reactor.callLater(60 * 30, self._killAction, keep_id, client) |
1622 | 1277 client.actions[keep_id] = (action_data, id_, security_limit, action_timer) |
1278 | |
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
|
1279 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
|
1280 |
1622 | 1281 def actionsGet(self, profile): |
1282 """Return current non answered actions | |
1283 | |
1284 @param profile: %(doc_profile)s | |
1285 """ | |
1286 client = self.getClient(profile) | |
3028 | 1287 return [action_tuple[:-1] for action_tuple in client.actions.values()] |
1622 | 1288 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1289 def registerProgressCb( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1290 self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1291 ): |
0 | 1292 """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
|
1293 if metadata is None: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1294 metadata = {} |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
1295 client = self.getClient(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1296 if progress_id in client._progress_cb: |
3028 | 1297 raise exceptions.ConflictError("Progress ID is not unique !") |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1298 client._progress_cb[progress_id] = (callback, metadata) |
0 | 1299 |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1300 def removeProgressCb(self, progress_id, profile): |
0 | 1301 """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
|
1302 client = self.getClient(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1303 try: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1304 del client._progress_cb[progress_id] |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1305 except KeyError: |
3028 | 1306 log.error(_("Trying to remove an unknow progress callback")) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1307 |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1308 def _progressGet(self, progress_id, profile): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1309 data = self.progressGet(progress_id, profile) |
3028 | 1310 return {k: str(v) for k, v in data.items()} |
0 | 1311 |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1312 def progressGet(self, progress_id, profile): |
0 | 1313 """Return a dict with progress information |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1314 |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1315 @param progress_id(unicode): unique id of the progressing element |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1316 @param profile: %(doc_profile)s |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1317 @return (dict): data with the following keys: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1318 'position' (int): current possition |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1319 'size' (int): end_position |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1320 if id doesn't exists (may be a finished progression), and empty dict is |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1321 returned |
0 | 1322 """ |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
536
diff
changeset
|
1323 client = self.getClient(profile) |
0 | 1324 try: |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1325 data = client._progress_cb[progress_id][0](progress_id, profile) |
0 | 1326 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
|
1327 data = {} |
0 | 1328 return data |
1329 | |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1330 def _progressGetAll(self, profile_key): |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1331 progress_all = self.progressGetAll(profile_key) |
3028 | 1332 for profile, progress_dict in progress_all.items(): |
1333 for progress_id, data in progress_dict.items(): | |
1334 for key, value in data.items(): | |
1335 data[key] = str(value) | |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1336 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1337 |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1338 def progressGetAllMetadata(self, profile_key): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1339 """Return all progress metadata at once |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1340 |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1341 @param profile_key: %(doc_profile)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1342 if C.PROF_KEY_ALL is used, all progress metadata from all profiles are |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1343 returned |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1344 @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
|
1345 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
|
1346 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
|
1347 """ |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1348 clients = self.getClients(profile_key) |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1349 progress_all = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1350 for client in clients: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1351 profile = client.profile |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1352 progress_dict = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1353 progress_all[profile] = progress_dict |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1354 for ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1355 progress_id, |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
1356 (__, progress_metadata), |
3028 | 1357 ) in client._progress_cb.items(): |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1358 progress_dict[progress_id] = progress_metadata |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1359 return progress_all |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1360 |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1361 def progressGetAll(self, profile_key): |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1362 """Return all progress status at once |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1363 |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1364 @param profile_key: %(doc_profile)s |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1365 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
|
1366 @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
|
1367 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
|
1368 progress_data is the same dict as returned by [progressGet] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1369 """ |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1370 clients = self.getClients(profile_key) |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1371 progress_all = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1372 for client in clients: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1373 profile = client.profile |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1374 progress_dict = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1375 progress_all[profile] = progress_dict |
3028 | 1376 for progress_id, (progress_cb, __) in client._progress_cb.items(): |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1377 progress_dict[progress_id] = progress_cb(progress_id, profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1378 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1379 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1380 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
|
1381 """Register a callback. |
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1382 |
2126 | 1383 @param callback(callable): method to call |
1384 @param kwargs: can contain: | |
1385 with_data(bool): True if the callback use the optional data dict | |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1386 force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1387 if possible |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
1388 one_shot(bool): True to delete callback once it has been called |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1389 @return: id of the registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1390 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1391 callback_id = kwargs.pop("force_id", None) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1392 if callback_id is None: |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2147
diff
changeset
|
1393 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
|
1394 else: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1395 if callback_id in self._cb_map: |
3028 | 1396 raise exceptions.ConflictError(_("id already registered")) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1397 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
|
1398 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1399 if "one_shot" in kwargs: # One Shot callback are removed after 30 min |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1400 |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1401 def purgeCallback(): |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1402 try: |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1403 self.removeCallback(callback_id) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1404 except KeyError: |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1405 pass |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1406 |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1407 reactor.callLater(1800, purgeCallback) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1408 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1409 return callback_id |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1410 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1411 def removeCallback(self, callback_id): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1412 """ Remove a previously registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1413 @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
|
1414 log.debug("Removing callback [%s]" % callback_id) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1415 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
|
1416 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
914
diff
changeset
|
1417 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
|
1418 """Launch a specific callback |
2126 | 1419 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1420 @param callback_id: id of the action (callback) to launch |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1421 @param data: optional data |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1422 @profile_key: %(doc_profile_key)s |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1423 @return: a deferred which fire a dict where key can be: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1424 - xmlui: a XMLUI need to be displayed |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1425 - validated: if present, can be used to launch a callback, it can have the |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1426 values |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1427 - C.BOOL_TRUE |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1428 - C.BOOL_FALSE |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1429 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1430 # FIXME: security limit need to be checked here |
1622 | 1431 try: |
1624 | 1432 client = self.getClient(profile_key) |
1433 except exceptions.NotFound: | |
1434 # client is not available yet | |
1435 profile = self.memory.getProfileName(profile_key) | |
1436 if not profile: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1437 raise exceptions.ProfileUnknownError( |
3028 | 1438 _("trying to launch action with a non-existant profile") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1439 ) |
1622 | 1440 else: |
1624 | 1441 profile = client.profile |
1442 # we check if the action is kept, and remove it | |
1443 try: | |
1444 action_tuple = client.actions[callback_id] | |
1445 except KeyError: | |
1446 pass | |
1447 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1448 action_tuple[-1].cancel() # the last item is the action timer |
1624 | 1449 del client.actions[callback_id] |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1450 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1451 try: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1452 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
|
1453 except KeyError: |
3028 | 1454 raise exceptions.DataError("Unknown callback id {}".format(callback_id)) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1455 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1456 if kwargs.get("with_data", False): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1457 if data is None: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1458 raise exceptions.DataError("Required data for this callback is missing") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1459 args, kwargs = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1460 list(args)[:], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1461 kwargs.copy(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1462 ) # we don't want to modify the original (kw)args |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1463 args.insert(0, data) |
1624 | 1464 kwargs["profile"] = profile |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1465 del kwargs["with_data"] |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1466 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1467 if kwargs.pop("one_shot", False): |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1468 self.removeCallback(callback_id) |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1469 |
3388
cc288ec8ec1a
core: use utils.asDeferred for `launchCallback` so coroutines can be used
Goffi <goffi@goffi.org>
parents:
3370
diff
changeset
|
1470 return utils.asDeferred(callback, *args, **kwargs) |
0 | 1471 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1472 # Menus management |
101 | 1473 |
2126 | 1474 def _getMenuCanonicalPath(self, path): |
1475 """give canonical form of path | |
1476 | |
1477 canonical form is a tuple of the path were every element is stripped and lowercase | |
1478 @param path(iterable[unicode]): untranslated path to menu | |
1479 @return (tuple[unicode]): canonical form of path | |
1480 """ | |
1481 return tuple((p.lower().strip() for p in path)) | |
1482 | |
2810
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
1483 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, |
c161a294fffd
core: added a base menu allowing to set encryption session or show the trust management UI.
Goffi <goffi@goffi.org>
parents:
2791
diff
changeset
|
1484 help_string="", type_=C.MENU_GLOBAL): |
3028 | 1485 r"""register a new menu for frontends |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1486 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1487 @param path(iterable[unicode]): path to go to the menu |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1488 (category/subcategory/.../item) (e.g.: ("File", "Open")) |
773 | 1489 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open"))) |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1490 untranslated/lower case path can be used to identity a menu, for this reason |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1491 it must be unique independently of case. |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1492 @param callback(callable): method to be called when menuitem is selected, callable |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1493 or a callback id (string) as returned by [registerCallback] |
2126 | 1494 @param security_limit(int): %(doc_security_limit)s |
809 | 1495 /!\ security_limit MUST be added to data in launchCallback if used #TODO |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1496 @param help_string(unicode): string used to indicate what the menu do (can be |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1497 show as a tooltip). |
773 | 1498 /!\ use D_() instead of _() for translations |
2126 | 1499 @param type(unicode): one of: |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1500 - C.MENU_GLOBAL: classical menu, can be shown in a menubar on top (e.g. |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1501 something like File/Open) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1502 - 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
|
1503 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
|
1504 - 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
|
1505 menu_data must contain a "jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1506 - C.MENU_JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1507 commands, jid is already filled) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1508 menu_data must contain a "jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1509 - C.MENU_ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1510 roster. |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1511 menu_data must contain a "room_jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1512 - C.MENU_ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1513 microblog, group is already filled) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1514 menu_data must contain a "group" data |
2126 | 1515 @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
|
1516 """ |
773 | 1517 |
1518 if callable(callback): | |
1519 callback_id = self.registerCallback(callback, with_data=True) | |
3028 | 1520 elif isinstance(callback, str): |
773 | 1521 # The callback is already registered |
1522 callback_id = callback | |
1523 try: | |
1524 callback, args, kwargs = self._cb_map[callback_id] | |
1525 except KeyError: | |
1526 raise exceptions.DataError("Unknown callback id") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1527 kwargs["with_data"] = True # we have to be sure that we use extra data |
773 | 1528 else: |
1529 raise exceptions.DataError("Unknown callback type") | |
1530 | |
3028 | 1531 for menu_data in self._menus.values(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1532 if menu_data["path"] == path and menu_data["type"] == type_: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1533 raise exceptions.ConflictError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1534 _("A menu with the same path and type already exists") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1535 ) |
773 | 1536 |
2126 | 1537 path_canonical = self._getMenuCanonicalPath(path) |
1538 menu_key = (type_, path_canonical) | |
1539 | |
1540 if menu_key in self._menus_paths: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1541 raise exceptions.ConflictError( |
3028 | 1542 "this menu path is already used: {path} ({menu_key})".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1543 path=path_canonical, menu_key=menu_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1544 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1545 ) |
2126 | 1546 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1547 menu_data = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1548 "path": tuple(path), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1549 "path_canonical": path_canonical, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1550 "security_limit": security_limit, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1551 "help_string": help_string, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1552 "type": type_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1553 } |
773 | 1554 |
1555 self._menus[callback_id] = menu_data | |
2126 | 1556 self._menus_paths[menu_key] = callback_id |
773 | 1557 |
1558 return callback_id | |
101 | 1559 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1560 def getMenus(self, language="", security_limit=C.NO_SECURITY_LIMIT): |
773 | 1561 """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
|
1562 |
773 | 1563 @param language: language used for translation, or empty string for default |
1564 @param security_limit: %(doc_security_limit)s | |
1565 @return: array of tuple with: | |
1566 - menu id (same as callback_id) | |
1567 - menu type | |
1568 - raw menu path (array of strings) | |
1569 - 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
|
1570 - 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
|
1571 - 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
|
1572 - help_url: link to a page with more complete documentation (TODO) |
773 | 1573 """ |
1574 ret = [] | |
3028 | 1575 for menu_id, menu_data in self._menus.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1576 type_ = menu_data["type"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1577 path = menu_data["path"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1578 menu_security_limit = menu_data["security_limit"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1579 if security_limit != C.NO_SECURITY_LIMIT and ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1580 menu_security_limit == C.NO_SECURITY_LIMIT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1581 or menu_security_limit > security_limit |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1582 ): |
809 | 1583 continue |
773 | 1584 languageSwitch(language) |
1585 path_i18n = [_(elt) for elt in path] | |
1586 languageSwitch() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1587 extra = {} # TODO: manage extra data like icon |
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
|
1588 ret.append((menu_id, type_, path, path_i18n, extra)) |
773 | 1589 |
1590 return ret | |
1591 | |
2879 | 1592 def _launchMenu(self, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT, |
1593 profile_key=C.PROF_KEY_NONE): | |
2126 | 1594 client = self.getClient(profile_key) |
1595 return self.launchMenu(client, menu_type, path, data, security_limit) | |
1596 | |
2879 | 1597 def launchMenu(self, client, menu_type, path, data=None, |
1598 security_limit=C.NO_SECURITY_LIMIT): | |
2126 | 1599 """launch action a menu action |
1600 | |
1601 @param menu_type(unicode): type of menu to launch | |
1602 @param path(iterable[unicode]): canonical path of the menu | |
1603 @params data(dict): menu data | |
1604 @raise NotFound: this path is not known | |
1605 """ | |
1606 # FIXME: manage security_limit here | |
1607 # defaut security limit should be high instead of C.NO_SECURITY_LIMIT | |
1608 canonical_path = self._getMenuCanonicalPath(path) | |
1609 menu_key = (menu_type, canonical_path) | |
1610 try: | |
1611 callback_id = self._menus_paths[menu_key] | |
1612 except KeyError: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1613 raise exceptions.NotFound( |
3028 | 1614 "Can't find menu {path} ({menu_type})".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1615 path=canonical_path, menu_type=menu_type |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1616 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1617 ) |
2126 | 1618 return self.launchCallback(callback_id, data, client.profile) |
1619 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1620 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
|
1621 """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
|
1622 |
773 | 1623 @param menu_id: id of the menu (same as callback_id) |
1624 @param language: language used for translation, or empty string for default | |
1625 @param return: translated help | |
1626 | |
1627 """ | |
101 | 1628 try: |
773 | 1629 menu_data = self._menus[menu_id] |
101 | 1630 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
|
1631 raise exceptions.DataError("Trying to access an unknown menu") |
773 | 1632 languageSwitch(language) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1633 help_string = _(menu_data["help_string"]) |
773 | 1634 languageSwitch() |
1635 return help_string |