Mercurial > libervia-backend
changeset 2199:ea0d0a4e2ad8
jp (pubsub/node): added set command
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 14 Mar 2017 00:21:20 +0100 (2017-03-13) |
parents | 44f12990e275 |
children | 95dc90f1065a |
files | frontends/src/jp/cmd_pubsub.py |
diffstat | 1 files changed, 38 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/jp/cmd_pubsub.py Tue Mar 14 00:18:02 2017 +0100 +++ b/frontends/src/jp/cmd_pubsub.py Tue Mar 14 00:21:20 2017 +0100 @@ -63,9 +63,46 @@ callback=self.psNodeConfigurationGetCb, errback=self.psNodeConfigurationGetEb) +class NodeSet(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'set', use_output=C.OUTPUT_DICT, use_verbose=True, help=_(u'set node configuration')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields', + required=True, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set (required)")) + 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 psNodeConfigurationSetCb(self): + self.disp(_(u'node configuration successful'), 1) + self.host.quit() + + def psNodeConfigurationSetEb(self, failure_): + self.disp(u"can't set node configuration: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def getKeyName(self, k): + if not k.startswith(u'pubsub#'): + return u'pubsub#' + k + else: + return k + + def start(self): + self.host.bridge.psNodeConfigurationSet( + self.args.service, + self.args.node, + {self.getKeyName(k): v for k,v in self.args.fields}, + self.profile, + callback=self.psNodeConfigurationSetCb, + errback=self.psNodeConfigurationSetEb) + class Node(base.CommandBase): - subcommands = (NodeInfo,) + subcommands = (NodeInfo, NodeSet) def __init__(self, host): super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling'))