From e33d68bcf1ff77d763427bd36ecec192dbeed15e Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 8 Sep 2017 07:58:08 +0200 Subject: [PATCH] jp (pubsub): added subscribe, unsubscribe and subscriptions methods: those methods are added in pubsub directly instead of being subcommands of pubsub/subscription to make them more easy/natural to use. The node owner versions are in pubsub/node/subscriptions though. --- frontends/src/jp/cmd_pubsub.py | 75 +++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/frontends/src/jp/cmd_pubsub.py b/frontends/src/jp/cmd_pubsub.py index 061a3b4e..e65046e9 100644 --- a/frontends/src/jp/cmd_pubsub.py +++ b/frontends/src/jp/cmd_pubsub.py @@ -601,6 +601,79 @@ class Edit(base.CommandBase, common.BaseEdit): self.edit(content_file_path, content_file_obj) +class Subscribe(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'subscribe', use_pubsub_node_req=True, use_verbose=True, help=_(u'subscribe to a node')) + self.need_loop=True + + def add_parser_options(self): + pass + + def psSubscribeCb(self): + self.disp(_(u'subscription done'), 1) + self.host.quit() + + def start(self): + self.host.bridge.psSubscribe( + self.args.service, + self.args.node, + self.profile, + callback=self.psSubscribeCb, + errback=partial(self.errback, + msg=_(u"can't subscribe to node: {}"), + exit_code=C.EXIT_BRIDGE_ERRBACK)) + + +class Unsubscribe(base.CommandBase): + # TODO: voir pourquoi NodeNotFound sur subscribe juste après unsubscribe + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'unsubscribe', use_pubsub_node_req=True, use_verbose=True, help=_(u'unsubscribe from a node')) + self.need_loop=True + + def add_parser_options(self): + pass + + def psUnsubscribeCb(self): + self.disp(_(u'subscription removed'), 1) + self.host.quit() + + def start(self): + self.host.bridge.psUnsubscribe( + self.args.service, + self.args.node, + self.profile, + callback=self.psUnsubscribeCb, + errback=partial(self.errback, + msg=_(u"can't unsubscribe from node: {}"), + exit_code=C.EXIT_BRIDGE_ERRBACK)) + + +class Subscriptions(base.CommandBase): + + def __init__(self, host): + base.CommandBase.__init__(self, host, 'subscriptions', use_output=C.OUTPUT_LIST_DICT, use_pubsub=True, help=_(u'retrieve all subscriptions on a service')) + self.need_loop=True + + def add_parser_options(self): + pass + + def psSubscriptionsGetCb(self, subscriptions): + self.output(subscriptions) + self.host.quit() + + def start(self): + self.host.bridge.psSubscriptionsGet( + self.args.service, + self.args.node, + self.profile, + callback=self.psSubscriptionsGetCb, + errback=partial(self.errback, + msg=_(u"can't retrieve subscriptions: {}"), + exit_code=C.EXIT_BRIDGE_ERRBACK)) + + class Affiliations(base.CommandBase): def __init__(self, host): @@ -1096,7 +1169,7 @@ class Hook(base.CommandBase): class Pubsub(base.CommandBase): - subcommands = (Get, Delete, Edit, Node, Affiliations, Search, Hook, Uri) + subcommands = (Get, Delete, Edit, Subscribe, Unsubscribe, Subscriptions, Node, Affiliations, Search, Hook, Uri) def __init__(self, host): super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))