comparison 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
comparison
equal deleted inserted replaced
2601:12bf089f0bf3 2602:41db2f58c753
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
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 import common
24 from sat_frontends.jp.constants import Const as C
25 from functools import partial
23 import json 26 import json
27 import os
24 28
25 __commands__ = ["Ticket"] 29 __commands__ = ["Ticket"]
26 30
27 FIELDS_MAP = u'mapping' 31 FIELDS_MAP = u'mapping'
32
33
34 class Get(base.CommandBase):
35
36 def __init__(self, host):
37 base.CommandBase.__init__(self, host, 'get', use_verbose=True,
38 use_pubsub=True, pubsub_flags={C.MULTI_ITEMS},
39 pubsub_defaults = {u'service': _(u'auto'), u'node': _(u'auto')},
40 use_output=C.OUTPUT_LIST_XMLUI, help=_(u'get tickets'))
41 self.need_loop=True
42
43 def add_parser_options(self):
44 pass
45
46 def ticketsGetCb(self, tickets_data):
47 self.output(tickets_data[0])
48 self.host.quit(C.EXIT_OK)
49
50 def getTickets(self):
51 self.host.bridge.ticketsGet(
52 self.args.service,
53 self.args.node,
54 self.args.max,
55 self.args.items,
56 u'',
57 {},
58 self.profile,
59 callback=self.ticketsGetCb,
60 errback=partial(self.errback,
61 msg=_(u"can't get tickets: {}"),
62 exit_code=C.EXIT_BRIDGE_ERRBACK))
63
64 def start(self):
65 common.URIFinder(self, os.getcwd(), 'tickets', self.getTickets, meta_map={})
28 66
29 67
30 class Import(base.CommandAnswering): 68 class Import(base.CommandAnswering):
31 # TODO: factorize with blog/import 69 # TODO: factorize with blog/import
32 70
90 self.host.bridge.ticketsImport(self.args.importer, self.args.location, options, self.args.service, self.args.node, self.profile, 128 self.host.bridge.ticketsImport(self.args.importer, self.args.location, options, self.args.service, self.args.node, self.profile,
91 callback=gotId, errback=self.error) 129 callback=gotId, errback=self.error)
92 130
93 131
94 class Ticket(base.CommandBase): 132 class Ticket(base.CommandBase):
95 subcommands = (Import,) 133 subcommands = (Get, Import)
96 134
97 def __init__(self, host): 135 def __init__(self, host):
98 super(Ticket, self).__init__(host, 'ticket', use_profile=False, help=_('tickets handling')) 136 super(Ticket, self).__init__(host, 'ticket', use_profile=False, help=_('tickets handling'))