Mercurial > libervia-backend
annotate frontends/src/jp/cmd_invitation.py @ 2227:79d279d1ee88
plugin XEP-0277: comments node access model changes:
comments node access model is now copied from parent item by default. If whitelist access is used, parent item affiliations are copied too.
publish model is now open by default instead of subscribers
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 17 Apr 2017 20:33:32 +0200 |
parents | 0d27d95652a7 |
children | a41a4729c2d8 |
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 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from functools import partial |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 __commands__ = ["Invitation"] |
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 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 class Create(base.CommandBase): |
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 def __init__(self, host): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 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
|
33 self.need_loop=True |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 def add_parser_options(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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') |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default='', help="profile doing the invitation (default: don't associate profile") |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 def invitationCreateCb(self, invitation_data): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 self.output(invitation_data) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 self.host.quit(C.EXIT_OK) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def invitationCreateEb(self, failure_): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 self.disp(u"can't create invitation: {reason}".format( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 reason=failure_), error=True) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 def start(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 extra = dict(self.args.extra) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 email = self.args.email |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 if self.args.no_email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 if email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 extra['email'] = email |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 if not email: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 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
|
67 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 self.host.bridge.invitationCreate( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 self.args.jid, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 self.args.password, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 self.args.name, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 self.args.host_name, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 email, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 self.args.lang, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 self.args.url, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 self.args.subject, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 self.args.body, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 extra, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self.args.profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 callback=self.invitationCreateCb, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 errback=self.invitationCreateEb) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
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 class Get(base.CommandBase): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 def __init__(self, host): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 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
|
88 self.need_loop=True |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def add_parser_options(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 self.parser.add_argument("id", type=base.unicode_decoder, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 help=_(u"invitation UUID")) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 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
|
94 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def output_data(self, data, jid_=None): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 if jid_ is not None: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 data['jid'] = jid_ |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 self.output(data) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 self.host.quit() |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def invitationGetCb(self, invitation_data): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 if self.args.with_jid: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 profile = invitation_data[u'guest_profile'] |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 def session_started(dummy): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 self.host.bridge.asyncGetParamA( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 u'JabberID', |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 u'Connection', |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 profile_key=profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 callback=lambda jid_: self.output_data(invitation_data, jid_), |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 errback=partial(self.errback, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 msg=_(u"can't retrieve jid: {}"), |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 self.host.bridge.profileStartSession( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 invitation_data[u'password'], |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 profile, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 callback=session_started, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 errback=partial(self.errback, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 msg=_(u"can't start session: {}"), |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 else: |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 self.output_data(invitation_data) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 def start(self): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 self.host.bridge.invitationGet( |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 self.args.id, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 callback=self.invitationGetCb, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 errback=partial(self.errback, |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 msg=_(u"can't get invitation data: {}"), |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
133 class Modify(base.CommandBase): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
134 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
135 def __init__(self, host): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
136 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
|
137 self.need_loop=True |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
138 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
139 def add_parser_options(self): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 self.parser.add_argument("id", type=base.unicode_decoder, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
148 help=_(u"invitation UUID")) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
149 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
150 def invitationModifyCb(self): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
151 self.disp(_(u'invitations have been modified correctly')) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
152 self.host.quit(C.EXIT_OK) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
153 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
154 def invitationModifyEb(self, failure_): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
155 self.disp(u"can't create invitation: {reason}".format( |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
156 reason=failure_), error=True) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
157 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
158 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
159 def start(self): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
160 extra = dict(self.args.extra) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
161 for arg_name in ('name', 'host_name', 'email', 'lang', 'profile'): |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
162 value = getattr(self.args, arg_name) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
163 if not value: |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
164 continue |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
165 if arg_name in extra: |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
166 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
|
167 extra[arg_name] = value |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
168 self.host.bridge.invitationModify( |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
169 self.args.id, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
170 extra, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
171 self.args.replace, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
172 callback=self.invitationModifyCb, |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
173 errback=self.invitationModifyEb) |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
174 |
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
175 |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 class Invitation(base.CommandBase): |
2220
0d27d95652a7
jp (invitation): added modify command
Goffi <goffi@goffi.org>
parents:
2215
diff
changeset
|
177 subcommands = (Create, Get, Modify) |
2215
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 def __init__(self, host): |
5831e8fcc5f8
jp (invitation): invitation command first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account')) |