Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_invitation.py @ 2900:93dfbeb41da8
primitivus: don't call chatStateComposing when host is out of sync:
if host is out of sync, that means that server is not connected and it makes no sense to call this method. Furthermore, this was resulting in a crash because profile is not found.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 07 Apr 2019 21:09:51 +0200 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
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 | 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 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 import base |
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, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 help=_(u"create and send an invitation"), |
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 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 help="jid of the invitee (default: generate one)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 "--password", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 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
|
57 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 "-n", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 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
|
79 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 "--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
|
82 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 type=base.unicode_decoder, |
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="main language spoken by the invitee", |
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 "-u", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 "--url", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 help="template to construct the URL", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 "-s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 "--subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 help="subject of the invitation email (default: generic subject)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 "-b", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 "--body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 type=base.unicode_decoder, |
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="body of the invitation email (default: generic body)", |
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 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 help="profile doing the invitation (default: don't associate profile)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 def invitationCreateCb(self, invitation_data): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 self.output(invitation_data) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 self.host.quit(C.EXIT_OK) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 def invitationCreateEb(self, failure_): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 u"can't create invitation: {reason}".format(reason=failure_), error=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 def start(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 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
|
141 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
|
142 emails_extra = self.args.email[1:] |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 if self.args.no_email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 if email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 extra["email"] = email |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 data_format.iter2dict(u"emails_extra", emails_extra) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 if not email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 self.parser.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 _(u"you need to specify an email address to send email invitation") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 ) |
2215
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 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
|
154 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
|
155 emails_extra, |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 self.args.jid, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self.args.password, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 self.args.name, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 self.args.host_name, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 self.args.lang, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 self.args.url, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 self.args.subject, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 self.args.body, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 extra, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 self.args.profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 callback=self.invitationCreateCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 errback=self.invitationCreateEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 class Get(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 help=_(u"get invitation data"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
180 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 self.need_loop = True |
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 add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
184 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 "id", type=base.unicode_decoder, help=_(u"invitation UUID") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 "--with-jid", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 action="store_true", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 help=_(u"start profile session and retrieve jid"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 def output_data(self, data, jid_=None): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 if jid_ is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 data["jid"] = jid_ |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 self.output(data) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 self.host.quit() |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 def invitationGetCb(self, invitation_data): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 if self.args.with_jid: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
202 profile = invitation_data[u"guest_profile"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
204 def session_started(__): |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 self.host.bridge.asyncGetParamA( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
206 u"JabberID", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 u"Connection", |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 profile_key=profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 callback=lambda jid_: self.output_data(invitation_data, jid_), |
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, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 msg=_(u"can't retrieve jid: {}"), |
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 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 self.host.bridge.profileStartSession( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 invitation_data[u"password"], |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 callback=session_started, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 msg=_(u"can't start session: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 self.output_data(invitation_data) |
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 def start(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 self.host.bridge.invitationGet( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 self.args.id, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 callback=self.invitationGetCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 msg=_(u"can't get invitation data: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 ) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
242 class Modify(base.CommandBase): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
243 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
244 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 self, host, "modify", use_profile=False, help=_(u"modify existing invitation") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
246 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 self.need_loop = True |
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 type=base.unicode_decoder, |
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="name of the invitee", |
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 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 type=base.unicode_decoder, |
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="name of the host", |
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 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 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
|
273 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 dest="language", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 type=base.unicode_decoder, |
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="main language spoken by the invitee", |
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( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 "--extra", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 metavar=("KEY", "VALUE"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
286 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
287 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
288 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
289 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 help="extra data to associate with invitation/invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 type=base.unicode_decoder, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
296 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
297 help="profile doing the invitation (default: don't associate profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
298 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
299 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
300 "id", type=base.unicode_decoder, help=_(u"invitation UUID") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
302 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
303 def invitationModifyCb(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
304 self.disp(_(u"invitations have been modified correctly")) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
305 self.host.quit(C.EXIT_OK) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
306 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
307 def invitationModifyEb(self, failure_): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
308 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
309 u"can't create invitation: {reason}".format(reason=failure_), error=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
310 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
311 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
312 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
313 def start(self): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
314 extra = dict(self.args.extra) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
315 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
|
316 value = getattr(self.args, arg_name) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
317 if not value: |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
318 continue |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
319 if arg_name in extra: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
320 self.parser.error( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
322 u"you can't set {arg_name} in both optional argument and extra" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
323 ).format(arg_name=arg_name) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
324 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
325 extra[arg_name] = value |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
326 self.host.bridge.invitationModify( |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
327 self.args.id, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
328 extra, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
329 self.args.replace, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
330 callback=self.invitationModifyCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 errback=self.invitationModifyEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
332 ) |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
333 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
334 |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
335 class List(base.CommandBase): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
336 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
342 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 use_output=C.OUTPUT_COMPLEX, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 extra_outputs=extra_outputs, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 help=_(u"list invitations data"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
346 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 self.need_loop = True |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
348 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
349 def default_output(self, data): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
350 for idx, datum in enumerate(data.iteritems()): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
351 if idx: |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
352 self.disp(u"\n") |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
353 key, invitation_data = datum |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
354 self.disp(A.color(C.A_HEADER, key)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
355 indent = u" " |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
356 for k, v in invitation_data.iteritems(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
357 self.disp(indent + A.color(C.A_SUBHEADER, k + u":") + u" " + unicode(v)) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
358 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
359 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
360 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
361 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
362 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
363 default=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
364 help=_(u"return only invitations linked to this profile"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
365 ) |
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 def invitationListCb(self, data): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
368 self.output(data) |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
369 self.host.quit() |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
370 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
371 def start(self): |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
372 self.host.bridge.invitationList( |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
373 self.args.profile, |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
374 callback=self.invitationListCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
375 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
376 self.errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 msg=_(u"can't list invitations: {}"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
378 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
379 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
380 ) |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
381 |
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
382 |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 class Invitation(base.CommandBase): |
2234
a41a4729c2d8
jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents:
2220
diff
changeset
|
384 subcommands = (Create, Get, Modify, List) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 super(Invitation, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 "invitation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
391 help=_(u"invitation of user(s) without XMPP account"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
392 ) |