annotate twisted/plugins/sat_plugin.py @ 3324:b57b5e42e894

plugins invitation, invitation-file: adapt service JID and affiliation: if the user part of the service is missing while creating and invitation, it's added because using only the domain will lead to a different repository depending on the requester. In addition, the invitee is added to the repostiroy path as a member, to be sure he/she can access it.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:24:03 +0200
parents a3639d6d9643
children 3ac28e51a24f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3076
diff changeset
2
3281
a3639d6d9643 core: replaced `sat` shell script by a python script:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
3 # SàT: an XMPP client
a3639d6d9643 core: replaced `sat` shell script by a python script:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
4 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2695
diff changeset
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
goffi@necton2
parents:
diff changeset
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
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
27 from sat.core.i18n import _
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
28
3076
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
29 # patch for Python 3.8 compatibility
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
30 from sat_tmp.twisted import install as install_twisted_patches
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
31
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
32
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
33 install_twisted_patches()
2180b0f5c1cd core: use sat_tmp's twisted patches for Python 3.8 compatibility
Goffi <goffi@goffi.org>
parents: 3053
diff changeset
34
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents: 811
diff changeset
35
1130
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
36 def initialise(options):
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
37 """Method to initialise global modules"""
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
38 # XXX: We need to configure logs before any log method is used, so here is the best place.
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
39 from sat.core import log_config
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
40 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
41
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
42
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
43 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
44 optParameters = []
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
45
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
46
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2695
diff changeset
47 @implementer(IPlugin, IServiceMaker)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2695
diff changeset
48 class SatMaker:
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
49
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
50 tapname = C.APP_NAME_FILE
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2695
diff changeset
51 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
52 options = Options
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
53
3053
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
54 def setDebugger(self):
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
55 from twisted.internet import defer
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
56 if defer.Deferred.debug:
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
57 # 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
58 try:
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
59 import ipdb
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
60 import pdb
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
61 pdb.set_trace = ipdb.set_trace
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
62 pdb.post_mortem = ipdb.post_mortem
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
63 except ImportError:
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
64 pass
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
65
1122
9ae01ccf89c1 core: sat bakcend is now a twisted plugin (no more .tac file)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
66 def makeService(self, options):
2695
c5543fba97e8 core: fixed reactor crash by installing reactor only in makeService
Goffi <goffi@goffi.org>
parents: 2670
diff changeset
67 from twisted.internet import gireactor
c5543fba97e8 core: fixed reactor crash by installing reactor only in makeService
Goffi <goffi@goffi.org>
parents: 2670
diff changeset
68 gireactor.install()
3053
8b36e5c3f28f misc: don't import memory in launch script:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
69 self.setDebugger()
1130
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
70 # XXX: SAT must be imported after log configuration, because it write stuff to logs
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
71 initialise(options.parent)
adea30ca0b51 core: twistd plugin refactoring:
Goffi <goffi@goffi.org>
parents: 1122
diff changeset
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()