annotate frontends/src/jp/cmd_invitation.py @ 2250:6c1070ae1b7d

jp (invitation): fixed typo
author Goffi <goffi@goffi.org>
date Sun, 21 May 2017 19:57:46 +0200
parents a41a4729c2d8
children 45b89d7c5c81
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
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
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
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from functools import partial
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 __commands__ = ["Invitation"]
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 class Create(base.CommandBase):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 base.CommandBase.__init__(self, host, 'create', use_profile=False, use_output=C.OUTPUT_DICT, help=_(u'create and send an invitation'))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.need_loop=True
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def add_parser_options(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.parser.add_argument("-j", "--jid", type=base.unicode_decoder, default='', help='jid of the invitee (default: generate one)')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.parser.add_argument("-P", "--password", type=base.unicode_decoder, default='', help='password of the invitee profile/XMPP account (default: generate one)')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.parser.add_argument("-n", "--name", type=base.unicode_decoder, default='', help='name of the invitee')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.parser.add_argument("-N", "--host-name", type=base.unicode_decoder, default='', help='name of the host')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.parser.add_argument("-e", "--email", type=base.unicode_decoder, default='', help='email to send the invitation to (if --no-email is set, email will just be saved)')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.parser.add_argument("--no-email", action="store_true", help='do NOT send invitation email')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.parser.add_argument("-l", "--lang", type=base.unicode_decoder, default='', help='main language spoken by the invitee')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.parser.add_argument("-u", "--url", type=base.unicode_decoder, default='', help='template to construt the URL')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.parser.add_argument("-s", "--subject", type=base.unicode_decoder, default='', help='subject of the invitation email (default: generic subject)')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.parser.add_argument("-b", "--body", type=base.unicode_decoder, default='', help='body of the invitation email (default: generic body)')
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.parser.add_argument("-x", "--extra", metavar=('KEY', 'VALUE'), type=base.unicode_decoder, action='append', nargs=2, default=[], help='extra data to associate with invitation/invitee')
2250
6c1070ae1b7d jp (invitation): fixed typo
Goffi <goffi@goffi.org>
parents: 2234
diff changeset
48 self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default='', help="profile doing the invitation (default: don't associate profile)")
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def invitationCreateCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.output(invitation_data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.host.quit(C.EXIT_OK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def invitationCreateEb(self, failure_):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.disp(u"can't create invitation: {reason}".format(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 reason=failure_), error=True)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 extra = dict(self.args.extra)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 email = self.args.email
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 if self.args.no_email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 if email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 extra['email'] = email
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 if not email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.parser.error(_(u'you need to specify an email address to send email invitation'))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.host.bridge.invitationCreate(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.args.jid,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.args.password,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.args.name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.args.host_name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 email,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.args.lang,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.args.url,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.args.subject,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.args.body,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 extra,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.args.profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 callback=self.invitationCreateCb,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 errback=self.invitationCreateEb)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 class Get(base.CommandBase):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 def __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 base.CommandBase.__init__(self, host, 'get', use_profile=False, use_output=C.OUTPUT_DICT, help=_(u'get invitation data'))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.need_loop=True
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 def add_parser_options(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.parser.add_argument("id", type=base.unicode_decoder,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 help=_(u"invitation UUID"))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.parser.add_argument("-j", "--with-jid", action="store_true", help=_(u"start profile session and retrieve jid"))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 def output_data(self, data, jid_=None):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if jid_ is not None:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 data['jid'] = jid_
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.output(data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 self.host.quit()
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def invitationGetCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 if self.args.with_jid:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 profile = invitation_data[u'guest_profile']
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def session_started(dummy):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.host.bridge.asyncGetParamA(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 u'JabberID',
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 u'Connection',
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 profile_key=profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 callback=lambda jid_: self.output_data(invitation_data, jid_),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 msg=_(u"can't retrieve jid: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 exit_code=C.EXIT_BRIDGE_ERRBACK))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.host.bridge.profileStartSession(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 invitation_data[u'password'],
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 callback=session_started,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 msg=_(u"can't start session: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 exit_code=C.EXIT_BRIDGE_ERRBACK))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self.output_data(invitation_data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 def start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 self.host.bridge.invitationGet(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self.args.id,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 callback=self.invitationGetCb,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 msg=_(u"can't get invitation data: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 exit_code=C.EXIT_BRIDGE_ERRBACK))
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
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
134 class Modify(base.CommandBase):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
135
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
136 def __init__(self, host):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
137 base.CommandBase.__init__(self, host, 'modify', use_profile=False, help=_(u'modify existing invitation'))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
138 self.need_loop=True
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
139
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
140 def add_parser_options(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
141 self.parser.add_argument("--replace", action='store_true', help='replace the whole data')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
142 self.parser.add_argument("-n", "--name", type=base.unicode_decoder, default='', help='name of the invitee')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
143 self.parser.add_argument("-N", "--host-name", type=base.unicode_decoder, default='', help='name of the host')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
144 self.parser.add_argument("-e", "--email", type=base.unicode_decoder, default='', help='email to send the invitation to (if --no-email is set, email will just be saved)')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
145 self.parser.add_argument("-l", "--lang", type=base.unicode_decoder, default='', help='main language spoken by the invitee')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
146 self.parser.add_argument("-x", "--extra", metavar=('KEY', 'VALUE'), type=base.unicode_decoder, action='append', nargs=2, default=[], help='extra data to associate with invitation/invitee')
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
147 self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default='', help="profile doing the invitation (default: don't associate profile")
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
148 self.parser.add_argument("id", type=base.unicode_decoder,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
149 help=_(u"invitation UUID"))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
150
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
151 def invitationModifyCb(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
152 self.disp(_(u'invitations have been modified correctly'))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
153 self.host.quit(C.EXIT_OK)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
154
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
155 def invitationModifyEb(self, failure_):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
156 self.disp(u"can't create invitation: {reason}".format(
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
157 reason=failure_), error=True)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
158 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
159
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
160 def start(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
161 extra = dict(self.args.extra)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
162 for arg_name in ('name', 'host_name', 'email', 'lang', 'profile'):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
163 value = getattr(self.args, arg_name)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
164 if not value:
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
165 continue
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
166 if arg_name in extra:
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
167 self.parser.error(_(u"you can't set {arg_name} in both optional argument and extra").format(arg_name=arg_name))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
168 extra[arg_name] = value
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
169 self.host.bridge.invitationModify(
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
170 self.args.id,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
171 extra,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
172 self.args.replace,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
173 callback=self.invitationModifyCb,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
174 errback=self.invitationModifyEb)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
175
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
176
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
177 class List(base.CommandBase):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
178
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
179 def __init__(self, host):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
180 extra_outputs = {'default': self.default_output}
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
181 base.CommandBase.__init__(self, host, 'list', use_profile=False, use_output=C.OUTPUT_COMPLEX, extra_outputs=extra_outputs, help=_(u'list invitations data'))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
182 self.need_loop=True
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
183
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
184 def default_output(self, data):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
185 for idx, datum in enumerate(data.iteritems()):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
186 if idx:
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
187 self.disp(u"\n")
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
188 key, invitation_data = datum
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
189 self.disp(A.color(C.A_HEADER, key))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
190 indent = u' '
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
191 for k, v in invitation_data.iteritems():
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
192 self.disp(indent + A.color(C.A_SUBHEADER, k + u':') + u' ' + unicode(v))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
193
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
194 def add_parser_options(self):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
195 self.parser.add_argument("-p", "--profile", default=C.PROF_KEY_NONE, help=_(u"return only invitations linked to this profile"))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
196
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
197 def invitationListCb(self, data):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
198 self.output(data)
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
199 self.host.quit()
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
200
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
201 def start(self):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
202 self.host.bridge.invitationList(
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
203 self.args.profile,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
204 callback=self.invitationListCb,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
205 errback=partial(self.errback,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
206 msg=_(u"can't list invitations: {}"),
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
207 exit_code=C.EXIT_BRIDGE_ERRBACK))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
208
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
209
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
210 class Invitation(base.CommandBase):
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
211 subcommands = (Create, Get, Modify, List)
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
212
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
213 def __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
214 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))