changeset 2207:d662bdd682b2

jp (pubsub/node) added pubsub/node/affiliations/set command
author Goffi <goffi@goffi.org>
date Sun, 26 Mar 2017 18:08:05 +0200
parents 59d3de85a0cb
children c316c6f6a737
files frontends/src/jp/cmd_pubsub.py
diffstat 1 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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'))