jp (pubsub/node) added pubsub/node/affiliations/set command

This commit is contained in:
Goffi 2017-03-26 18:08:05 +02:00
commit 3eb7074f26

View file

@ -108,9 +108,9 @@ class NodeAffiliationsGet(base.CommandBase):
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 @@ class NodeAffiliationsGet(base.CommandBase):
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'))