Mercurial > libervia-backend
comparison frontends/src/jp/cmd_pubsub.py @ 2197:e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 13 Mar 2017 23:18:57 +0100 |
parents | d65275ac39b3 |
children | ea0d0a4e2ad8 |
comparison
equal
deleted
inserted
replaced
2196:d3e48c9a255e | 2197:e0e06391ce91 |
---|---|
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 | 24 |
25 __commands__ = ["Pubsub"] | 25 __commands__ = ["Pubsub"] |
26 | |
27 | |
28 class NodeInfo(base.CommandBase): | |
29 | |
30 def __init__(self, host): | |
31 base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, help=_(u'retrieve node configuration')) | |
32 self.need_loop=True | |
33 | |
34 def add_parser_options(self): | |
35 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys', | |
36 help=_(u"data key to filter")) | |
37 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) | |
38 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'', | |
39 help=_(u"JID of the PubSub service (default: request profile own pubsub)")) | |
40 | |
41 def removePrefix(self, key): | |
42 return key[7:] if key.startswith(u"pubsub#") else key | |
43 | |
44 def filterKey(self, key): | |
45 return any((key == k or key == u'pubsub#' + k) for k in self.args.keys) | |
46 | |
47 def psNodeConfigurationGetCb(self, config_dict): | |
48 key_filter = (lambda k: True) if not self.args.keys else self.filterKey | |
49 config_dict = {self.removePrefix(k):v for k,v in config_dict.iteritems() if key_filter(k)} | |
50 self.output(config_dict) | |
51 self.host.quit() | |
52 | |
53 def psNodeConfigurationGetEb(self, failure_): | |
54 self.disp(u"can't get node configuration: {reason}".format( | |
55 reason=failure_), error=True) | |
56 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
57 | |
58 def start(self): | |
59 self.host.bridge.psNodeConfigurationGet( | |
60 self.args.service, | |
61 self.args.node, | |
62 self.profile, | |
63 callback=self.psNodeConfigurationGetCb, | |
64 errback=self.psNodeConfigurationGetEb) | |
65 | |
66 | |
67 class Node(base.CommandBase): | |
68 subcommands = (NodeInfo,) | |
69 | |
70 def __init__(self, host): | |
71 super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling')) | |
26 | 72 |
27 | 73 |
28 class Get(base.CommandBase): | 74 class Get(base.CommandBase): |
29 | 75 |
30 def __init__(self, host): | 76 def __init__(self, host): |
65 callback=self.psItemGetCb, | 111 callback=self.psItemGetCb, |
66 errback=self.psItemGetEb) | 112 errback=self.psItemGetEb) |
67 | 113 |
68 | 114 |
69 class Pubsub(base.CommandBase): | 115 class Pubsub(base.CommandBase): |
70 subcommands = (Get,) | 116 subcommands = (Get, Node) |
71 | 117 |
72 def __init__(self, host): | 118 def __init__(self, host): |
73 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) | 119 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) |