Mercurial > libervia-backend
comparison frontends/src/jp/cmd_pubsub.py @ 2191:a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 12 Mar 2017 23:34:51 +0100 |
parents | |
children | d65275ac39b3 |
comparison
equal
deleted
inserted
replaced
2190:d823a0cdbcc2 | 2191:a1a8233f89e8 |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # jp: a SàT command line tool | |
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 import base | |
22 from sat.core.i18n import _ | |
23 from sat_frontends.jp.constants import Const as C | |
24 | |
25 __commands__ = ["Pubsub"] | |
26 | |
27 | |
28 class Get(base.CommandBase): | |
29 | |
30 def __init__(self, host): | |
31 base.CommandBase.__init__(self, host, 'get', use_verbose=True, use_output=C.OUTPUT_LIST_XML, help=_(u'get pubsub item(s)')) | |
32 self.need_loop=True | |
33 | |
34 def add_parser_options(self): | |
35 self.parser.add_argument("-i", "--item", type=base.unicode_decoder, action='append', default=[], dest='items', | |
36 help=_(u"item(s) id(s) to get (default: request all items)")) | |
37 self.parser.add_argument("-s", "--sub-id", type=base.unicode_decoder, default=u'', | |
38 help=_(u"subscription id")) | |
39 self.parser.add_argument("-m", "--max", type=int, default=10, help=_(u"maximum number of items to get ({} to get all items)".format(C.NO_LIMIT))) | |
40 # TODO: a key(s) argument to select keys to display | |
41 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) | |
42 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'', | |
43 help=_(u"JID of the PubSub service (default: request profile own pubsub)")) | |
44 # TODO: add MAM filters | |
45 | |
46 | |
47 def psGetCb(self, ps_result): | |
48 self.output(ps_result[0]) | |
49 self.host.quit(C.EXIT_OK) | |
50 | |
51 def psGetEb(self, failure_): | |
52 self.disp(u"can't get pubsub items: {reason}".format( | |
53 reason=failure_), error=True) | |
54 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
55 | |
56 def start(self): | |
57 self.host.bridge.psGet( | |
58 self.args.service, | |
59 self.args.node, | |
60 self.args.max, | |
61 self.args.items, | |
62 self.args.sub_id, | |
63 {}, | |
64 self.profile, | |
65 callback=self.psGetCb, | |
66 errback=self.psGetEb) | |
67 | |
68 | |
69 class Pubsub(base.CommandBase): | |
70 subcommands = (Get,) | |
71 | |
72 def __init__(self, host): | |
73 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) |