# HG changeset patch # User Goffi # Date 1504850288 -7200 # Node ID ebc0dfe9c0ca3c9411c5ed44522717a67bef65f2 # Parent 6c26f435a02d01b4fbc98b5c31fe0a35048be825 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. diff -r 6c26f435a02d -r ebc0dfe9c0ca frontends/src/jp/cmd_pubsub.py --- a/frontends/src/jp/cmd_pubsub.py Fri Sep 08 07:57:57 2017 +0200 +++ b/frontends/src/jp/cmd_pubsub.py Fri Sep 08 07:58:08 2017 +0200 @@ -601,6 +601,79 @@ 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 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'))