From afef209d704f982f4852e592d22a84210c70114c Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 14 Mar 2017 00:21:20 +0100 Subject: [PATCH] jp (pubsub/node): added set command --- frontends/src/jp/cmd_pubsub.py | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/frontends/src/jp/cmd_pubsub.py b/frontends/src/jp/cmd_pubsub.py index dfc8fea9..ff4204ee 100644 --- a/frontends/src/jp/cmd_pubsub.py +++ b/frontends/src/jp/cmd_pubsub.py @@ -63,9 +63,46 @@ class NodeInfo(base.CommandBase): 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'))