Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/frontends/src/jp/cmd_pubsub.py Mon Mar 13 23:18:00 2017 +0100 +++ b/frontends/src/jp/cmd_pubsub.py Mon Mar 13 23:18:57 2017 +0100 @@ -25,6 +25,52 @@ __commands__ = ["Pubsub"] +class NodeInfo(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, help=_(u'retrieve node configuration')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys', + help=_(u"data key to filter")) + self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) + self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'', + help=_(u"JID of the PubSub service (default: request profile own pubsub)")) + + def removePrefix(self, key): + return key[7:] if key.startswith(u"pubsub#") else key + + def filterKey(self, key): + return any((key == k or key == u'pubsub#' + k) for k in self.args.keys) + + def psNodeConfigurationGetCb(self, config_dict): + key_filter = (lambda k: True) if not self.args.keys else self.filterKey + config_dict = {self.removePrefix(k):v for k,v in config_dict.iteritems() if key_filter(k)} + self.output(config_dict) + self.host.quit() + + def psNodeConfigurationGetEb(self, failure_): + self.disp(u"can't get node configuration: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def start(self): + self.host.bridge.psNodeConfigurationGet( + self.args.service, + self.args.node, + self.profile, + callback=self.psNodeConfigurationGetCb, + errback=self.psNodeConfigurationGetEb) + + +class Node(base.CommandBase): + subcommands = (NodeInfo,) + + def __init__(self, host): + super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling')) + + class Get(base.CommandBase): def __init__(self, host): @@ -67,7 +113,7 @@ class Pubsub(base.CommandBase): - subcommands = (Get,) + subcommands = (Get, Node) def __init__(self, host): super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))