diff frontends/src/jp/cmd_pubsub.py @ 2235:4db836386641

jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase pubsub add --node and --service arguments pubsub_node_req add --service and a positional node argument (i.e. mandatory)
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:01:43 +0200
parents 87fcd4a7c7e4
children 17502e74c046
line wrap: on
line diff
--- a/frontends/src/jp/cmd_pubsub.py	Thu Apr 27 00:59:25 2017 +0200
+++ b/frontends/src/jp/cmd_pubsub.py	Thu Apr 27 01:01:43 2017 +0200
@@ -28,31 +28,15 @@
 __commands__ = ["Pubsub"]
 
 
-class NodeCommon(object):
-    node_required = True
-
-    def __init__(self, node_required=True):
-        self.node_required = node_required
-
-    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: PEP service)"))
-        if self.node_required:
-            self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
-        else:
-            self.parser.add_argument("-n", "--node", type=base.unicode_decoder, default=u'', help=_(u"node to request"))
-
-
-class NodeInfo(base.CommandBase, NodeCommon):
+class NodeInfo(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, help=_(u'retrieve node configuration'))
+        base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_(u'retrieve node configuration'))
         self.need_loop=True
 
     def add_parser_options(self):
         self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys',
                                  help=_(u"data key to filter"))
-        NodeCommon.add_parser_options(self)
 
     def removePrefix(self, key):
         return key[7:] if key.startswith(u"pubsub#") else key
@@ -80,18 +64,16 @@
             errback=self.psNodeConfigurationGetEb)
 
 
-class NodeCreate(base.CommandBase, NodeCommon):
+class NodeCreate(base.CommandBase):
 
     def __init__(self, host):
-        NodeCommon.__init__(self, node_required=False)
-        base.CommandBase.__init__(self, host, 'create', use_output=C.OUTPUT_DICT, use_verbose=True, help=_(u'create a node'))
+        base.CommandBase.__init__(self, host, 'create', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, use_verbose=True, help=_(u'create a node'))
         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',
-                                 default={}, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set (required)"))
+                                 default={}, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set"))
         self.parser.add_argument("-F", "--full-prefix", action="store_true", help=_(u"don't prepend \"pubsub#\" prefix to field names"))
-        NodeCommon.add_parser_options(self)
 
     def psNodeCreateCb(self, node_id):
         if self.host.verbosity:
@@ -122,15 +104,14 @@
                             exit_code=C.EXIT_BRIDGE_ERRBACK))
 
 
-class NodeDelete(base.CommandBase, NodeCommon):
+class NodeDelete(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'delete', help=_(u'delete a node'))
+        base.CommandBase.__init__(self, host, 'delete', use_pubsub_node_req=True, help=_(u'delete a node'))
         self.need_loop=True
 
     def add_parser_options(self):
         self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete node without confirmation'))
-        NodeCommon.add_parser_options(self)
 
     def psNodeDeleteCb(self):
         self.disp(_(u'node deleted successfully'))
@@ -160,16 +141,15 @@
                             exit_code=C.EXIT_BRIDGE_ERRBACK))
 
 
-class NodeSet(base.CommandBase, NodeCommon):
+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'))
+        base.CommandBase.__init__(self, host, 'set', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, 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)"))
-        NodeCommon.add_parser_options(self)
 
     def psNodeConfigurationSetCb(self):
         self.disp(_(u'node configuration successful'), 1)
@@ -196,14 +176,14 @@
             errback=self.psNodeConfigurationSetEb)
 
 
-class NodeAffiliationsGet(base.CommandBase, NodeCommon):
+class NodeAffiliationsGet(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, help=_(u'retrieve node affiliations (for node owner)'))
+        base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_(u'retrieve node affiliations (for node owner)'))
         self.need_loop=True
 
     def add_parser_options(self):
-        NodeCommon.add_parser_options(self)
+        pass
 
     def psNodeAffiliationsGetCb(self, affiliations):
         self.output(affiliations)
@@ -223,14 +203,13 @@
             errback=self.psNodeAffiliationsGetEb)
 
 
-class NodeAffiliationsSet(base.CommandBase, NodeCommon):
+class NodeAffiliationsSet(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'set', use_verbose=True, help=_(u'set affiliations (for node owner)'))
+        base.CommandBase.__init__(self, host, 'set', use_pubsub_node_req=True, use_verbose=True, help=_(u'set affiliations (for node owner)'))
         self.need_loop=True
 
     def add_parser_options(self):
-        NodeCommon.add_parser_options(self)
         # 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",
@@ -277,10 +256,10 @@
         super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling'))
 
 
-class Get(base.CommandBase, NodeCommon):
+class Get(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_LIST_XML, help=_(u'get pubsub item(s)'))
+        base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_LIST_XML, use_pubsub_node_req=True, help=_(u'get pubsub item(s)'))
         self.need_loop=True
 
     def add_parser_options(self):
@@ -315,15 +294,14 @@
             errback=self.psItemGetEb)
 
 
-class Affiliations(base.CommandBase, NodeCommon):
+class Affiliations(base.CommandBase):
 
     def __init__(self, host):
-        NodeCommon.__init__(self, node_required=False)
-        base.CommandBase.__init__(self, host, 'affiliations', use_output=C.OUTPUT_DICT, help=_(u'retrieve all affiliations on a service'))
+        base.CommandBase.__init__(self, host, 'affiliations', use_output=C.OUTPUT_DICT, use_pubsub=True, help=_(u'retrieve all affiliations on a service'))
         self.need_loop=True
 
     def add_parser_options(self):
-        NodeCommon.add_parser_options(self)
+        pass
 
     def psAffiliationsGetCb(self, affiliations):
         self.output(affiliations)
@@ -343,14 +321,13 @@
             errback=self.psAffiliationsGetEb)
 
 
-class Uri(base.CommandBase, NodeCommon):
+class Uri(base.CommandBase):
 
     def __init__(self, host):
-        base.CommandBase.__init__(self, host, 'uri', use_profile=False, help=_(u'build URI'))
+        base.CommandBase.__init__(self, host, 'uri', use_profile=False, use_pubsub_node_req=True, help=_(u'build URI'))
         self.need_loop=True
 
     def add_parser_options(self):
-        NodeCommon.add_parser_options(self)
         self.parser.add_argument("-i", "--item", type=base.unicode_decoder, help=_(u"item to link"))
         self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default=C.PROF_KEY_DEFAULT, help=_(u"profile (used when no server is specified)"))