changeset 2234:a41a4729c2d8

jp (invitation): added list subcommand
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 00:59:25 +0200
parents bf998d8626d9
children 4db836386641
files frontends/src/jp/cmd_invitation.py
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_invitation.py	Thu Apr 27 00:58:12 2017 +0200
+++ b/frontends/src/jp/cmd_invitation.py	Thu Apr 27 00:59:25 2017 +0200
@@ -21,6 +21,7 @@
 import base
 from sat.core.i18n import _
 from sat_frontends.jp.constants import Const as C
+from sat.tools.common.ansi import ANSI as A
 from functools import partial
 
 __commands__ = ["Invitation"]
@@ -173,8 +174,41 @@
             errback=self.invitationModifyEb)
 
 
+class List(base.CommandBase):
+
+    def __init__(self, host):
+        extra_outputs = {'default': self.default_output}
+        base.CommandBase.__init__(self, host, 'list', use_profile=False, use_output=C.OUTPUT_COMPLEX, extra_outputs=extra_outputs, help=_(u'list invitations data'))
+        self.need_loop=True
+
+    def default_output(self, data):
+        for idx, datum in enumerate(data.iteritems()):
+            if idx:
+                self.disp(u"\n")
+            key, invitation_data = datum
+            self.disp(A.color(C.A_HEADER, key))
+            indent = u'  '
+            for k, v in invitation_data.iteritems():
+                self.disp(indent + A.color(C.A_SUBHEADER, k + u':') + u' ' + unicode(v))
+
+    def add_parser_options(self):
+        self.parser.add_argument("-p", "--profile", default=C.PROF_KEY_NONE, help=_(u"return only invitations linked to this profile"))
+
+    def invitationListCb(self, data):
+        self.output(data)
+        self.host.quit()
+
+    def start(self):
+        self.host.bridge.invitationList(
+            self.args.profile,
+            callback=self.invitationListCb,
+            errback=partial(self.errback,
+                            msg=_(u"can't list invitations: {}"),
+                            exit_code=C.EXIT_BRIDGE_ERRBACK))
+
+
 class Invitation(base.CommandBase):
-    subcommands = (Create, Get, Modify)
+    subcommands = (Create, Get, Modify, List)
 
     def __init__(self, host):
         super(Invitation, self).__init__(host, 'invitation', use_profile=False, help=_(u'invitation of user(s) without XMPP account'))