annotate sat_frontends/jp/cmd_invitation.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
5 # Copyright (C) 2009-2019 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 from functools import partial
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 __commands__ = ["Invitation"]
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
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class Create(base.CommandBase):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
37 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
38 use_output=C.OUTPUT_DICT,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
39 help=_("create and send an invitation"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 self.need_loop = True
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 "--jid",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 help="jid of the invitee (default: generate one)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 "--password",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 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
55 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 "-n",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 "--name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 help="name of the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 "-N",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 "--host-name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 help="name of the host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 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
74 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 "--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
77 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 "--lang",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 help="main language spoken by the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 "-u",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 "--url",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 help="template to construct the URL",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 "-s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 "--subject",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 help="subject of the invitation email (default: generic subject)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 "-b",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 "--body",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 help="body of the invitation email (default: generic body)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 "-x",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 "--extra",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 metavar=("KEY", "VALUE"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 help="extra data to associate with invitation/invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 help="profile doing the invitation (default: don't associate profile)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def invitationCreateCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.output(invitation_data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 self.host.quit(C.EXIT_OK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 def invitationCreateEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
124 "can't create invitation: {reason}".format(reason=failure_), error=True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 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
130 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
131 emails_extra = self.args.email[1:]
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 if self.args.no_email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 if email:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 extra["email"] = email
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 data_format.iter2dict("emails_extra", emails_extra)
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 if not email:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 self.parser.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
139 _("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
140 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.host.bridge.invitationCreate(
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
143 email,
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
144 emails_extra,
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.args.jid,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self.args.password,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 self.args.name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 self.args.host_name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 self.args.lang,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 self.args.url,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 self.args.subject,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 self.args.body,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 extra,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.args.profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 callback=self.invitationCreateCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 errback=self.invitationCreateEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 class Get(base.CommandBase):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
162 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 use_output=C.OUTPUT_DICT,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
168 help=_("get invitation data"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 self.need_loop = True
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
174 "id", help=_("invitation UUID")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 "--with-jid",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
180 help=_("start profile session and retrieve jid"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 def output_data(self, data, jid_=None):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 if jid_ is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 data["jid"] = jid_
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self.output(data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.host.quit()
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def invitationGetCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190 if self.args.with_jid:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
191 profile = invitation_data["guest_profile"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
193 def session_started(__):
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.host.bridge.asyncGetParamA(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
195 "JabberID",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
196 "Connection",
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
197 profile_key=profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
198 callback=lambda jid_: self.output_data(invitation_data, jid_),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
201 msg=_("can't retrieve jid: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
205
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
206 self.host.bridge.profileStartSession(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
207 invitation_data["password"],
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208 profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209 callback=session_started,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
212 msg=_("can't start session: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
216 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 self.output_data(invitation_data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219 def start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220 self.host.bridge.invitationGet(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
221 self.args.id,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
222 callback=self.invitationGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
225 msg=_("can't get invitation data: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 )
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
229
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
230
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
231 class Modify(base.CommandBase):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
232 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 base.CommandBase.__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
234 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
235 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 self.need_loop = True
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
237
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
238 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 "--replace", action="store_true", help="replace the whole data"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 "-n",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 "--name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
246 help="name of the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
247 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
249 "-N",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 "--host-name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
252 help="name of the host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
257 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
258 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
259 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
261 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
262 "--lang",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 dest="language",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
264 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
265 help="main language spoken by the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
266 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
267 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 "-x",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 "--extra",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 metavar=("KEY", "VALUE"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
274 help="extra data to associate with invitation/invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
279 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
280 help="profile doing the invitation (default: don't associate profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
281 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
282 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
283 "id", help=_("invitation UUID")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
284 )
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
285
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
286 def invitationModifyCb(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
287 self.disp(_("invitations have been modified correctly"))
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
288 self.host.quit(C.EXIT_OK)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
289
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
290 def invitationModifyEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
292 "can't create invitation: {reason}".format(reason=failure_), error=True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 )
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
294 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
295
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
296 def start(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
297 extra = dict(self.args.extra)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 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
299 value = getattr(self.args, arg_name)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
300 if not value:
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
301 continue
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
302 if arg_name in extra:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
305 "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 ).format(arg_name=arg_name)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 )
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
308 extra[arg_name] = value
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
309 self.host.bridge.invitationModify(
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
310 self.args.id,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
311 extra,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
312 self.args.replace,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
313 callback=self.invitationModifyCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 errback=self.invitationModifyEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
315 )
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
316
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
317
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
318 class List(base.CommandBase):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
319 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
320 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 "list",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 use_output=C.OUTPUT_COMPLEX,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
327 extra_outputs=extra_outputs,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
328 help=_("list invitations data"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 self.need_loop = True
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
331
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
332 def default_output(self, data):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
333 for idx, datum in enumerate(data.items()):
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
334 if idx:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
335 self.disp("\n")
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
336 key, invitation_data = datum
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
337 self.disp(A.color(C.A_HEADER, key))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
338 indent = " "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
339 for k, v in invitation_data.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
340 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
341
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
342 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
343 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
344 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
345 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
346 default=C.PROF_KEY_NONE,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
347 help=_("return only invitations linked to this profile"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
348 )
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
349
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
350 def invitationListCb(self, data):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
351 self.output(data)
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
352 self.host.quit()
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
353
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
354 def start(self):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
355 self.host.bridge.invitationList(
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
356 self.args.profile,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
357 callback=self.invitationListCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
358 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
359 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
360 msg=_("can't list invitations: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
361 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
362 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
363 )
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
364
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
365
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
366 class Invitation(base.CommandBase):
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
367 subcommands = (Create, Get, Modify, List)
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
368
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
369 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
370 super(Invitation, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
371 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
372 "invitation",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
373 use_profile=False,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
374 help=_("invitation of user(s) without XMPP account"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 )