comparison frontends/src/jp/common.py @ 2554:0062d3e79d12

plugin uri finder, jp (merge-request): labels handling: - a label can now be specified as metadata after specifing a "xmpp:" URI in doc (with « use "[label]" label" » after the URI) - updated jp to handle new signature of URIFind - jp (merge-request/set): labels can now be specified using --label
author Goffi <goffi@goffi.org>
date Sun, 01 Apr 2018 20:17:00 +0200
parents b27165bf160c
children 501b0f827f63
comparison
equal deleted inserted replaced
2553:39b10475f56b 2554:0062d3e79d12
669 669
670 class URIFinder(object): 670 class URIFinder(object):
671 """Helper class to find URIs in well-known locations""" 671 """Helper class to find URIs in well-known locations"""
672 672
673 def __init__(self, command, path, key, callback): 673 def __init__(self, command, path, key, callback):
674 """
675 @param command(CommandBase): command instance
676 args of this instance will be updated with found values
677 @param path(unicode): absolute path to use as a starting point to look for URIs
678 @param key(unicode): key to look for
679 @param callback(callable): method to call once URIs are found (or not)
680 """
674 if not command.args.service and not command.args.node: 681 if not command.args.service and not command.args.node:
675 self.host = command.host 682 self.host = command.host
676 self.args = command.args 683 self.args = command.args
677 self.key = key 684 self.key = key
678 self.callback = callback 685 self.callback = callback
683 msg=_(u"can't find " + key + u" URI: {}"), 690 msg=_(u"can't find " + key + u" URI: {}"),
684 exit_code=C.EXIT_BRIDGE_ERRBACK)) 691 exit_code=C.EXIT_BRIDGE_ERRBACK))
685 else: 692 else:
686 callback() 693 callback()
687 694
688 def URIFindCb(self, uri_data): 695 def URIFindCb(self, uris_data):
689 try: 696 try:
690 uri = uri_data[self.key] 697 uri_data = uris_data[self.key]
691 except KeyError: 698 except KeyError:
692 self.host.disp(_(u"No {key} URI specified for this project, please specify service and node").format(key=self.key), error=True) 699 self.host.disp(_(u"No {key} URI specified for this project, please specify service and node").format(key=self.key), error=True)
693 self.host.quit(C.EXIT_NOT_FOUND) 700 self.host.quit(C.EXIT_NOT_FOUND)
701 else:
702 uri = uri_data[u'uri']
703 labels_raw = uri_data.get(u'labels')
704
705 if labels_raw is not None:
706 try:
707 labels = self.args.labels
708 except AttributeError:
709 raise exceptions.InternalError(u'there is no "labels" arguments')
710 else:
711 if labels is None:
712 labels = []
713 labels.extend(json.loads(labels_raw))
714 self.args.labels = labels
694 parsed_uri = xmpp_uri.parseXMPPUri(uri) 715 parsed_uri = xmpp_uri.parseXMPPUri(uri)
695 try: 716 try:
696 self.args.service = parsed_uri[u'path'] 717 self.args.service = parsed_uri[u'path']
697 self.args.node = parsed_uri[u'node'] 718 self.args.node = parsed_uri[u'node']
698 except KeyError: 719 except KeyError: