annotate frontends/src/jp/cmd_invitation.py @ 2409:d2ff5ff3de77

jp (ad-hoc): new "list" and "run" commands: - list just display commands available at ad-hoc entry point. --verbose allows to display values names, which is useful for automation. - run can either run interactively a command, or execute a workflow to automate them.
author Goffi <goffi@goffi.org>
date Tue, 31 Oct 2017 23:20:04 +0100
parents c05000d00dbb
children 8b37a62336c3
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
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
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 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
35 self.need_loop=True
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def add_parser_options(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 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
39 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
40 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
41 self.parser.add_argument("-N", "--host-name", type=base.unicode_decoder, default='', help='name of the host')
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
42 self.parser.add_argument("-e", "--email", action="append", type=base.unicode_decoder, default=[], help='email(s) to send the invitation to (if --no-email is set, email will just be saved)')
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 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
44 self.parser.add_argument("-l", "--lang", type=base.unicode_decoder, default='', help='main language spoken by the invitee')
2285
688ff67d6ae9 jp (invitation/create): typo
Goffi <goffi@goffi.org>
parents: 2260
diff changeset
45 self.parser.add_argument("-u", "--url", type=base.unicode_decoder, default='', help='template to construct the URL')
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 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
47 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
48 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
49 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
50
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def invitationCreateCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.output(invitation_data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.host.quit(C.EXIT_OK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 def invitationCreateEb(self, failure_):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.disp(u"can't create invitation: {reason}".format(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 reason=failure_), error=True)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 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
62 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
63 emails_extra = self.args.email[1:]
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 if self.args.no_email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 if email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 extra['email'] = email
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
67 data_format.iter2dict(u'emails_extra', emails_extra)
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 if not email:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 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
71
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 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
73 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
74 emails_extra,
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.args.jid,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.args.password,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.args.name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.args.host_name,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.args.lang,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 self.args.url,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.args.subject,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.args.body,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 extra,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.args.profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 callback=self.invitationCreateCb,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 errback=self.invitationCreateEb)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 class Get(base.CommandBase):
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 __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 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
93 self.need_loop=True
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def add_parser_options(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.parser.add_argument("id", type=base.unicode_decoder,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
97 help=_(u"invitation UUID"))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 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
99
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
100 def output_data(self, data, jid_=None):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
101 if jid_ is not None:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
102 data['jid'] = jid_
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103 self.output(data)
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.host.quit()
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def invitationGetCb(self, invitation_data):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 if self.args.with_jid:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 profile = invitation_data[u'guest_profile']
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 def session_started(dummy):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.host.bridge.asyncGetParamA(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 u'JabberID',
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 u'Connection',
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
113 profile_key=profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114 callback=lambda jid_: self.output_data(invitation_data, jid_),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116 msg=_(u"can't retrieve jid: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 exit_code=C.EXIT_BRIDGE_ERRBACK))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
119 self.host.bridge.profileStartSession(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
120 invitation_data[u'password'],
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
121 profile,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
122 callback=session_started,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 msg=_(u"can't start session: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 exit_code=C.EXIT_BRIDGE_ERRBACK))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 else:
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 self.output_data(invitation_data)
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 start(self):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 self.host.bridge.invitationGet(
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 self.args.id,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 callback=self.invitationGetCb,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 errback=partial(self.errback,
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 msg=_(u"can't get invitation data: {}"),
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 exit_code=C.EXIT_BRIDGE_ERRBACK))
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
138 class Modify(base.CommandBase):
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 __init__(self, host):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
141 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
142 self.need_loop=True
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
143
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
144 def add_parser_options(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
145 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
146 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
147 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
148 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)')
2260
45b89d7c5c81 jp (invitation): fixed inconsistency in language handling
Goffi <goffi@goffi.org>
parents: 2250
diff changeset
149 self.parser.add_argument("-l", "--lang", dest="language", type=base.unicode_decoder, default='',
45b89d7c5c81 jp (invitation): fixed inconsistency in language handling
Goffi <goffi@goffi.org>
parents: 2250
diff changeset
150 help='main language spoken by the invitee')
2220
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
151 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
152 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
153 self.parser.add_argument("id", type=base.unicode_decoder,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
154 help=_(u"invitation UUID"))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
155
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
156 def invitationModifyCb(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
157 self.disp(_(u'invitations have been modified correctly'))
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
158 self.host.quit(C.EXIT_OK)
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 invitationModifyEb(self, failure_):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
161 self.disp(u"can't create invitation: {reason}".format(
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
162 reason=failure_), error=True)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
163 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
164
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
165 def start(self):
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
166 extra = dict(self.args.extra)
2260
45b89d7c5c81 jp (invitation): fixed inconsistency in language handling
Goffi <goffi@goffi.org>
parents: 2250
diff changeset
167 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
168 value = getattr(self.args, arg_name)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
169 if not value:
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
170 continue
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
171 if arg_name in extra:
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
172 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
173 extra[arg_name] = value
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
174 self.host.bridge.invitationModify(
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
175 self.args.id,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
176 extra,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
177 self.args.replace,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
178 callback=self.invitationModifyCb,
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
179 errback=self.invitationModifyEb)
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
180
0d27d95652a7 jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents: 2215
diff changeset
181
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
182 class List(base.CommandBase):
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 __init__(self, host):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
185 extra_outputs = {'default': self.default_output}
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
186 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
187 self.need_loop=True
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
188
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
189 def default_output(self, data):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
190 for idx, datum in enumerate(data.iteritems()):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
191 if idx:
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
192 self.disp(u"\n")
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
193 key, invitation_data = datum
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
194 self.disp(A.color(C.A_HEADER, key))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
195 indent = u' '
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
196 for k, v in invitation_data.iteritems():
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
197 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
198
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
199 def add_parser_options(self):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
200 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
201
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
202 def invitationListCb(self, data):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
203 self.output(data)
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
204 self.host.quit()
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
205
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
206 def start(self):
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
207 self.host.bridge.invitationList(
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
208 self.args.profile,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
209 callback=self.invitationListCb,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
210 errback=partial(self.errback,
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
211 msg=_(u"can't list invitations: {}"),
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
212 exit_code=C.EXIT_BRIDGE_ERRBACK))
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
213
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
214
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
215 class Invitation(base.CommandBase):
2234
a41a4729c2d8 jp (invitation): added list subcommand
Goffi <goffi@goffi.org>
parents: 2220
diff changeset
216 subcommands = (Create, Get, Modify, List)
2215
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
218 def __init__(self, host):
5831e8fcc5f8 jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))