comparison frontends/src/jp/cmd_pubsub.py @ 2199:ea0d0a4e2ad8

jp (pubsub/node): added set command
author Goffi <goffi@goffi.org>
date Tue, 14 Mar 2017 00:21:20 +0100
parents e0e06391ce91
children afc703419186
comparison
equal deleted inserted replaced
2198:44f12990e275 2199:ea0d0a4e2ad8
61 self.args.node, 61 self.args.node,
62 self.profile, 62 self.profile,
63 callback=self.psNodeConfigurationGetCb, 63 callback=self.psNodeConfigurationGetCb,
64 errback=self.psNodeConfigurationGetEb) 64 errback=self.psNodeConfigurationGetEb)
65 65
66 class NodeSet(base.CommandBase):
67
68 def __init__(self, host):
69 base.CommandBase.__init__(self, host, 'set', use_output=C.OUTPUT_DICT, use_verbose=True, help=_(u'set node configuration'))
70 self.need_loop=True
71
72 def add_parser_options(self):
73 self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields',
74 required=True, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set (required)"))
75 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
76 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
77 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
78
79 def psNodeConfigurationSetCb(self):
80 self.disp(_(u'node configuration successful'), 1)
81 self.host.quit()
82
83 def psNodeConfigurationSetEb(self, failure_):
84 self.disp(u"can't set node configuration: {reason}".format(
85 reason=failure_), error=True)
86 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
87
88 def getKeyName(self, k):
89 if not k.startswith(u'pubsub#'):
90 return u'pubsub#' + k
91 else:
92 return k
93
94 def start(self):
95 self.host.bridge.psNodeConfigurationSet(
96 self.args.service,
97 self.args.node,
98 {self.getKeyName(k): v for k,v in self.args.fields},
99 self.profile,
100 callback=self.psNodeConfigurationSetCb,
101 errback=self.psNodeConfigurationSetEb)
102
66 103
67 class Node(base.CommandBase): 104 class Node(base.CommandBase):
68 subcommands = (NodeInfo,) 105 subcommands = (NodeInfo, NodeSet)
69 106
70 def __init__(self, host): 107 def __init__(self, host):
71 super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling')) 108 super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling'))
72 109
73 110