From a5e6eea5daea20c0246eb9583cc54326033da197 Mon Sep 17 00:00:00 2001 From: Michael Hanke Date: Thu, 16 May 2019 13:45:35 +0200 Subject: [PATCH] RF: Drop use of `add` in `addurls(save=False)` --- datalad/plugin/addurls.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/datalad/plugin/addurls.py b/datalad/plugin/addurls.py index ef1173320d..79aee6102a 100644 --- a/datalad/plugin/addurls.py +++ b/datalad/plugin/addurls.py @@ -16,7 +16,10 @@ import re import string -from six import string_types +from six import ( + string_types, + text_type, +) from six.moves.urllib.parse import urlparse from datalad.dochelpers import exc_str @@ -493,8 +496,21 @@ def add_meta(rows): for row in rows: ds, filename = row["ds"], row["ds_filename"] - with patch.object(ds.repo, "always_commit", False): + res = ds.repo.add(filename) + res_status = 'notneeded' if not res \ + else 'ok' if res.get('success', False) \ + else 'error' + + yield dict( + action='add', + # decorator dies with Path() + path=text_type(ds.pathobj / filename), + type='file', + status=res_status, + parentds=ds.path, + ) + lgr.debug("Adding metadata to %s in %s", filename, ds.path) for a in ds.repo.set_metadata_(filename, add=row["meta_args"]): res = annexjson2result(a, ds, type="file", logger=lgr) @@ -816,17 +832,12 @@ def __call__(dataset, urlfile, urlformat, filenameformat, filename_format='{}'""".format(url_file, url_format, filename_format) if files_to_add: - for r in dataset.add(files_to_add, save=False): - yield r - meta_rows = [r for r in rows if r["filename_abs"] in files_to_add] for r in add_meta(meta_rows): yield r - # Save here rather than the add call above to trigger a metadata - # commit on the git-annex branch. if save: - for r in dataset.save(message=msg, recursive=True): + for r in dataset.save(path=files_to_add, message=msg, recursive=True): yield r