Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_invitation.py @ 3458:b68346a52920
Backed out changeset 6deea0d8d0e7
This patch has been merged by mistake, it will be applied later.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 04 Feb 2021 21:07:49 +0100 |
parents | c560aae54f5f |
children | be6d91572633 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # jp: a SàT command line tool |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
3028 | 21 from . import base |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.i18n import _ |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat_frontends.jp.constants import Const as C |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
24 from sat.tools.common.ansi import ANSI as A |
2291
c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents:
2285
diff
changeset
|
25 from sat.tools.common import data_format |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 __commands__ = ["Invitation"] |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 class Create(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
33 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 use_output=C.OUTPUT_DICT, |
3028 | 38 help=_("create and send an invitation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 "--jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 help="jid of the invitee (default: generate one)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 "--password", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 help="password of the invitee profile/XMPP account (default: generate one)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 help="email(s) to send the invitation to (if --no-email is set, email will just be saved)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 "--no-email", action="store_true", help="do NOT send invitation email" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 help="main language spoken by the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 "-u", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 "--url", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 help="template to construct the URL", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 "--subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 help="subject of the invitation email (default: generic subject)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 "-b", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 "--body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 help="body of the invitation email (default: generic body)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 help="profile doing the invitation (default: don't associate profile)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
3040 | 116 async def start(self): |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 extra = dict(self.args.extra) |
2291
c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents:
2285
diff
changeset
|
118 email = self.args.email[0] if self.args.email else None |
c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents:
2285
diff
changeset
|
119 emails_extra = self.args.email[1:] |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 if self.args.no_email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 if email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 extra["email"] = email |
3028 | 123 data_format.iter2dict("emails_extra", emails_extra) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 if not email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 self.parser.error( |
3028 | 127 _("you need to specify an email address to send email invitation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
3040 | 130 try: |
131 invitation_data = await self.host.bridge.invitationCreate( | |
132 email, | |
133 emails_extra, | |
134 self.args.jid, | |
135 self.args.password, | |
136 self.args.name, | |
137 self.args.host_name, | |
138 self.args.lang, | |
139 self.args.url, | |
140 self.args.subject, | |
141 self.args.body, | |
142 extra, | |
143 self.args.profile, | |
144 ) | |
145 except Exception as e: | |
146 self.disp(f"can't create invitation: {e}", error=True) | |
147 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
148 else: | |
149 await self.output(invitation_data) | |
150 self.host.quit(C.EXIT_OK) | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 class Get(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 use_output=C.OUTPUT_DICT, |
3028 | 161 help=_("get invitation data"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 self.parser.add_argument( |
3028 | 166 "id", help=_("invitation UUID") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 "--with-jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 action="store_true", |
3028 | 172 help=_("start profile session and retrieve jid"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
3040 | 175 async def output_data(self, data, jid_=None): |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 if jid_ is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 data["jid"] = jid_ |
3040 | 178 await self.output(data) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 self.host.quit() |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
3040 | 181 async def start(self): |
182 try: | |
183 invitation_data = await self.host.bridge.invitationGet( | |
184 self.args.id, | |
185 ) | |
186 except Exception as e: | |
187 self.disp(msg=_(f"can't get invitation data: {e}"), error=True) | |
188 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
189 | |
190 if not self.args.with_jid: | |
191 await self.output_data(invitation_data) | |
192 else: | |
3028 | 193 profile = invitation_data["guest_profile"] |
3040 | 194 try: |
195 await self.host.bridge.profileStartSession( | |
196 invitation_data["password"], | |
197 profile, | |
198 ) | |
199 except Exception as e: | |
200 self.disp(msg=_(f"can't start session: {e}"), error=True) | |
201 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 |
3040 | 203 try: |
204 jid_ = await self.host.bridge.asyncGetParamA( | |
3028 | 205 "JabberID", |
206 "Connection", | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 profile_key=profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 ) |
3040 | 209 except Exception as e: |
210 self.disp(msg=_(f"can't retrieve jid: {e}"), error=True) | |
211 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
3040 | 213 await self.output_data(invitation_data, jid_) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
216 class Delete(base.CommandBase): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
217 def __init__(self, host): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
218 base.CommandBase.__init__( |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
219 self, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
220 host, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
221 "delete", |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
222 use_profile=False, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
223 help=_("delete guest account"), |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
224 ) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
225 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
226 def add_parser_options(self): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
227 self.parser.add_argument( |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
228 "id", help=_("invitation UUID") |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
229 ) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
230 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
231 async def start(self): |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
232 try: |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
233 await self.host.bridge.invitationDelete( |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
234 self.args.id, |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
235 ) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
236 except Exception as e: |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
237 self.disp(msg=_(f"can't delete guest account: {e}"), error=True) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
238 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
239 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
240 self.host.quit() |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
241 |
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
242 |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
243 class Modify(base.CommandBase): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
244 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 base.CommandBase.__init__( |
3028 | 246 self, host, "modify", use_profile=False, help=_("modify existing invitation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
248 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
249 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
250 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 "--replace", action="store_true", help="replace the whole data" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
256 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 help="email to send the invitation to (if --no-email is set, email will just be saved)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 dest="language", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 help="main language spoken by the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 help="profile doing the invitation (default: don't associate profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 self.parser.add_argument( |
3028 | 294 "id", help=_("invitation UUID") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
296 |
3040 | 297 async def start(self): |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
298 extra = dict(self.args.extra) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
299 for arg_name in ("name", "host_name", "email", "language", "profile"): |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
300 value = getattr(self.args, arg_name) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
301 if not value: |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
302 continue |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
303 if arg_name in extra: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 self.parser.error( |
3040 | 305 _(f"you can't set {arg_name} in both optional argument and extra") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
306 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
307 extra[arg_name] = value |
3040 | 308 try: |
309 await self.host.bridge.invitationModify( | |
310 self.args.id, | |
311 extra, | |
312 self.args.replace, | |
313 ) | |
314 except Exception as e: | |
315 self.disp( | |
316 f"can't modify invitation: {e}", error=True | |
317 ) | |
318 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
319 else: | |
320 self.disp(_("invitations have been modified successfuly")) | |
321 self.host.quit(C.EXIT_OK) | |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
322 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
323 |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
324 class List(base.CommandBase): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
325 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
327 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
328 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
330 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 use_output=C.OUTPUT_COMPLEX, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
333 extra_outputs=extra_outputs, |
3028 | 334 help=_("list invitations data"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
335 ) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
336 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
337 def default_output(self, data): |
3028 | 338 for idx, datum in enumerate(data.items()): |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
339 if idx: |
3028 | 340 self.disp("\n") |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
341 key, invitation_data = datum |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
342 self.disp(A.color(C.A_HEADER, key)) |
3028 | 343 indent = " " |
344 for k, v in invitation_data.items(): | |
345 self.disp(indent + A.color(C.A_SUBHEADER, k + ":") + " " + str(v)) | |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
346 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
347 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
348 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
349 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
350 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
351 default=C.PROF_KEY_NONE, |
3028 | 352 help=_("return only invitations linked to this profile"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
353 ) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
354 |
3040 | 355 async def start(self): |
356 try: | |
357 data = await self.host.bridge.invitationList( | |
358 self.args.profile, | |
359 ) | |
360 except Exception as e: | |
361 self.disp(f"return only invitations linked to this profile: {e}", error=True) | |
362 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
363 else: | |
364 await self.output(data) | |
365 self.host.quit() | |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
366 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
367 |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 class Invitation(base.CommandBase): |
3339
c560aae54f5f
jp (invitation): `delete` implementation
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
369 subcommands = (Create, Get, Delete, Modify, List) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
372 super(Invitation, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
373 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
374 "invitation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
375 use_profile=False, |
3028 | 376 help=_("invitation of user(s) without XMPP account"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 ) |