diff sat_frontends/jp/cmd_ticket.py @ 2602:41db2f58c753

jp (ticket): new "get" subcommand, to retrieve ticket(s)
author Goffi <goffi@goffi.org>
date Fri, 01 Jun 2018 12:17:06 +0200
parents 26edcf3a30eb
children 56f94936df1e
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_ticket.py	Fri Jun 01 12:15:38 2018 +0200
+++ b/sat_frontends/jp/cmd_ticket.py	Fri Jun 01 12:17:06 2018 +0200
@@ -20,13 +20,51 @@
 
 import base
 from sat.core.i18n import _
+from sat_frontends.jp import common
+from sat_frontends.jp.constants import Const as C
+from functools import partial
 import json
+import os
 
 __commands__ = ["Ticket"]
 
 FIELDS_MAP = u'mapping'
 
 
+class Get(base.CommandBase):
+
+    def __init__(self, host):
+        base.CommandBase.__init__(self, host, 'get', use_verbose=True,
+                                  use_pubsub=True, pubsub_flags={C.MULTI_ITEMS},
+                                  pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')},
+                                  use_output=C.OUTPUT_LIST_XMLUI, help=_(u'get tickets'))
+        self.need_loop=True
+
+    def add_parser_options(self):
+        pass
+
+    def ticketsGetCb(self, tickets_data):
+        self.output(tickets_data[0])
+        self.host.quit(C.EXIT_OK)
+
+    def getTickets(self):
+        self.host.bridge.ticketsGet(
+            self.args.service,
+            self.args.node,
+            self.args.max,
+            self.args.items,
+            u'',
+            {},
+            self.profile,
+            callback=self.ticketsGetCb,
+            errback=partial(self.errback,
+                            msg=_(u"can't get tickets: {}"),
+                            exit_code=C.EXIT_BRIDGE_ERRBACK))
+
+    def start(self):
+        common.URIFinder(self, os.getcwd(), 'tickets', self.getTickets, meta_map={})
+
+
 class Import(base.CommandAnswering):
     # TODO: factorize with blog/import
 
@@ -92,7 +130,7 @@
 
 
 class Ticket(base.CommandBase):
-    subcommands = (Import,)
+    subcommands = (Get, Import)
 
     def __init__(self, host):
         super(Ticket, self).__init__(host, 'ticket', use_profile=False, help=_('tickets handling'))