# HG changeset patch # User Goffi # Date 1489447280 -3600 # Node ID ea0d0a4e2ad838dab5d11a401185347aa595ca6d # Parent 44f12990e275bead9ff6483ec47005b8fd118e89 jp (pubsub/node): added set command diff -r 44f12990e275 -r ea0d0a4e2ad8 frontends/src/jp/cmd_pubsub.py --- 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'))