Skip to content

Commit

Permalink
RF: Drop use of add in addurls(save=False)
Browse files Browse the repository at this point in the history
  • Loading branch information
mih authored and kyleam committed May 16, 2019
1 parent 0db3226 commit a5e6eea
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions datalad/plugin/addurls.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit a5e6eea

Please sign in to comment.