Mercurial > libervia-backend
annotate libervia/backend/core/main.py @ 4167:319a0e47dc8b
plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
the plugin was using python-dbus which is deprecated in the backend in the favor of
TxDBus. Methods calls have been updated, and the plugin works again, but there seems to be
still some issues (warnings in the logs). Those will be fixed later.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Dec 2023 15:22:55 +0100 |
parents | 02f0adc745c6 |
children | 3b95704ab777 |
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 |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
26 |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
27 from wokkel.data_form import Option |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
28 from libervia import backend |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
29 from libervia.backend.core.i18n import _, D_, language_switch |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
30 from libervia.backend.core import patches |
2687
e9cd473a2f46
core (xmpp): server certificate validation:
Goffi <goffi@goffi.org>
parents:
2666
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 from twisted.words.protocols.jabber import jid |
0 | 35 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
|
36 from wokkel.xmppim import RosterItem |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
37 from libervia.backend.core import xmpp |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
38 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
39 from libervia.backend.core.core_types import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
40 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
41 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
42 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
43 from libervia.backend.memory import memory |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
44 from libervia.backend.memory import cache |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
45 from libervia.backend.memory import encryption |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
46 from libervia.backend.tools import async_trigger as trigger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
47 from libervia.backend.tools import utils |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
48 from libervia.backend.tools import image |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
49 from libervia.backend.tools.common import dynamic_import |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
50 from libervia.backend.tools.common import regex |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
51 from libervia.backend.tools.common import data_format |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
52 from libervia.backend.stdui import ui_contact_list, ui_profile_manager |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
53 import libervia.backend.plugins |
0 | 54 |
2691
1ecceac3df96
plugin XEP-0198: Stream Management implementation:
Goffi <goffi@goffi.org>
parents:
2689
diff
changeset
|
55 |
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
|
56 log = getLogger(__name__) |
0 | 57 |
4072
040095a5dc7f
refactoring: rename `SAT` class to `LiberviaBackend`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
58 class LiberviaBackend(service.Service): |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
59 |
3110
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
60 def _init(self): |
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
61 # 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
|
62 # this _init is called in startService |
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
63 log.info(f"{C.APP_NAME} {self.full_version}") |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
64 self._cb_map = {} # map from callback_id to callbacks |
3912
ce5d03772689
core (main): `OrderedDict` is not necesasry here anymore, as `dict` are now ordered
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
65 # dynamic menus. key: callback_id, value: menu data (dictionnary) |
ce5d03772689
core (main): `OrderedDict` is not necesasry here anymore, as `dict` are now ordered
Goffi <goffi@goffi.org>
parents:
3911
diff
changeset
|
66 self._menus = {} |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
67 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
|
68 # 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
|
69 self.initialised = defer.Deferred() |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
70 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
|
71 self.plugins = {} |
2688
943e78e18882
core (xmpp): added missing disco#info namespace to disco info result.
Goffi <goffi@goffi.org>
parents:
2687
diff
changeset
|
72 # map for short name to whole namespace, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
73 # extended by plugins with register_namespace |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
74 self.ns_map = { |
3028 | 75 "x-data": xmpp.NS_X_DATA, |
76 "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
|
77 } |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
78 |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
79 self.memory = memory.Memory(self) |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
80 |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
81 # trigger are used to change Libervia behaviour |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
82 self.trigger = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
83 trigger.TriggerManager() |
3088
d1464548055a
plugin file download: meta plugin to handle file download:
Goffi <goffi@goffi.org>
parents:
3066
diff
changeset
|
84 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
85 |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
86 bridge_name = ( |
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
87 os.getenv("LIBERVIA_BRIDGE_NAME") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
88 or self.memory.config_get("", "bridge", "dbus") |
3634
3c7a64d6f49f
bridge: bridge can now be set using environment variable:
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
89 ) |
2088
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
90 |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
91 bridge_module = dynamic_import.bridge(bridge_name) |
c02f96756d5c
core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
97 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
|
98 except exceptions.BridgeInitError: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
99 log.exception("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
|
100 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
|
101 |
3989
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
102 defer.ensureDeferred(self._post_init()) |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
103 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
104 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
105 def version(self): |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
106 """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
|
107 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
|
108 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
109 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
110 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
|
111 """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
|
112 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
113 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
|
114 """ |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
115 version = self.version |
4079
10b6ad569157
version: use standard Python's `dev0` instead of Libervia specific `D` for dev version
Goffi <goffi@goffi.org>
parents:
4073
diff
changeset
|
116 if version.split(".")[-1] == "dev0": |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
117 # 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
|
118 try: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
119 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
|
120 except AttributeError: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
121 self._version_cache = "{} « {} » ({})".format( |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
122 version, C.APP_RELEASE_NAME, utils.get_repository_data(backend) |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
123 ) |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
124 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
|
125 else: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
126 return version |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
127 |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
128 @property |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
129 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
|
130 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
|
131 |
3989
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
132 async def _post_init(self): |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
133 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
134 bridge_pi = self.bridge.post_init |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
135 except AttributeError: |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
136 pass |
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
137 else: |
3989
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
138 try: |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
139 await bridge_pi() |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
140 except Exception: |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
141 log.exception("Could not initialize bridge") |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
142 # because init is not complete at this stage, we use callLater |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
143 reactor.callLater(0, self.stop) |
f5ba7594cced
core (main): log Exception when `bridge_pi` fails
Goffi <goffi@goffi.org>
parents:
3932
diff
changeset
|
144 return |
3539
60d3861e5996
bridge (dbus): use Tx DBus for backend part of D-Bus bridge:
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
145 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
146 self.bridge.register_method("ready_get", lambda: self.initialised) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
147 self.bridge.register_method("version_get", lambda: self.full_version) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
148 self.bridge.register_method("features_get", self.features_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
149 self.bridge.register_method("profile_name_get", self.memory.get_profile_name) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
150 self.bridge.register_method("profiles_list_get", self.memory.get_profiles_list) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
151 self.bridge.register_method("entity_data_get", self.memory._get_entity_data) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
152 self.bridge.register_method("entities_data_get", self.memory._get_entities_data) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
153 self.bridge.register_method("profile_create", self.memory.create_profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
154 self.bridge.register_method("profile_delete_async", self.memory.profile_delete_async) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
155 self.bridge.register_method("profile_start_session", self.memory.start_session) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
156 self.bridge.register_method( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
157 "profile_is_session_started", self.memory._is_session_started |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
158 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
159 self.bridge.register_method("profile_set_default", self.memory.profile_set_default) |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
160 self.bridge.register_method("connect", self._connect) |
2086 | 161 self.bridge.register_method("disconnect", self.disconnect) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
162 self.bridge.register_method("contact_get", self._contact_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
163 self.bridge.register_method("contacts_get", self.contacts_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
164 self.bridge.register_method("contacts_get_from_group", self.contacts_get_from_group) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
165 self.bridge.register_method("main_resource_get", self.memory._get_main_resource) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
166 self.bridge.register_method( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
167 "presence_statuses_get", self.memory._get_presence_statuses |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
168 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
169 self.bridge.register_method("sub_waiting_get", self.memory.sub_waiting_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
170 self.bridge.register_method("message_send", self._message_send) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
171 self.bridge.register_method("message_encryption_start", |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
172 self._message_encryption_start) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
173 self.bridge.register_method("message_encryption_stop", |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
174 self._message_encryption_stop) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
175 self.bridge.register_method("message_encryption_get", |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
176 self._message_encryption_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
177 self.bridge.register_method("encryption_namespace_get", |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
178 self._encryption_namespace_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
179 self.bridge.register_method("encryption_plugins_get", self._encryption_plugins_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
180 self.bridge.register_method("encryption_trust_ui_get", self._encryption_trust_ui_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
181 self.bridge.register_method("config_get", self._get_config) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
182 self.bridge.register_method("param_set", self.param_set) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
183 self.bridge.register_method("param_get_a", self.memory.get_string_param_a) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
184 self.bridge.register_method("private_data_get", self.memory._private_data_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
185 self.bridge.register_method("private_data_set", self.memory._private_data_set) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
186 self.bridge.register_method("private_data_delete", self.memory._private_data_delete) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
187 self.bridge.register_method("param_get_a_async", self.memory.async_get_string_param_a) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
188 self.bridge.register_method( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
189 "params_values_from_category_get_async", |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
190 self.memory._get_params_values_from_category, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
191 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
192 self.bridge.register_method("param_ui_get", self.memory._get_params_ui) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
193 self.bridge.register_method( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
194 "params_categories_get", self.memory.params_categories_get |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
195 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
196 self.bridge.register_method("params_register_app", self.memory.params_register_app) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
197 self.bridge.register_method("history_get", self.memory._history_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
198 self.bridge.register_method("presence_set", self._set_presence) |
2086 | 199 self.bridge.register_method("subscription", self.subscription) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
200 self.bridge.register_method("contact_add", self._add_contact) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
201 self.bridge.register_method("contact_update", self._update_contact) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
202 self.bridge.register_method("contact_del", self._del_contact) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
203 self.bridge.register_method("roster_resync", self._roster_resync) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
204 self.bridge.register_method("is_connected", self.is_connected) |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
205 self.bridge.register_method("action_launch", self._action_launch) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
206 self.bridge.register_method("actions_get", self.actions_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
207 self.bridge.register_method("progress_get", self._progress_get) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
208 self.bridge.register_method("progress_get_all", self._progress_get_all) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
209 self.bridge.register_method("menus_get", self.get_menus) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
210 self.bridge.register_method("menu_help_get", self.get_menu_help) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
211 self.bridge.register_method("menu_launch", self._launch_menu) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
212 self.bridge.register_method("disco_infos", self.memory.disco._disco_infos) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
213 self.bridge.register_method("disco_items", self.memory.disco._disco_items) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
214 self.bridge.register_method("disco_find_by_features", self._find_by_features) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
215 self.bridge.register_method("params_template_save", self.memory.save_xml) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
216 self.bridge.register_method("params_template_load", self.memory.load_xml) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
217 self.bridge.register_method("session_infos_get", self.get_session_infos) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
218 self.bridge.register_method("devices_infos_get", self._get_devices_infos) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
219 self.bridge.register_method("namespaces_get", self.get_namespaces) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
220 self.bridge.register_method("image_check", self._image_check) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
221 self.bridge.register_method("image_resize", self._image_resize) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
222 self.bridge.register_method("image_generate_preview", self._image_generate_preview) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
223 self.bridge.register_method("image_convert", self._image_convert) |
4130
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4079
diff
changeset
|
224 self.bridge.register_method("notification_add", self.memory._add_notification) |
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4079
diff
changeset
|
225 self.bridge.register_method("notifications_get", self.memory._get_notifications) |
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4079
diff
changeset
|
226 self.bridge.register_method("notification_delete", self.memory._delete_notification) |
02f0adc745c6
core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
4079
diff
changeset
|
227 self.bridge.register_method("notifications_expired_clean", self.memory._notifications_expired_clean) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
228 |
0 | 229 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
230 await self.memory.initialise() |
2509
d485e9416493
core (memory/cache): common cache:
Goffi <goffi@goffi.org>
parents:
2496
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 except Exception as e: |
3649
4a89342476e9
core (sat_main): fix the "Could not initialize backend" error logging
Goffi <goffi@goffi.org>
parents:
3634
diff
changeset
|
238 log.error(f"Could not initialize backend: {e}") |
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
|
239 sys.exit(1) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
240 self._add_base_menus() |
3120 | 241 |
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
|
242 self.initialised.callback(None) |
3028 | 243 log.info(_("Backend is ready")) |
0 | 244 |
3120 | 245 # profile autoconnection must be done after self.initialised is called because |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
246 # start_session waits for it. |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
247 autoconnect_dict = await self.memory.storage.get_ind_param_values( |
3120 | 248 category='Connection', name='autoconnect_backend', |
249 ) | |
250 profiles_autoconnect = [p for p, v in autoconnect_dict.items() if C.bool(v)] | |
251 if not self.trigger.point("profilesAutoconnect", profiles_autoconnect): | |
252 return | |
253 if profiles_autoconnect: | |
254 log.info(D_( | |
255 "Following profiles will be connected automatically: {profiles}" | |
256 ).format(profiles= ', '.join(profiles_autoconnect))) | |
257 connect_d_list = [] | |
258 for profile in profiles_autoconnect: | |
259 connect_d_list.append(defer.ensureDeferred(self.connect(profile))) | |
260 | |
261 if connect_d_list: | |
262 results = await defer.DeferredList(connect_d_list) | |
263 for idx, (success, result) in enumerate(results): | |
264 if not success: | |
265 profile = profiles_autoconnect[0] | |
266 log.warning( | |
267 _("Can't autoconnect profile {profile}: {reason}").format( | |
268 profile = profile, | |
269 reason = result) | |
270 ) | |
271 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
272 def _add_base_menus(self): |
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
|
273 """Add base menus""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
274 encryption.EncryptionHandler._import_menus(self) |
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
|
275 |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
276 def _unimport_plugin(self, plugin_path): |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
277 """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
|
278 try: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
279 del sys.modules[plugin_path] |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
280 except KeyError: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
281 pass |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
282 |
0 | 283 def _import_plugins(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
284 """import all plugins found in plugins directory""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
285 # FIXME: module imported but cancelled should be deleted |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
286 # 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
|
287 # FIXME: should use imp |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
288 # 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
|
289 # if we just use a client, and plugin blacklisting should be possible in |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
290 # libervia.conf |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
291 plugins_path = Path(libervia.backend.plugins.__file__).parent |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
292 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
|
293 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
|
294 if plug_path.is_dir(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
295 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
|
296 if not init_path.exists(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
297 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
298 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
|
299 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
300 plug_name = plug_path.name |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
301 elif plug_path.is_file(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
302 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
|
303 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
304 plug_name = plug_path.stem |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
305 else: |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
306 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
307 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
|
308 continue |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
309 if not plug_name.isidentifier(): |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
310 log.warning( |
2157880ba3b4
core: plugins can now be loaded from a directory:
Goffi <goffi@goffi.org>
parents:
3295
diff
changeset
|
311 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
|
312 continue |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4043
diff
changeset
|
313 plugin_path = f"libervia.backend.plugins.{plug_name}" |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
314 try: |
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
315 __import__(plugin_path) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
316 except exceptions.MissingModule as e: |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
317 self._unimport_plugin(plugin_path) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
318 log.warning( |
3028 | 319 "Can't import plugin [{path}] because of an unavailale third party " |
320 "module:\n{msg}".format( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
321 path=plugin_path, msg=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
322 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
323 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
324 continue |
2100 | 325 except exceptions.CancelError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
326 log.info( |
3028 | 327 "Plugin [{path}] cancelled its own import: {msg}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
328 path=plugin_path, msg=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
329 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
330 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
331 self._unimport_plugin(plugin_path) |
2100 | 332 continue |
3040 | 333 except Exception: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
334 import traceback |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
335 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
336 log.error( |
3028 | 337 _("Can't import plugin [{path}]:\n{error}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
338 path=plugin_path, error=traceback.format_exc() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
339 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
340 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
341 self._unimport_plugin(plugin_path) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
342 continue |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
343 mod = sys.modules[plugin_path] |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
344 plugin_info = mod.PLUGIN_INFO |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
345 import_name = plugin_info["import_name"] |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
346 |
3028 | 347 plugin_modes = plugin_info["modes"] = set( |
348 plugin_info.setdefault("modes", C.PLUG_MODE_DEFAULT) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
349 ) |
3650
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
350 if not plugin_modes.intersection(C.PLUG_MODE_BOTH): |
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
351 log.error( |
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
352 f"Can't import plugin at {plugin_path}, invalid {C.PI_MODES!r} " |
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
353 f"value: {plugin_modes!r}" |
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
354 ) |
760f3ff05092
core (main): check plugin modes and skip pluggin/log an error if value is invalid
Goffi <goffi@goffi.org>
parents:
3649
diff
changeset
|
355 continue |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
356 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
357 # if the plugin is an entry point, it must work in component mode |
3028 | 358 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
|
359 # if plugin is an entrypoint, we cache it |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
360 if C.PLUG_MODE_COMPONENT not in plugin_modes: |
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 "{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
|
364 ).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
|
365 ) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
366 self._unimport_plugin(plugin_path) |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
367 continue |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
368 |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
369 if import_name in plugins_to_import: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
370 log.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
371 _( |
3028 | 372 "Name conflict for import name [{import_name}], can't import " |
373 "plugin [{name}]" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
374 ).format(**plugin_info) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
375 ) |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
376 continue |
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
377 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
|
378 while True: |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
379 try: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
380 self._import_plugins_from_dict(plugins_to_import) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
381 except ImportError: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
382 pass |
1503
f681788097ba
core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents:
1491
diff
changeset
|
383 if not plugins_to_import: |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
384 break |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
385 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
386 def _import_plugins_from_dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
387 self, plugins_to_import, import_name=None, optional=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
388 ): |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
389 """Recursively import and their dependencies in the right order |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
390 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
391 @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
|
392 plugin_info) |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
393 @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
|
394 PLUGIN_INFO['import_name'] |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
395 @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
|
396 is raised |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
397 """ |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
398 if import_name in self.plugins: |
3028 | 399 log.debug("Plugin {} already imported, passing".format(import_name)) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
400 return |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
401 if not import_name: |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
402 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
|
403 else: |
288
76247af9917c
core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
404 if not import_name in plugins_to_import: |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
405 if optional: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
406 log.warning( |
3028 | 407 _("Recommended plugin not found: {}").format(import_name) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
408 ) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
409 return |
3028 | 410 msg = "Dependency not found: {}".format(import_name) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
411 log.error(msg) |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
412 raise ImportError(msg) |
287
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
413 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
|
414 dependencies = plugin_info.setdefault("dependencies", []) |
925
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
415 recommendations = plugin_info.setdefault("recommendations", []) |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
416 for to_import in dependencies + recommendations: |
5c78cefd233f
core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents:
923
diff
changeset
|
417 if to_import not in self.plugins: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
418 log.debug( |
3028 | 419 "Recursively import dependency of [%s]: [%s]" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
420 % (import_name, to_import) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
421 ) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
422 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
423 self._import_plugins_from_dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
424 plugins_to_import, to_import, to_import not in dependencies |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
425 ) |
1145
4e1a0a1523f1
core: more robust plugins importation
Goffi <goffi@goffi.org>
parents:
1130
diff
changeset
|
426 except ImportError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
427 log.warning( |
3028 | 428 _("Can't import plugin {name}: {error}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
429 name=plugin_info["name"], error=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
430 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
431 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
432 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
433 return |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
434 raise e |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
435 log.info("importing plugin: {}".format(plugin_info["name"])) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
436 # we instanciate the plugin here |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
437 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
438 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
|
439 except Exception as e: |
4019
7bf7677b893d
core: log a traceback if a plugin can't be loaded
Goffi <goffi@goffi.org>
parents:
3989
diff
changeset
|
440 log.exception( |
7bf7677b893d
core: log a traceback if a plugin can't be loaded
Goffi <goffi@goffi.org>
parents:
3989
diff
changeset
|
441 f"Can't load plugin \"{plugin_info['name']}\", ignoring it: {e}" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
442 ) |
1535
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
443 if optional: |
c9ef16de3f13
core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents:
1533
diff
changeset
|
444 return |
3028 | 445 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
|
446 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
|
447 self.plugins[import_name].is_handler = True |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
448 else: |
2720536b5a22
core: added plugin dependency management
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
449 self.plugins[import_name].is_handler = False |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
450 # we keep metadata as a Class attribute |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
451 self.plugins[import_name]._info = plugin_info |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
452 # TODO: test xmppclient presence and register handler parent |
0 | 453 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
454 def plugins_unload(self): |
1550 | 455 """Call unload method on every loaded plugin, if exists |
456 | |
457 @return (D): A deferred which return None when all method have been called | |
458 """ | |
459 # TODO: in the futur, it should be possible to hot unload a plugin | |
460 # pluging depending on the unloaded one should be unloaded too | |
461 # for now, just a basic call on plugin.unload is done | |
462 defers_list = [] | |
3028 | 463 for plugin in self.plugins.values(): |
1550 | 464 try: |
465 unload = plugin.unload | |
466 except AttributeError: | |
467 continue | |
468 else: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
469 defers_list.append(utils.as_deferred(unload)) |
1550 | 470 return defers_list |
471 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
472 def _connect(self, profile_key, password="", options=None): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
473 profile = self.memory.get_profile_name(profile_key) |
3120 | 474 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
|
475 |
3120 | 476 async def connect( |
477 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
|
478 """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
|
479 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
480 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
|
481 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
|
482 @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
|
483 @param password (string): the Libervia profile password |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
484 @param options (dict): connection options. Key can be: |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
485 - |
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
|
486 @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
|
487 @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
|
488 - 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
|
489 - 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
|
490 @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
|
491 """ |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2138
diff
changeset
|
492 if options is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
493 options = {} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
494 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
495 await self.memory.start_session(password, profile) |
3120 | 496 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
497 if self.is_connected(profile): |
3120 | 498 log.info(_("already connected !")) |
499 return True | |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
500 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
501 if self.memory.is_component(profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
502 await xmpp.SatXMPPComponent.start_connection(self, profile, max_retries) |
3120 | 503 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
504 await xmpp.SatXMPPClient.start_connection(self, profile, max_retries) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
505 |
3120 | 506 return False |
1019 | 507 |
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
|
508 def disconnect(self, profile_key): |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
509 """disconnect from jabber server""" |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
510 # 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
|
511 # it shoud be deleted only when session is finished |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
512 if not self.is_connected(profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
513 # is_connected is checked here and not on client |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
514 # because client is deleted when session is ended |
3028 | 515 log.info(_("not connected !")) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
516 return defer.succeed(None) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
517 client = self.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
518 return client.entity_disconnect() |
6
5799493fa548
connection and disconnection management
Goffi <goffi@goffi.org>
parents:
5
diff
changeset
|
519 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
520 def features_get(self, profile_key=C.PROF_KEY_NONE): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
521 """Get available features |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
522 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
523 Return list of activated plugins and plugin specific data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
524 @param profile_key: %(doc_profile_key)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
525 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
|
526 dependent) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
527 @return (dict)[Deferred]: features data where: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
528 - 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
|
529 - 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
|
530 this dict is return by plugin's getFeature method. |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
531 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
|
532 """ |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
533 try: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
534 # FIXME: there is no method yet to check profile session |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
535 # as soon as one is implemented, it should be used here |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
536 self.get_client(profile_key) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
537 except KeyError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
538 log.warning("Requesting features for a profile outside a session") |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
539 profile_key = C.PROF_KEY_NONE |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
540 except exceptions.ProfileNotSetError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
541 pass |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
542 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
543 features = [] |
3028 | 544 for import_name, plugin in self.plugins.items(): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
545 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
546 features_d = utils.as_deferred(plugin.features_get, profile_key) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
547 except AttributeError: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
548 features_d = defer.succeed({}) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
549 features.append(features_d) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
550 |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
551 d_list = defer.DeferredList(features) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
552 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
553 def build_features(result, import_names): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
554 assert len(result) == len(import_names) |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
555 ret = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
556 for name, (success, data) in zip(import_names, result): |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
557 if success: |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
558 ret[name] = data |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
559 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
560 log.warning( |
3028 | 561 "Error while getting features for {name}: {failure}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
562 name=name, failure=data |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
563 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
564 ) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
565 ret[name] = {} |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
566 return ret |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
567 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
568 d_list.addCallback(build_features, list(self.plugins.keys())) |
1482
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
569 return d_list |
80cd55dd5b04
core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents:
1470
diff
changeset
|
570 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
571 def _contact_get(self, entity_jid_s, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
572 client = self.get_client(profile_key) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
573 entity_jid = jid.JID(entity_jid_s) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
574 return defer.ensureDeferred(self.get_contact(client, entity_jid)) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
575 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
576 async def get_contact(self, client, entity_jid): |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
577 # we want to be sure that roster has been received |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
578 await client.roster.got_roster |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
579 item = client.roster.get_item(entity_jid) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
580 if item is None: |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
581 raise exceptions.NotFound(f"{entity_jid} is not in roster!") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
582 return (client.roster.get_attributes(item), list(item.groups)) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
583 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
584 def contacts_get(self, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
585 client = self.get_client(profile_key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
586 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2733
diff
changeset
|
587 def got_roster(__): |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
588 ret = [] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
589 for item in client.roster.get_items(): # we get all items for client's roster |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
590 # and convert them to expected format |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
591 attr = client.roster.get_attributes(item) |
2977
06f30ad8e110
core: return full jid in bridge's getContacts:
Goffi <goffi@goffi.org>
parents:
2914
diff
changeset
|
592 # 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
|
593 # 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
|
594 ret.append([item.entity.full(), attr, list(item.groups)]) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
595 return ret |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
596 |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
597 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
|
598 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
599 def contacts_get_from_group(self, group, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
600 client = self.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
601 return [jid_.full() for jid_ in client.roster.get_jids_from_group(group)] |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
489
diff
changeset
|
602 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
603 def purge_entity(self, profile): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
604 """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
|
605 |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
606 the garbage collector can then free the memory |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
607 """ |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
608 try: |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
609 del self.profiles[profile] |
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
610 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
611 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
|
612 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
613 self.memory.purge_profile_session(profile) |
416
32dc8b18c2ae
core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
614 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
615 def startService(self): |
3110
3fcc99b2d6b7
core (sat_main): avoid double init + log version
Goffi <goffi@goffi.org>
parents:
3102
diff
changeset
|
616 self._init() |
3028 | 617 log.info("Salut à toi ô mon frère !") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
618 |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
12
diff
changeset
|
619 def stopService(self): |
3028 | 620 log.info("Salut aussi à Rantanplan") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
621 return self.plugins_unload() |
0 | 622 |
623 def run(self): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
624 log.debug(_("running app")) |
0 | 625 reactor.run() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
626 |
0 | 627 def stop(self): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
628 log.debug(_("stopping app")) |
0 | 629 reactor.stop() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
630 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
631 ## Misc methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
632 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
633 def get_jid_n_stream(self, profile_key): |
64 | 634 """Convenient method to get jid and stream from profile key |
635 @return: tuple (jid, xmlstream) from profile, can be None""" | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
636 # TODO: deprecate this method (get_client is enough) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
637 profile = self.memory.get_profile_name(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
638 if not profile or not self.profiles[profile].is_connected(): |
64 | 639 return (None, None) |
640 return (self.profiles[profile].jid, self.profiles[profile].xmlstream) | |
641 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
642 def get_client(self, profile_key: str) -> xmpp.SatXMPPClient: |
64 | 643 """Convenient method to get client from profile key |
1624 | 644 |
3911
8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
Syndace <me@syndace.dev>
parents:
3779
diff
changeset
|
645 @return: the client |
1624 | 646 @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist |
647 @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
|
648 This happen if profile has not been used yet |
1624 | 649 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
650 profile = self.memory.get_profile_name(profile_key) |
64 | 651 if not profile: |
1624 | 652 raise exceptions.ProfileKeyUnknown |
653 try: | |
654 return self.profiles[profile] | |
655 except KeyError: | |
2445
0199c0bd4c60
core: specify profile on NotFound exception
Goffi <goffi@goffi.org>
parents:
2443
diff
changeset
|
656 raise exceptions.NotFound(profile_key) |
64 | 657 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
658 def get_clients(self, profile_key): |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
659 """Convenient method to get list of clients from profile key |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
660 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
661 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
|
662 @param profile_key: %(doc_profile_key)s |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
663 @return: list of clients |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
664 """ |
2251
83bcd9ec4782
core: fixed profile key detection in getClients + raise DataError on empty profile
Goffi <goffi@goffi.org>
parents:
2176
diff
changeset
|
665 if not profile_key: |
3028 | 666 raise exceptions.DataError(_("profile_key must not be empty")) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
667 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
668 profile = self.memory.get_profile_name(profile_key, True) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
669 except exceptions.ProfileUnknownError: |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
670 return [] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
671 if profile == C.PROF_KEY_ALL: |
3028 | 672 return list(self.profiles.values()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
673 elif profile[0] == "@": # only profile keys can start with "@" |
1624 | 674 raise exceptions.ProfileKeyUnknown |
728
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
675 return [self.profiles[profile]] |
e07afabc4a25
plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents:
727
diff
changeset
|
676 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
677 def _get_config(self, section, name): |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
678 """Get the main configuration option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
679 |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
680 @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
|
681 @param name: name of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
682 @return: unicode representation of the option |
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
683 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
684 return str(self.memory.config_get(section, name, "")) |
1234
9c17bd37e6e5
core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents:
1189
diff
changeset
|
685 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
686 def log_errback(self, failure_, msg=_("Unexpected error: {failure_}")): |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
687 """Generic errback logging |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
688 |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
689 @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
|
690 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
|
691 """ |
2990
6959c71ab8bf
plugin XEP-0045: log "failure" on configure error
Goffi <goffi@goffi.org>
parents:
2977
diff
changeset
|
692 log.error(msg.format(failure_=failure_)) |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
693 return failure_ |
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
694 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
695 # 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
|
696 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
697 def register_namespace(self, 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
|
698 """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
|
699 if short_name in self.ns_map: |
3028 | 700 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
|
701 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
|
702 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
|
703 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
704 def get_namespaces(self): |
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
|
705 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
|
706 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
707 def get_namespace(self, short_name): |
2914
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
708 try: |
25f14fbd364e
core: added getNamespace method to retrieve a namespace from short name.
Goffi <goffi@goffi.org>
parents:
2892
diff
changeset
|
709 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
|
710 except KeyError: |
3028 | 711 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
|
712 .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
|
713 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
714 def get_session_infos(self, profile_key): |
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
|
715 """compile interesting data on current profile session""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
716 client = self.get_client(profile_key) |
2689
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
717 data = { |
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
718 "jid": client.jid.full(), |
3028 | 719 "started": str(int(client.started)) |
2689
d715d912afac
plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
2688
diff
changeset
|
720 } |
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
|
721 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
|
722 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
723 def _get_devices_infos(self, bare_jid, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
724 client = self.get_client(profile_key) |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
725 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
|
726 bare_jid = None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
727 d = defer.ensureDeferred(self.get_devices_infos(client, bare_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
|
728 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
|
729 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
|
730 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
731 async def get_devices_infos(self, client, bare_jid=None): |
3206
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
732 """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
|
733 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
734 @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
|
735 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
|
736 @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
|
737 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
|
738 - 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
|
739 """ |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
740 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
|
741 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
|
742 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
|
743 else: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
744 bare_jid = jid.JID(bare_jid) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
745 resources = self.memory.get_all_resources(client, bare_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
|
746 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
|
747 # 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
|
748 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
|
749 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
|
750 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
|
751 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
|
752 res_jid.resource = resource |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
753 cache_data = self.memory.entity_data_get(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
|
754 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
|
755 "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
|
756 } |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
757 try: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
758 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
|
759 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
|
760 pass |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
761 else: |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
762 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
|
763 "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
|
764 "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
|
765 "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
|
766 } |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
767 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
768 disco = await self.get_disco_infos(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
|
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 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
|
771 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
|
772 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
|
773 "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
|
774 "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
|
775 "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
|
776 }) |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
777 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
778 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
|
779 |
ae09989e9feb
core, bridge: new `devicesInfosGet` method to get infos on known devices of an entity
Goffi <goffi@goffi.org>
parents:
3201
diff
changeset
|
780 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
|
781 |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
782 # images |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
783 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
784 def _image_check(self, path): |
3220 | 785 report = image.check(self, path) |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
786 return data_format.serialise(report) |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
787 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
788 def _image_resize(self, path, width, height): |
3220 | 789 d = image.resize(path, (width, height)) |
3066
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
790 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
|
791 return d |
2cc2f65379f7
core: added imageCheck and imageResize methods:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
792 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
793 def _image_generate_preview(self, path, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
794 client = self.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
795 d = defer.ensureDeferred(self.image_generate_preview(client, Path(path))) |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
796 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
|
797 return d |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
798 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
799 async def image_generate_preview(self, client, path): |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
800 """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
|
801 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
802 @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
|
803 @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
|
804 """ |
3220 | 805 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
|
806 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
807 if not report['too_large']: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
808 # 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
|
809 preview_path = path |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
810 else: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
811 # 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
|
812 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
|
813 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
|
814 filename = f"{uid}{path.suffix.lower()}" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
815 metadata = client.cache.get_metadata(uid=uid) |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
816 if metadata is not None: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
817 preview_path = metadata['path'] |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
818 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
819 with client.cache.cache_data( |
3201
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
820 source='HOST_PREVIEW', |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
821 uid=uid, |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
822 filename=filename) as cache_f: |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
823 |
3220 | 824 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
|
825 path, |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
826 new_size=report['recommended_size'], |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
827 dest=cache_f |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
828 ) |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
829 |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
830 return preview_path |
439e2f88c3a9
core, bridge: new `imageGeneratePreview` helped method to generate a thumbnail
Goffi <goffi@goffi.org>
parents:
3179
diff
changeset
|
831 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
832 def _image_convert(self, source, dest, extra, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
833 client = self.get_client(profile_key) if profile_key else None |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
834 source = Path(source) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
835 dest = None if not dest else Path(dest) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
836 extra = data_format.deserialise(extra) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
837 d = defer.ensureDeferred(self.image_convert(client, source, dest, extra)) |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
838 d.addCallback(lambda dest_path: str(dest_path)) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
839 return d |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
840 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
841 async def image_convert(self, client, source, dest=None, extra=None): |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
842 """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
|
843 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
844 @param client(SatClient, None): client to use for caching |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
845 this parameter is only used if dest is None |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
846 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
|
847 @param source(Path): path to the image to convert |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
848 @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
|
849 - 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
|
850 file will be converted to PNG |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
851 - Path: path to the file to create/overwrite |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
852 - 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
|
853 @param extra(dict, None): conversion options |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
854 see [image.convert] for details |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
855 @return (Path): path to the converted image |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
856 @raise ValueError: an issue happened with source of dest |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
857 """ |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
858 if not source.is_file: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
859 raise ValueError(f"Source file {source} doesn't exist!") |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
860 if dest is None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
861 # 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
|
862 path_hash = hashlib.sha256(str(source).encode()).hexdigest() |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
863 uid = f"{source.stem}_{path_hash}_convert_png" |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
864 filename = f"{uid}.png" |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
865 if client is None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
866 cache = self.common_cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
867 else: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
868 cache = client.cache |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
869 metadata = cache.get_metadata(uid=uid) |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
870 if metadata is not None: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
871 # there is already a conversion for this image in cache |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
872 return metadata['path'] |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
873 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
874 with cache.cache_data( |
3259
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
875 source='HOST_IMAGE_CONVERT', |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
876 uid=uid, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
877 filename=filename) as cache_f: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
878 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
879 converted_path = await image.convert( |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
880 source, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
881 dest=cache_f, |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
882 extra=extra |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
883 ) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
884 return converted_path |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
885 else: |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
886 return await image.convert(source, dest, extra) |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
887 |
f300d78f08f3
core: image convertion + SVG support:
Goffi <goffi@goffi.org>
parents:
3254
diff
changeset
|
888 |
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
|
889 # 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
|
890 |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
891 def get_local_path( |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
892 self, |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
893 client: Optional[SatXMPPEntity], |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
894 dir_name: str, |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
895 *extra_path: str, |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
896 component: bool = False, |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
897 ) -> Path: |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
898 """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
|
899 |
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
|
900 if path doesn't exist, it will be created |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
901 @param client: client instance |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
902 if not none, client.profile will be used as last path element |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
903 @param dir_name: name of the main path directory |
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
|
904 @param *extra_path: extra path element(s) to use |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
905 @param component: if True, path will be prefixed with C.COMPONENTS_DIR |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
906 @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
|
907 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
908 local_dir = self.memory.config_get("", "local_dir") |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
909 if not local_dir: |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
910 raise exceptions.InternalError("local_dir must be set") |
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
911 path_elts = [] |
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
|
912 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
|
913 path_elts.append(C.COMPONENTS_DIR) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
914 path_elts.append(regex.path_escape(dir_name)) |
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
|
915 if extra_path: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
916 path_elts.extend([regex.path_escape(p) for p in extra_path]) |
3932
7af29260ecb8
core: fix and renamed getLocalPath -> get_local_path:
Goffi <goffi@goffi.org>
parents:
3912
diff
changeset
|
917 if client is not None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
918 path_elts.append(regex.path_escape(client.profile)) |
3285
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
919 local_path = Path(*path_elts) |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
920 local_path.mkdir(0o700, parents=True, exist_ok=True) |
4240b44842bb
core: getLocalPath now returns a Path
Goffi <goffi@goffi.org>
parents:
3259
diff
changeset
|
921 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
|
922 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
923 ## Client management ## |
0 | 924 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
925 def param_set(self, name, value, category, security_limit, profile_key): |
0 | 926 """set wanted paramater and notice observers""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
927 self.memory.param_set(name, value, category, security_limit, profile_key) |
0 | 928 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
929 def is_connected(self, profile_key): |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
930 """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
|
931 |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
932 @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
|
933 @return: True if connected |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
934 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
935 profile = self.memory.get_profile_name(profile_key) |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
936 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
937 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
|
938 raise exceptions.ProfileUnknownError(profile_key) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
939 if profile not in self.profiles: |
62
93cb45a7420f
SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents:
60
diff
changeset
|
940 return False |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
941 return self.profiles[profile].is_connected() |
0 | 942 |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
943 ## Encryption ## |
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
944 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
945 def register_encryption_plugin(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
946 return encryption.EncryptionHandler.register_plugin(*args, **kwargs) |
2646
712cb4ff3e13
core: new EncryptionHandler class which manage encrypted session as a core feature:
Goffi <goffi@goffi.org>
parents:
2645
diff
changeset
|
947 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
948 def _message_encryption_start(self, to_jid_s, namespace, replace=False, |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
949 profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
950 client = self.get_client(profile_key) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
951 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
|
952 return defer.ensureDeferred( |
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
953 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
|
954 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
955 def _message_encryption_stop(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
956 client = self.get_client(profile_key) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
957 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
|
958 return defer.ensureDeferred( |
2f406b762788
core (memory/encryption): encryption session are now restored on client connection
Goffi <goffi@goffi.org>
parents:
3220
diff
changeset
|
959 client.encryption.stop(to_jid)) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
960 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
961 def _message_encryption_get(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
962 client = self.get_client(profile_key) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
963 to_jid = jid.JID(to_jid_s) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
964 session_data = client.encryption.getSession(to_jid) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
965 return client.encryption.get_bridge_data(session_data) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
966 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
967 def _encryption_namespace_get(self, name): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
968 return encryption.EncryptionHandler.get_ns_from_name(name) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
969 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
970 def _encryption_plugins_get(self): |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
971 plugins = encryption.EncryptionHandler.getPlugins() |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
972 ret = [] |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
973 for p in plugins: |
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
974 ret.append({ |
3028 | 975 "name": p.name, |
976 "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
|
977 "priority": p.priority, |
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3088
diff
changeset
|
978 "directed": p.directed, |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
979 }) |
3102
7574f795bd1e
core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents:
3088
diff
changeset
|
980 return data_format.serialise(ret) |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
981 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
982 def _encryption_trust_ui_get(self, to_jid_s, namespace, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
983 client = self.get_client(profile_key) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
984 to_jid = jid.JID(to_jid_s) |
3237
b0c57c9a4bd8
plugin XEP-0384: OMEMO trust policy:
Goffi <goffi@goffi.org>
parents:
3226
diff
changeset
|
985 d = defer.ensureDeferred( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
986 client.encryption.get_trust_ui(to_jid, namespace=namespace or None)) |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
987 d.addCallback(lambda xmlui: xmlui.toXml()) |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
988 return d |
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
989 |
1052
e88bff4c8b77
core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents:
1043
diff
changeset
|
990 ## XMPP methods ## |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
991 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
992 def _message_send( |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
993 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
|
994 profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
995 client = self.get_client(profile_key) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
996 to_jid = jid.JID(to_jid_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
997 return client.sendMessage( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
998 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
999 message, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1000 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1001 mess_type, |
3179
84a94b385760
bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents:
3163
diff
changeset
|
1002 data_format.deserialise(extra_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1003 ) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
1004 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1005 def _set_presence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1006 return self.presence_set(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
|
1007 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1008 def presence_set(self, to_jid=None, show="", statuses=None, |
2658
4e130cc9bfc0
core (memore/encryption): new methods and checks:
Goffi <goffi@goffi.org>
parents:
2646
diff
changeset
|
1009 profile_key=C.PROF_KEY_NONE): |
0 | 1010 """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
|
1011 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
|
1012 statuses = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1013 profile = self.memory.get_profile_name(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1014 assert profile |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1015 priority = int( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1016 self.memory.param_get_a("Priority", "Connection", profile_key=profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1017 ) |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1018 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
|
1019 # 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
|
1020 # broadcasted to generating resource) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1021 if "" in statuses: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1022 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop("") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1023 self.bridge.presence_update( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1024 self.profiles[profile].jid.full(), show, int(priority), statuses, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1025 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1026 |
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
|
1027 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
|
1028 """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
|
1029 @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
|
1030 @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
|
1031 @param profile_key: profile""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1032 profile = self.memory.get_profile_name(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1033 assert profile |
50 | 1034 to_jid = jid.JID(raw_jid) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1035 log.debug( |
3028 | 1036 _("subsciption request [%(subs_type)s] for %(jid)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1037 % {"subs_type": subs_type, "jid": to_jid.full()} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1038 ) |
589
d1b4805124a1
Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
1039 if subs_type == "subscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1040 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
|
1041 elif subs_type == "subscribed": |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
79
diff
changeset
|
1042 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
|
1043 elif subs_type == "unsubscribe": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1044 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
|
1045 elif subs_type == "unsubscribed": |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1046 self.profiles[profile].presence.unsubscribed(to_jid) |
0 | 1047 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1048 def _add_contact(self, to_jid_s, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1049 return self.contact_add(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
|
1050 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1051 def contact_add(self, to_jid, profile_key): |
0 | 1052 """Add a contact in roster list""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1053 profile = self.memory.get_profile_name(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1054 assert profile |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1055 # 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
|
1056 # RFC 6121 §3.1.2 |
63
0db25931b60d
SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents:
62
diff
changeset
|
1057 self.profiles[profile].presence.subscribe(to_jid) |
0 | 1058 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1059 def _update_contact(self, to_jid_s, name, groups, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1060 client = self.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1061 return self.contact_update(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
|
1062 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1063 def contact_update(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
|
1064 """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
|
1065 roster_item = RosterItem(to_jid) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1066 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
|
1067 roster_item.groups = set(groups) |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1068 if not self.trigger.point("roster_update", client, roster_item): |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1069 return |
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3237
diff
changeset
|
1070 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
|
1071 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1072 def _del_contact(self, to_jid_s, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1073 return self.contact_del(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
|
1074 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1075 def contact_del(self, to_jid, profile_key): |
0 | 1076 """Remove contact from roster list""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1077 profile = self.memory.get_profile_name(profile_key) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1078 assert profile |
1355
33a21f06551d
core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents:
1325
diff
changeset
|
1079 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
|
1080 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
|
1081 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1082 def _roster_resync(self, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1083 client = self.get_client(profile_key) |
2892
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1084 return client.roster.resync() |
82b781c46841
core: added a rosterResync method to bridge:
Goffi <goffi@goffi.org>
parents:
2886
diff
changeset
|
1085 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1086 ## Discovery ## |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1087 # discovery methods are shortcuts to self.memory.disco |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1088 # 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
|
1089 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1090 def hasFeature(self, *args, **kwargs): |
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1091 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
|
1092 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1093 def check_feature(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1094 return self.memory.disco.check_feature(*args, **kwargs) |
951
027a054c6dda
core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents:
949
diff
changeset
|
1095 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1096 def check_features(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1097 return self.memory.disco.check_features(*args, **kwargs) |
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
|
1098 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1099 def has_identity(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1100 return self.memory.disco.has_identity(*args, **kwargs) |
3718
16e36f0dd1cb
memory (disco), core (main): new `hasIdentity` method
Goffi <goffi@goffi.org>
parents:
3661
diff
changeset
|
1101 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1102 def get_disco_infos(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1103 return self.memory.disco.get_infos(*args, **kwargs) |
0 | 1104 |
944
e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents:
943
diff
changeset
|
1105 def getDiscoItems(self, *args, **kwargs): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1106 return self.memory.disco.get_items(*args, **kwargs) |
0 | 1107 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1108 def find_service_entity(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1109 return self.memory.disco.find_service_entity(*args, **kwargs) |
2431
a9fac72825a2
memory (disco): added findServiceEntity helper method to get first service of a kind
Goffi <goffi@goffi.org>
parents:
2414
diff
changeset
|
1110 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1111 def find_service_entities(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1112 return self.memory.disco.find_service_entities(*args, **kwargs) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1113 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1114 def find_features_set(self, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1115 return self.memory.disco.find_features_set(*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
|
1116 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1117 def _find_by_features(self, namespaces, identities, bare_jids, service, roster, own_jid, |
2666 | 1118 local_device, profile_key): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1119 client = self.get_client(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
|
1120 identities = [tuple(i) for i in identities] if identities else None |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1121 return defer.ensureDeferred(self.find_by_features( |
3140 | 1122 client, namespaces, identities, bare_jids, service, roster, own_jid, |
1123 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
|
1124 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1125 async def find_by_features( |
3295 | 1126 self, |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1127 client: SatXMPPEntity, |
3295 | 1128 namespaces: List[str], |
1129 identities: Optional[List[Tuple[str, str]]]=None, | |
1130 bare_jids: bool=False, | |
1131 service: bool=True, | |
1132 roster: bool=True, | |
1133 own_jid: bool=True, | |
1134 local_device: bool=False | |
1135 ) -> Tuple[ | |
1136 Dict[jid.JID, Tuple[str, str, str]], | |
1137 Dict[jid.JID, Tuple[str, str, str]], | |
1138 Dict[jid.JID, Tuple[str, str, str]] | |
1139 ]: | |
3140 | 1140 """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
|
1141 |
3295 | 1142 @param namespaces: features which must be handled |
1143 @param identities: if not None or empty, | |
1144 only keep those identities | |
1145 tuple must be (category, type) | |
1146 @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
|
1147 if False, retrieve full jid of connected devices |
3295 | 1148 @param service: if True return service from our server |
1149 @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
|
1150 full jid of all matching resources available will be returned |
3295 | 1151 @param own_jid: if True, return profile's jid resources |
1152 @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
|
1153 (i.e. client.jid) |
3295 | 1154 @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
|
1155 - 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
|
1156 - 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
|
1157 - roster entities |
3295 | 1158 Each element is a dict mapping from jid to a tuple with category, type and |
1159 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
|
1160 """ |
2666 | 1161 assert isinstance(namespaces, list) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1162 if not identities: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1163 identities = None |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1164 if not namespaces and not identities: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1165 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1166 "at least one namespace or one identity must be set" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1167 ) |
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
|
1168 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
|
1169 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
|
1170 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
|
1171 if service: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1172 services_jids = await self.find_features_set(client, namespaces) |
2791
034c88e9cd93
core (findByFeatures): fixed services discovery
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
1173 services_jids = list(services_jids) # we need a list to map results below |
3140 | 1174 services_infos = await defer.DeferredList( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1175 [self.get_disco_infos(client, service_jid) for service_jid in services_jids] |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1176 ) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1177 |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1178 for idx, (success, infos) in enumerate(services_infos): |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1179 service_jid = services_jids[idx] |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1180 if not success: |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1181 log.warning( |
3028 | 1182 _("Can't find features for service {service_jid}, ignoring") |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1183 .format(service_jid=service_jid.full())) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1184 continue |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1185 if (identities is not None |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1186 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
|
1187 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1188 found_identities = [ |
3028 | 1189 (cat, type_, name or "") |
1190 for (cat, type_), name in infos.identities.items() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1191 ] |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1192 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
|
1193 |
2666 | 1194 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
|
1195 if own_jid: |
2666 | 1196 to_find.append((found_own, [client.jid.userhostJID()])) |
1197 if roster: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1198 to_find.append((found_roster, client.roster.get_jids())) |
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
|
1199 |
3140 | 1200 for found, jids in to_find: |
1201 full_jids = [] | |
1202 disco_defers = [] | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1203 |
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
|
1204 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
|
1205 if jid_.resource: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1206 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1207 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
|
1208 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
|
1209 else: |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1210 if bare_jids: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1211 resources = [None] |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1212 else: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1213 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1214 resources = self.memory.get_available_resources(client, jid_) |
2536
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1215 except exceptions.UnknownEntityError: |
27539029a662
core: added bare_jid and identities arguments to discoGetByFeatures:
Goffi <goffi@goffi.org>
parents:
2534
diff
changeset
|
1216 continue |
2666 | 1217 if not resources and jid_ == client.jid.userhostJID() and own_jid: |
1218 # small hack to avoid missing our own resource when this | |
1219 # method is called at the very beginning of the session | |
1220 # and our presence has not been received yet | |
1221 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
|
1222 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
|
1223 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
|
1224 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
|
1225 continue |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1226 full_jids.append(full_jid) |
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1227 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1228 disco_defers.append(self.get_disco_infos(client, full_jid)) |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1229 |
3140 | 1230 d_list = defer.DeferredList(disco_defers) |
1231 # XXX: 10 seconds may be too low for slow connections (e.g. mobiles) | |
1232 # but for discovery, that's also the time the user will wait the first time | |
1233 # before seing the page, if something goes wrong. | |
1234 d_list.addTimeout(10, reactor) | |
1235 infos_data = await d_list | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1236 |
3140 | 1237 for idx, (success, infos) in enumerate(infos_data): |
1238 full_jid = full_jids[idx] | |
1239 if not success: | |
1240 log.warning( | |
1241 _("Can't retrieve {full_jid} infos, ignoring") | |
1242 .format(full_jid=full_jid.full())) | |
2767
a97c43dc4924
core: findByFeatures speed improvments:
Goffi <goffi@goffi.org>
parents:
2765
diff
changeset
|
1243 continue |
3140 | 1244 if infos.features.issuperset(namespaces): |
1245 if identities is not None and not set( | |
1246 infos.identities.keys() | |
1247 ).issuperset(identities): | |
1248 continue | |
1249 found_identities = [ | |
1250 (cat, type_, name or "") | |
1251 for (cat, type_), name in infos.identities.items() | |
1252 ] | |
1253 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
|
1254 |
3140 | 1255 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
|
1256 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1257 ## Generic HMI ## |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
579
diff
changeset
|
1258 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1259 def _kill_action(self, keep_id, client): |
3028 | 1260 log.debug("Killing action {} for timeout".format(keep_id)) |
1622 | 1261 client.actions[keep_id] |
1262 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1263 def action_new( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1264 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1265 action_data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1266 security_limit=C.NO_SECURITY_LIMIT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1267 keep_id=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1268 profile=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1269 ): |
4043
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1270 """Shortcut to bridge.action_new which generate an 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
|
1271 |
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 @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
|
1273 @param security_limit: %(doc_security_limit)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1274 @param keep_id(None, unicode): if not None, used to keep action for differed |
4043
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1275 retrieval. The value will be used as callback_id, be sure to use an unique |
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1276 value. |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1277 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
|
1278 @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
|
1279 """ |
1622 | 1280 if keep_id is not None: |
4043
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1281 id_ = keep_id |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1282 client = self.get_client(profile) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1283 action_timer = reactor.callLater(60 * 30, self._kill_action, keep_id, client) |
1622 | 1284 client.actions[keep_id] = (action_data, id_, security_limit, action_timer) |
4043
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1285 else: |
9641ce286e07
core (main): if `keep_id` is set in `action_new`, use it as `action_id`
Goffi <goffi@goffi.org>
parents:
4041
diff
changeset
|
1286 id_ = str(uuid.uuid4()) |
1622 | 1287 |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1288 self.bridge.action_new( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1289 data_format.serialise(action_data), id_, security_limit, profile |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1290 ) |
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
|
1291 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1292 def actions_get(self, profile): |
1622 | 1293 """Return current non answered actions |
1294 | |
1295 @param profile: %(doc_profile)s | |
1296 """ | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1297 client = self.get_client(profile) |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1298 return [ |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1299 (data_format.serialise(action_tuple[0]), *action_tuple[1:-1]) |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1300 for action_tuple in client.actions.values() |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1301 ] |
1622 | 1302 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1303 def register_progress_cb( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1304 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
|
1305 ): |
0 | 1306 """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
|
1307 if metadata is None: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1308 metadata = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1309 client = self.get_client(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1310 if progress_id in client._progress_cb: |
3028 | 1311 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
|
1312 client._progress_cb[progress_id] = (callback, metadata) |
0 | 1313 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1314 def remove_progress_cb(self, progress_id, profile): |
0 | 1315 """Remove a progress callback""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1316 client = self.get_client(profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1317 try: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1318 del client._progress_cb[progress_id] |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1319 except KeyError: |
3028 | 1320 log.error(_("Trying to remove an unknow progress callback")) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1321 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1322 def _progress_get(self, progress_id, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1323 data = self.progress_get(progress_id, profile) |
3028 | 1324 return {k: str(v) for k, v in data.items()} |
0 | 1325 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1326 def progress_get(self, progress_id, profile): |
0 | 1327 """Return a dict with progress information |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1328 |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1329 @param progress_id(unicode): unique id of the progressing element |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1330 @param profile: %(doc_profile)s |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1331 @return (dict): data with the following keys: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1332 'position' (int): current possition |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1333 'size' (int): end_position |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1334 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
|
1335 returned |
0 | 1336 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1337 client = self.get_client(profile) |
0 | 1338 try: |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1339 data = client._progress_cb[progress_id][0](progress_id, profile) |
0 | 1340 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
|
1341 data = {} |
0 | 1342 return data |
1343 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1344 def _progress_get_all(self, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1345 progress_all = self.progress_get_all(profile_key) |
3028 | 1346 for profile, progress_dict in progress_all.items(): |
1347 for progress_id, data in progress_dict.items(): | |
1348 for key, value in data.items(): | |
1349 data[key] = str(value) | |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1350 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1351 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1352 def progress_get_all_metadata(self, profile_key): |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1353 """Return all progress metadata at once |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1354 |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1355 @param profile_key: %(doc_profile)s |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1356 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
|
1357 returned |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1358 @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
|
1359 progress_dict map progress_id to progress_data |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1360 progress_metadata is the same dict as sent by [progress_started] |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1361 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1362 clients = self.get_clients(profile_key) |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1363 progress_all = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1364 for client in clients: |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1365 profile = client.profile |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1366 progress_dict = {} |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1367 progress_all[profile] = progress_dict |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1368 for ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1369 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
|
1370 (__, progress_metadata), |
3028 | 1371 ) in client._progress_cb.items(): |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1372 progress_dict[progress_id] = progress_metadata |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1373 return progress_all |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1374 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1375 def progress_get_all(self, profile_key): |
1626
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1376 """Return all progress status at once |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1377 |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1378 @param profile_key: %(doc_profile)s |
63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents:
1624
diff
changeset
|
1379 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
|
1380 @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
|
1381 progress_dict map progress_id to progress_data |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1382 progress_data is the same dict as returned by [progress_get] |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1383 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1384 clients = self.get_clients(profile_key) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1385 progress_all = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1386 for client in clients: |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1387 profile = client.profile |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1388 progress_dict = {} |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1389 progress_all[profile] = progress_dict |
3028 | 1390 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
|
1391 progress_dict[progress_id] = progress_cb(progress_id, profile) |
1522
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1392 return progress_all |
7d7e57a84792
core: progression handling improvments:
Goffi <goffi@goffi.org>
parents:
1503
diff
changeset
|
1393 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1394 def register_callback(self, callback, *args, **kwargs): |
1603
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1395 """Register a callback. |
2b82d846848e
core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1396 |
2126 | 1397 @param callback(callable): method to call |
1398 @param kwargs: can contain: | |
1399 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
|
1400 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
|
1401 if possible |
2733
e347e32aa07f
core (memory/encryption): new encryptionNamespaceGet and encryptionTrustUIGet methods:
Goffi <goffi@goffi.org>
parents:
2691
diff
changeset
|
1402 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
|
1403 @return: id of the registered callback |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1404 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1405 callback_id = kwargs.pop("force_id", None) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1406 if callback_id is None: |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2147
diff
changeset
|
1407 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
|
1408 else: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1409 if callback_id in self._cb_map: |
3028 | 1410 raise exceptions.ConflictError(_("id already registered")) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1411 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
|
1412 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1413 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
|
1414 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1415 def purge_callback(): |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1416 try: |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1417 self.remove_callback(callback_id) |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1418 except KeyError: |
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1419 pass |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1420 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1421 reactor.callLater(1800, purge_callback) |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1422 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1423 return callback_id |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1424 |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1425 def remove_callback(self, callback_id): |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1426 """ Remove a previously registered callback |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1427 @param callback_id: id returned by [register_callback] """ |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
1428 log.debug("Removing callback [%s]" % callback_id) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1429 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
|
1430 |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1431 def _action_launch( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1432 self, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1433 callback_id: str, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1434 data_s: str, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1435 profile_key: str |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1436 ) -> defer.Deferred: |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1437 d = self.launch_callback( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1438 callback_id, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1439 data_format.deserialise(data_s), |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1440 profile_key |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1441 ) |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1442 d.addCallback(data_format.serialise) |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1443 return d |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1444 |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1445 def launch_callback( |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1446 self, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1447 callback_id: str, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1448 data: Optional[dict] = None, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1449 profile_key: str = C.PROF_KEY_NONE |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1450 ) -> defer.Deferred: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1451 """Launch a specific callback |
2126 | 1452 |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1453 @param callback_id: id of the action (callback) to launch |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1454 @param data: optional data |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1455 @profile_key: %(doc_profile_key)s |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1456 @return: a deferred which fire a dict where key can be: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1457 - xmlui: a XMLUI need to be displayed |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1458 - 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
|
1459 values |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1460 - C.BOOL_TRUE |
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
1234
diff
changeset
|
1461 - C.BOOL_FALSE |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1462 """ |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1463 # FIXME: is it possible to use this method without profile connected? If not, |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1464 # client must be used instead of profile_key |
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1465 # FIXME: security limit need to be checked here |
1622 | 1466 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1467 client = self.get_client(profile_key) |
1624 | 1468 except exceptions.NotFound: |
1469 # client is not available yet | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1470 profile = self.memory.get_profile_name(profile_key) |
1624 | 1471 if not profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1472 raise exceptions.ProfileUnknownError( |
3028 | 1473 _("trying to launch action with a non-existant profile") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1474 ) |
1622 | 1475 else: |
1624 | 1476 profile = client.profile |
1477 # we check if the action is kept, and remove it | |
1478 try: | |
1479 action_tuple = client.actions[callback_id] | |
1480 except KeyError: | |
1481 pass | |
1482 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1483 action_tuple[-1].cancel() # the last item is the action timer |
1624 | 1484 del client.actions[callback_id] |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1485 |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
1486 try: |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1487 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
|
1488 except KeyError: |
3028 | 1489 raise exceptions.DataError("Unknown callback id {}".format(callback_id)) |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1490 |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1491 if kwargs.get("with_data", False): |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1492 if data is None: |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1493 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
|
1494 args, kwargs = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1495 list(args)[:], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1496 kwargs.copy(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1497 ) # we don't want to modify the original (kw)args |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1498 args.insert(0, data) |
1624 | 1499 kwargs["profile"] = profile |
759
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1500 del kwargs["with_data"] |
93bd868b8fb6
backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents:
755
diff
changeset
|
1501 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1502 if kwargs.pop("one_shot", False): |
4041
2594e1951cf7
core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
1503 self.remove_callback(callback_id) |
806
5d6c45d6ee1b
core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents:
801
diff
changeset
|
1504 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1505 return utils.as_deferred(callback, *args, **kwargs) |
0 | 1506 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1507 # Menus management |
101 | 1508 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1509 def _get_menu_canonical_path(self, path): |
2126 | 1510 """give canonical form of path |
1511 | |
1512 canonical form is a tuple of the path were every element is stripped and lowercase | |
1513 @param path(iterable[unicode]): untranslated path to menu | |
1514 @return (tuple[unicode]): canonical form of path | |
1515 """ | |
1516 return tuple((p.lower().strip() for p in path)) | |
1517 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1518 def import_menu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, |
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
|
1519 help_string="", type_=C.MENU_GLOBAL): |
3028 | 1520 r"""register a new menu for frontends |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
1521 |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1522 @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
|
1523 (category/subcategory/.../item) (e.g.: ("File", "Open")) |
773 | 1524 /!\ 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
|
1525 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
|
1526 it must be unique independently of case. |
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1527 @param callback(callable): method to be called when menuitem is selected, callable |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1528 or a callback id (string) as returned by [register_callback] |
2126 | 1529 @param security_limit(int): %(doc_security_limit)s |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1530 /!\ security_limit MUST be added to data in launch_callback if used #TODO |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1531 @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
|
1532 show as a tooltip). |
773 | 1533 /!\ use D_() instead of _() for translations |
2126 | 1534 @param type(unicode): one of: |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1535 - 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
|
1536 something like File/Open) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1537 - 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
|
1538 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
|
1539 - 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
|
1540 menu_data must contain a "jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1541 - 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
|
1542 commands, jid is already filled) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1543 menu_data must contain a "jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1544 - 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
|
1545 roster. |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1546 menu_data must contain a "room_jid" data |
2643
189e38fb11ff
core: style improvments (90 chars limit)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1547 - 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
|
1548 microblog, group is already filled) |
1092
0eefc74c346b
core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
1549 menu_data must contain a "group" data |
2126 | 1550 @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
|
1551 """ |
773 | 1552 |
1553 if callable(callback): | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1554 callback_id = self.register_callback(callback, with_data=True) |
3028 | 1555 elif isinstance(callback, str): |
773 | 1556 # The callback is already registered |
1557 callback_id = callback | |
1558 try: | |
1559 callback, args, kwargs = self._cb_map[callback_id] | |
1560 except KeyError: | |
1561 raise exceptions.DataError("Unknown callback id") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1562 kwargs["with_data"] = True # we have to be sure that we use extra data |
773 | 1563 else: |
1564 raise exceptions.DataError("Unknown callback type") | |
1565 | |
3028 | 1566 for menu_data in self._menus.values(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1567 if menu_data["path"] == path and menu_data["type"] == type_: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1568 raise exceptions.ConflictError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1569 _("A menu with the same path and type already exists") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1570 ) |
773 | 1571 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1572 path_canonical = self._get_menu_canonical_path(path) |
2126 | 1573 menu_key = (type_, path_canonical) |
1574 | |
1575 if menu_key in self._menus_paths: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1576 raise exceptions.ConflictError( |
3028 | 1577 "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
|
1578 path=path_canonical, menu_key=menu_key |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1579 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1580 ) |
2126 | 1581 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1582 menu_data = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1583 "path": tuple(path), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1584 "path_canonical": path_canonical, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1585 "security_limit": security_limit, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1586 "help_string": help_string, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1587 "type": type_, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1588 } |
773 | 1589 |
1590 self._menus[callback_id] = menu_data | |
2126 | 1591 self._menus_paths[menu_key] = callback_id |
773 | 1592 |
1593 return callback_id | |
101 | 1594 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1595 def get_menus(self, language="", security_limit=C.NO_SECURITY_LIMIT): |
773 | 1596 """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
|
1597 |
773 | 1598 @param language: language used for translation, or empty string for default |
1599 @param security_limit: %(doc_security_limit)s | |
1600 @return: array of tuple with: | |
1601 - menu id (same as callback_id) | |
1602 - menu type | |
1603 - raw menu path (array of strings) | |
1604 - 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
|
1605 - 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
|
1606 - 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
|
1607 - help_url: link to a page with more complete documentation (TODO) |
773 | 1608 """ |
1609 ret = [] | |
3028 | 1610 for menu_id, menu_data in self._menus.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1611 type_ = menu_data["type"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1612 path = menu_data["path"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1613 menu_security_limit = menu_data["security_limit"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1614 if security_limit != C.NO_SECURITY_LIMIT and ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1615 menu_security_limit == C.NO_SECURITY_LIMIT |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1616 or menu_security_limit > security_limit |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1617 ): |
809 | 1618 continue |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1619 language_switch(language) |
773 | 1620 path_i18n = [_(elt) for elt in path] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1621 language_switch() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1622 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
|
1623 ret.append((menu_id, type_, path, path_i18n, extra)) |
773 | 1624 |
1625 return ret | |
1626 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1627 def _launch_menu(self, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT, |
2879 | 1628 profile_key=C.PROF_KEY_NONE): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1629 client = self.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1630 return self.launch_menu(client, menu_type, path, data, security_limit) |
2126 | 1631 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1632 def launch_menu(self, client, menu_type, path, data=None, |
2879 | 1633 security_limit=C.NO_SECURITY_LIMIT): |
2126 | 1634 """launch action a menu action |
1635 | |
1636 @param menu_type(unicode): type of menu to launch | |
1637 @param path(iterable[unicode]): canonical path of the menu | |
1638 @params data(dict): menu data | |
1639 @raise NotFound: this path is not known | |
1640 """ | |
1641 # FIXME: manage security_limit here | |
1642 # defaut security limit should be high instead of C.NO_SECURITY_LIMIT | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1643 canonical_path = self._get_menu_canonical_path(path) |
2126 | 1644 menu_key = (menu_type, canonical_path) |
1645 try: | |
1646 callback_id = self._menus_paths[menu_key] | |
1647 except KeyError: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1648 raise exceptions.NotFound( |
3028 | 1649 "Can't find menu {path} ({menu_type})".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1650 path=canonical_path, menu_type=menu_type |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1651 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1652 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1653 return self.launch_callback(callback_id, data, client.profile) |
2126 | 1654 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1655 def get_menu_help(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
|
1656 """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
|
1657 |
773 | 1658 @param menu_id: id of the menu (same as callback_id) |
1659 @param language: language used for translation, or empty string for default | |
1660 @param return: translated help | |
1661 | |
1662 """ | |
101 | 1663 try: |
773 | 1664 menu_data = self._menus[menu_id] |
101 | 1665 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
|
1666 raise exceptions.DataError("Trying to access an unknown menu") |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1667 language_switch(language) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2597
diff
changeset
|
1668 help_string = _(menu_data["help_string"]) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
4019
diff
changeset
|
1669 language_switch() |
773 | 1670 return help_string |