Mercurial > libervia-backend
annotate twisted/plugins/sat_plugin.py @ 4002:5245b675f7ad
plugin XEP-0313: don't wait for MAM to be retrieved in connection workflow:
MAM retrieval can be long, and can be done after connection, message just need to be
sorted when being inserted (i.e. frontends must do insort).
To avoid blocking connection for too long and result in bad UX and timeout risk, one2one
MAM message are not retrieved in background.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 10 Mar 2023 17:22:45 +0100 |
parents | f9a5b810f14d |
children | 524856bd7b19 |
rev | line source |
---|---|
3040 | 1 #!/usr/bin/env python3 |
3137 | 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:
572
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:
572
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:
572
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:
572
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:
572
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:
572
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:
572
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:
572
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:
572
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:
572
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
1014
e40d9858cb83
core: if in debug mode and ipdb is present, use ipdb instead of pdb
Goffi <goffi@goffi.org>
parents:
1010
diff
changeset
|
19 |
3028 | 20 from zope.interface import implementer |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
21 from twisted.python import usage |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
22 from twisted.plugin import IPlugin |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
23 from twisted.application.service import IServiceMaker |
0 | 24 |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
25 # XXX: We need to configure logs before any log method is used, so here is the best place. |
1010
73a0b7f94674
primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents:
994
diff
changeset
|
26 from sat.core.constants import Const as C |
1130 | 27 from sat.core.i18n import _ |
28 | |
3476
11003f9f92fb
core: moved `sat_tmp.wokkel` install `sat_plugin`:
Goffi <goffi@goffi.org>
parents:
3475
diff
changeset
|
29 from sat_tmp.wokkel import install as install_wokkel_patches |
11003f9f92fb
core: moved `sat_tmp.wokkel` install `sat_plugin`:
Goffi <goffi@goffi.org>
parents:
3475
diff
changeset
|
30 |
11003f9f92fb
core: moved `sat_tmp.wokkel` install `sat_plugin`:
Goffi <goffi@goffi.org>
parents:
3475
diff
changeset
|
31 |
11003f9f92fb
core: moved `sat_tmp.wokkel` install `sat_plugin`:
Goffi <goffi@goffi.org>
parents:
3475
diff
changeset
|
32 install_wokkel_patches() |
11003f9f92fb
core: moved `sat_tmp.wokkel` install `sat_plugin`:
Goffi <goffi@goffi.org>
parents:
3475
diff
changeset
|
33 |
991
05e02f8b7eb4
core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
34 |
1130 | 35 def initialise(options): |
36 """Method to initialise global modules""" | |
37 # XXX: We need to configure logs before any log method is used, so here is the best place. | |
38 from sat.core import log_config | |
39 log_config.satConfigure(C.LOG_BACKEND_TWISTED, C, backend_data=options) | |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
40 |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
41 |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
42 class Options(usage.Options): |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
43 optParameters = [] |
101 | 44 |
994
652c01ca69b1
core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents:
991
diff
changeset
|
45 |
3028 | 46 @implementer(IPlugin, IServiceMaker) |
47 class SatMaker: | |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
48 |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
49 tapname = C.APP_NAME_FILE |
3028 | 50 description = _("%s XMPP client backend") % C.APP_NAME_FULL |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
51 options = Options |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
52 |
3053
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
53 def setDebugger(self): |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
54 from twisted.internet import defer |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
55 if defer.Deferred.debug: |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
56 # if we are in debug mode, we want to use ipdb instead of pdb |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
57 try: |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
58 import ipdb |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
59 import pdb |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
60 pdb.set_trace = ipdb.set_trace |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
61 pdb.post_mortem = ipdb.post_mortem |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
62 except ImportError: |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
63 pass |
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
64 |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
65 def makeService(self, options): |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
66 from twisted.internet import asyncioreactor |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
67 asyncioreactor.install() |
3053
8b36e5c3f28f
misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
68 self.setDebugger() |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
69 # XXX: Libervia must be imported after log configuration, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
70 # because it write stuff to logs |
1130 | 71 initialise(options.parent) |
72 from sat.core.sat_main import SAT | |
1122
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
73 return SAT() |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
74 |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
75 |
9ae01ccf89c1
core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents:
1021
diff
changeset
|
76 serviceMaker = SatMaker() |