comparison frontends/src/jp/cmd_invitation.py @ 2234:a41a4729c2d8

jp (invitation): added list subcommand
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 00:59:25 +0200
parents 0d27d95652a7
children 6c1070ae1b7d
comparison
equal deleted inserted replaced
2233:bf998d8626d9 2234:a41a4729c2d8
19 19
20 20
21 import base 21 import base
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat.tools.common.ansi import ANSI as A
24 from functools import partial 25 from functools import partial
25 26
26 __commands__ = ["Invitation"] 27 __commands__ = ["Invitation"]
27 28
28 29
171 self.args.replace, 172 self.args.replace,
172 callback=self.invitationModifyCb, 173 callback=self.invitationModifyCb,
173 errback=self.invitationModifyEb) 174 errback=self.invitationModifyEb)
174 175
175 176
177 class List(base.CommandBase):
178
179 def __init__(self, host):
180 extra_outputs = {'default': self.default_output}
181 base.CommandBase.__init__(self, host, 'list', use_profile=False, use_output=C.OUTPUT_COMPLEX, extra_outputs=extra_outputs, help=_(u'list invitations data'))
182 self.need_loop=True
183
184 def default_output(self, data):
185 for idx, datum in enumerate(data.iteritems()):
186 if idx:
187 self.disp(u"\n")
188 key, invitation_data = datum
189 self.disp(A.color(C.A_HEADER, key))
190 indent = u' '
191 for k, v in invitation_data.iteritems():
192 self.disp(indent + A.color(C.A_SUBHEADER, k + u':') + u' ' + unicode(v))
193
194 def add_parser_options(self):
195 self.parser.add_argument("-p", "--profile", default=C.PROF_KEY_NONE, help=_(u"return only invitations linked to this profile"))
196
197 def invitationListCb(self, data):
198 self.output(data)
199 self.host.quit()
200
201 def start(self):
202 self.host.bridge.invitationList(
203 self.args.profile,
204 callback=self.invitationListCb,
205 errback=partial(self.errback,
206 msg=_(u"can't list invitations: {}"),
207 exit_code=C.EXIT_BRIDGE_ERRBACK))
208
209
176 class Invitation(base.CommandBase): 210 class Invitation(base.CommandBase):
177 subcommands = (Create, Get, Modify) 211 subcommands = (Create, Get, Modify, List)
178 212
179 def __init__(self, host): 213 def __init__(self, host):
180 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account')) 214 super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))