comparison frontends/src/jp/cmd_pubsub.py @ 2353:ebc0dfe9c0ca

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.
author Goffi <goffi@goffi.org>
date Fri, 08 Sep 2017 07:58:08 +0200
parents 3c0a3fae1862
children 47516e90d26a
comparison
equal deleted inserted replaced
2352:6c26f435a02d 2353:ebc0dfe9c0ca
597 597
598 def start(self): 598 def start(self):
599 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj = self.getItemPath(self.args.item) 599 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj = self.getItemPath(self.args.item)
600 600
601 self.edit(content_file_path, content_file_obj) 601 self.edit(content_file_path, content_file_obj)
602
603
604 class Subscribe(base.CommandBase):
605
606 def __init__(self, host):
607 base.CommandBase.__init__(self, host, 'subscribe', use_pubsub_node_req=True, use_verbose=True, help=_(u'subscribe to a node'))
608 self.need_loop=True
609
610 def add_parser_options(self):
611 pass
612
613 def psSubscribeCb(self):
614 self.disp(_(u'subscription done'), 1)
615 self.host.quit()
616
617 def start(self):
618 self.host.bridge.psSubscribe(
619 self.args.service,
620 self.args.node,
621 self.profile,
622 callback=self.psSubscribeCb,
623 errback=partial(self.errback,
624 msg=_(u"can't subscribe to node: {}"),
625 exit_code=C.EXIT_BRIDGE_ERRBACK))
626
627
628 class Unsubscribe(base.CommandBase):
629 # TODO: voir pourquoi NodeNotFound sur subscribe juste après unsubscribe
630
631 def __init__(self, host):
632 base.CommandBase.__init__(self, host, 'unsubscribe', use_pubsub_node_req=True, use_verbose=True, help=_(u'unsubscribe from a node'))
633 self.need_loop=True
634
635 def add_parser_options(self):
636 pass
637
638 def psUnsubscribeCb(self):
639 self.disp(_(u'subscription removed'), 1)
640 self.host.quit()
641
642 def start(self):
643 self.host.bridge.psUnsubscribe(
644 self.args.service,
645 self.args.node,
646 self.profile,
647 callback=self.psUnsubscribeCb,
648 errback=partial(self.errback,
649 msg=_(u"can't unsubscribe from node: {}"),
650 exit_code=C.EXIT_BRIDGE_ERRBACK))
651
652
653 class Subscriptions(base.CommandBase):
654
655 def __init__(self, host):
656 base.CommandBase.__init__(self, host, 'subscriptions', use_output=C.OUTPUT_LIST_DICT, use_pubsub=True, help=_(u'retrieve all subscriptions on a service'))
657 self.need_loop=True
658
659 def add_parser_options(self):
660 pass
661
662 def psSubscriptionsGetCb(self, subscriptions):
663 self.output(subscriptions)
664 self.host.quit()
665
666 def start(self):
667 self.host.bridge.psSubscriptionsGet(
668 self.args.service,
669 self.args.node,
670 self.profile,
671 callback=self.psSubscriptionsGetCb,
672 errback=partial(self.errback,
673 msg=_(u"can't retrieve subscriptions: {}"),
674 exit_code=C.EXIT_BRIDGE_ERRBACK))
602 675
603 676
604 class Affiliations(base.CommandBase): 677 class Affiliations(base.CommandBase):
605 678
606 def __init__(self, host): 679 def __init__(self, host):
1094 def __init__(self, host): 1167 def __init__(self, host):
1095 super(Hook, self).__init__(host, 'hook', use_profile=False, use_verbose=True, help=_('trigger action on Pubsub notifications')) 1168 super(Hook, self).__init__(host, 'hook', use_profile=False, use_verbose=True, help=_('trigger action on Pubsub notifications'))
1096 1169
1097 1170
1098 class Pubsub(base.CommandBase): 1171 class Pubsub(base.CommandBase):
1099 subcommands = (Get, Delete, Edit, Node, Affiliations, Search, Hook, Uri) 1172 subcommands = (Get, Delete, Edit, Subscribe, Unsubscribe, Subscriptions, Node, Affiliations, Search, Hook, Uri)
1100 1173
1101 def __init__(self, host): 1174 def __init__(self, host):
1102 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management')) 1175 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))