annotate sat_frontends/jp/cmd_invitation.py @ 3565:d66a8453b02b

plugin app manager: add a way to create files: a `files` field can now be used to create files on the fly. Its value must be a dict where key are file names, and values are an other dict with file data. For now file data can only use the `content` key. Value of content will be written to the file. If a file already exists, it is not overwritten.
author Goffi <goffi@goffi.org>
date Sat, 12 Jun 2021 15:10:49 +0200
parents be6d91572633
children 04283582966f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3339
diff changeset
5 # Copyright (C) 2009-2021 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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
130 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
131 invitation_data = await self.host.bridge.invitationCreate(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
132 email,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
133 emails_extra,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
134 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
135 self.args.password,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
136 self.args.name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
137 self.args.host_name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
138 self.args.lang,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
139 self.args.url,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
140 self.args.subject,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
141 self.args.body,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
142 extra,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
143 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
144 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
146 self.disp(f"can't create invitation: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
147 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
149 await self.output(invitation_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
181 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
182 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 invitation_data = await self.host.bridge.invitationGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 self.args.id,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
185 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
187 self.disp(msg=_(f"can't get invitation data: {e}"), error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
188 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
189
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
190 if not self.args.with_jid:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 await self.output_data(invitation_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
192 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
193 profile = invitation_data["guest_profile"]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
194 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 await self.host.bridge.profileStartSession(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
196 invitation_data["password"],
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
197 profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
199 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
200 self.disp(msg=_(f"can't start session: {e}"), error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
203 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
204 jid_ = await self.host.bridge.asyncGetParamA(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
205 "JabberID",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
209 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
210 self.disp(msg=_(f"can't retrieve jid: {e}"), error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
308 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
309 await self.host.bridge.invitationModify(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
310 self.args.id,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
311 extra,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
312 self.args.replace,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
313 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
314 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
315 self.disp(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
316 f"can't modify invitation: {e}", error=True
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
317 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
318 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
319 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
320 self.disp(_("invitations have been modified successfuly"))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
343 indent = " "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
344 for k, v in invitation_data.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
355 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
356 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
357 data = await self.host.bridge.invitationList(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
358 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
359 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
360 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
361 self.disp(f"return only invitations linked to this profile: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
362 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
363 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
364 await self.output(data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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 )