# HG changeset patch # User Goffi # Date 1490544485 -7200 # Node ID d662bdd682b2a27a8ca9b2593e55d9613b87357c # Parent 59d3de85a0cbecd4e9c07f643b32214b31eb2721 jp (pubsub/node) added pubsub/node/affiliations/set command diff -r 59d3de85a0cb -r d662bdd682b2 frontends/src/jp/cmd_pubsub.py --- a/frontends/src/jp/cmd_pubsub.py Sun Mar 26 18:06:58 2017 +0200 +++ b/frontends/src/jp/cmd_pubsub.py Sun Mar 26 18:08:05 2017 +0200 @@ -108,9 +108,9 @@ self.need_loop=True def add_parser_options(self): - self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', help=_(u"JID of the PubSub service (default: request profile own pubsub)")) + self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) def psNodeAffiliationsGetCb(self, affiliations): self.output(affiliations) @@ -130,8 +130,50 @@ errback=self.psNodeAffiliationsGetEb) +class NodeAffiliationsSet(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'set', use_verbose=True, help=_(u'set affiliations (for node owner)')) + self.need_loop=True + + def add_parser_options(self): + self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', + help=_(u"JID of the PubSub service (default: request profile own pubsub)")) + self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to set")) + # XXX: we use optional argument syntax for a required one because list of list of 2 elements + # (uses to construct dicts) don't work with positional arguments + self.parser.add_argument("-a", + "--affiliation", + dest="affiliations", + metavar=('JID', 'AFFILIATION'), + required=True, + type=base.unicode_decoder, + action="append", + nargs=2, + help=_(u"entity/affiliation couple(s)")) + + def psNodeAffiliationsSetCb(self): + self.disp(_(u"affiliations have been set"), 1) + self.host.quit() + + def psNodeAffiliationsSetEb(self, failure_): + self.disp(u"can't set node affiliations: {reason}".format( + reason=failure_), error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + + def start(self): + affiliations = dict(self.args.affiliations) + self.host.bridge.psNodeAffiliationsSet( + self.args.service, + self.args.node, + affiliations, + self.profile, + callback=self.psNodeAffiliationsSetCb, + errback=self.psNodeAffiliationsSetEb) + + class NodeAffiliations(base.CommandBase): - subcommands = (NodeAffiliationsGet,) + subcommands = (NodeAffiliationsGet, NodeAffiliationsSet) def __init__(self, host): super(NodeAffiliations, self).__init__(host, 'affiliations', use_profile=False, help=_(u'set or retrieve node affiliations'))