changeset 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 39b10475f56b
children ebdaaf858f21
files frontends/src/jp/cmd_merge_request.py frontends/src/jp/common.py src/plugins/plugin_exp_pubsub_schema.py src/plugins/plugin_misc_tickets.py src/plugins/plugin_misc_uri_finder.py
diffstat 5 files changed, 41 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/jp/cmd_merge_request.py	Sat Mar 31 18:42:01 2018 +0200
+++ b/frontends/src/jp/cmd_merge_request.py	Sun Apr 01 20:17:00 2018 +0200
@@ -41,6 +41,7 @@
         self.parser.add_argument("-i", "--item", type=base.unicode_decoder, default=u'', help=_(u"id or URL of the request to update, or nothing for a new one"))
         self.parser.add_argument("-r", "--repository", metavar="PATH", type=base.unicode_decoder, default=u'.', help=_(u"path of the repository (DEFAULT: current directory)"))
         self.parser.add_argument("-f", "--force", action="store_true", help=_(u"publish merge request without confirmation"))
+        self.parser.add_argument("-l", "--label", dest="labels", type=base.unicode_decoder, action='append', help=_(u"labels to categorize your request"))
 
     def mergeRequestSetCb(self, published_id):
         if published_id:
@@ -51,12 +52,15 @@
 
     def sendRequest(self):
         extra = {'update': 'true'} if self.args.item else {}
+        values = {}
+        if self.args.labels is not None:
+            values[u'labels'] = self.args.labels
         self.host.bridge.mergeRequestSet(
             self.args.service,
             self.args.node,
             self.repository,
             u'auto',
-            {},
+            values,
             u'',
             self.args.item,
             extra,
--- a/frontends/src/jp/common.py	Sat Mar 31 18:42:01 2018 +0200
+++ b/frontends/src/jp/common.py	Sun Apr 01 20:17:00 2018 +0200
@@ -671,6 +671,13 @@
     """Helper class to find URIs in well-known locations"""
 
     def __init__(self, command, path, key, callback):
+        """
+        @param command(CommandBase): command instance
+            args of this instance will be updated with found values
+        @param path(unicode): absolute path to use as a starting point to look for URIs
+        @param key(unicode): key to look for
+        @param callback(callable): method to call once URIs are found (or not)
+        """
         if not command.args.service and not command.args.node:
             self.host = command.host
             self.args = command.args
@@ -685,12 +692,26 @@
         else:
             callback()
 
-    def URIFindCb(self, uri_data):
+    def URIFindCb(self, uris_data):
         try:
-            uri = uri_data[self.key]
+            uri_data = uris_data[self.key]
         except KeyError:
             self.host.disp(_(u"No {key} URI specified for this project, please specify service and node").format(key=self.key), error=True)
             self.host.quit(C.EXIT_NOT_FOUND)
+        else:
+            uri = uri_data[u'uri']
+            labels_raw = uri_data.get(u'labels')
+
+        if labels_raw is not None:
+            try:
+                labels = self.args.labels
+            except AttributeError:
+                raise exceptions.InternalError(u'there is no "labels" arguments')
+            else:
+                if labels is None:
+                    labels = []
+                labels.extend(json.loads(labels_raw))
+                self.args.labels = labels
         parsed_uri = xmpp_uri.parseXMPPUri(uri)
         try:
             self.args.service = parsed_uri[u'path']
--- a/src/plugins/plugin_exp_pubsub_schema.py	Sat Mar 31 18:42:01 2018 +0200
+++ b/src/plugins/plugin_exp_pubsub_schema.py	Sun Apr 01 20:17:00 2018 +0200
@@ -430,8 +430,8 @@
         """Set an item in a node with a schema
 
         This method can be used directly by *Set methods added by dependant plugin
-        @param values(dict[key(unicode), [iterable[object], object]]): values of the items
-            if not iterable, will be put in a list
+        @param values(dict[key(unicode), [iterable[object]|object]]): values of the items
+            if value is not iterable, it will be put in a list
             'created' and 'updated' will be forced to current time:
                 - 'created' is set if item_id is None, i.e. if it's a new ticket
                 - 'updated' is set everytime
--- a/src/plugins/plugin_misc_tickets.py	Sat Mar 31 18:42:01 2018 +0200
+++ b/src/plugins/plugin_misc_tickets.py	Sun Apr 01 20:17:00 2018 +0200
@@ -84,8 +84,8 @@
 
         @param node(unicode, None): Pubsub node to use
             None to use default tickets node
-        @param values(dict[key(unicode), [iterable[object], object]]): values of the ticket
-            if not iterable, will be put in a list
+        @param values(dict[key(unicode), [iterable[object]|object]]): values of the ticket
+            if value is not iterable, it will be put in a list
             'created' and 'updated' will be forced to current time:
                 - 'created' is set if item_id is None, i.e. if it's a new ticket
                 - 'updated' is set everytime
--- a/src/plugins/plugin_misc_uri_finder.py	Sat Mar 31 18:42:01 2018 +0200
+++ b/src/plugins/plugin_misc_uri_finder.py	Sun Apr 01 20:17:00 2018 +0200
@@ -23,6 +23,7 @@
 from twisted.internet import defer
 import textwrap
 log = getLogger(__name__)
+import json
 import os.path
 import os
 import re
@@ -51,7 +52,7 @@
         log.info(_(u"URI finder plugin initialization"))
         self.host = host
         host.bridge.addMethod("URIFind", ".plugin",
-                              in_sign='sas', out_sign='a{ss}',
+                              in_sign='sas', out_sign='a{sa{ss}}',
                               method=self.find,
                               async=True)
 
@@ -64,7 +65,9 @@
         @return (dict[unicode, unicode]): map from key to found uri
         """
         keys_re = u'|'.join(keys)
-        uri_re = re.compile(ur'(?P<key>{keys_re})[ :]? +(?P<uri>xmpp:\S+)'.format(keys_re=keys_re))
+        label_re = r'"(?P<label>[^"]+)"'
+        uri_re = re.compile(ur'(?P<key>{keys_re})[ :]? +(?P<uri>xmpp:\S+)(?:.*use {label_re} label)?'.format(
+            keys_re=keys_re, label_re = label_re))
         path = os.path.normpath(path)
         if not os.path.isdir(path) or not os.path.isabs(path):
             raise ValueError(u'path must be an absolute path to a directory')
@@ -79,10 +82,13 @@
                         for m in uri_re.finditer(f.read()):
                             key = m.group(u'key')
                             uri = m.group(u'uri')
+                            label = m.group(u'label')
                             if key in found_uris:
                                 log.warning(_(u"Ignoring already found uri for key \"{key}\"").format(key=key))
                             else:
-                                found_uris[key] = uri
+                                uri_data = found_uris[key] = {u'uri': uri}
+                                if label is not None:
+                                    uri_data[u'labels'] = json.dumps([label])
             if found_uris:
                 break
             path = os.path.dirname(path)