Skip to content

Commit 52b7798

Browse files
adswamih
authored andcommitted
Companion PR for datalad/datalad#6706
In response to #17
1 parent ecee7fa commit 52b7798

File tree

1 file changed

+1
-82
lines changed

1 file changed

+1
-82
lines changed

datalad_next/create_sibling_webdav.py

+1-82
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
datasetmethod,
2626
require_dataset,
2727
)
28+
from datalad.distribution.utils import _yield_ds_w_matching_siblings
2829
from datalad.interface.base import (
2930
Interface,
3031
build_doc,
@@ -654,85 +655,3 @@ def _create_storage_sibling(
654655
type='sibling',
655656
url=url,
656657
)
657-
658-
659-
def _yield_ds_w_matching_siblings(
660-
ds, names, recursive=False, recursion_limit=None):
661-
"""(Recursively) inspect a dataset for siblings with particular name(s)
662-
663-
Parameters
664-
----------
665-
ds: Dataset
666-
The dataset to be inspected.
667-
names: iterable
668-
Sibling names (str) to test for.
669-
recursive: bool, optional
670-
Whether to recurse into subdatasets.
671-
recursion_limit: int, optional
672-
Recursion depth limit.
673-
674-
Yields
675-
------
676-
str, str
677-
Path to the dataset with a matching sibling, and name of the matching
678-
sibling in that dataset.
679-
"""
680-
681-
def _discover_all_remotes(ds, refds, **kwargs):
682-
"""Helper to be run on all relevant datasets via foreach
683-
"""
684-
# Note, that `siblings` doesn't tell us about not enabled special
685-
# remotes. There could still be conflicting names we need to know
686-
# about in order to properly deal with the `existing` switch.
687-
688-
repo = ds.repo
689-
# list of known git remotes
690-
if isinstance(repo, AnnexRepo):
691-
remotes = repo.get_remotes(exclude_special_remotes=True)
692-
remotes.extend([v['name']
693-
for k, v in repo.get_special_remotes().items()]
694-
)
695-
else:
696-
remotes = repo.get_remotes()
697-
return remotes
698-
699-
if not recursive:
700-
for name in _discover_all_remotes(ds, ds):
701-
if name in names:
702-
yield ds.path, name
703-
return
704-
705-
# in recursive mode this check could take a substantial amount of
706-
# time: employ a progress bar (or rather a counter, because we don't
707-
# know the total in advance
708-
pbar_id = 'check-siblings-{}'.format(id(ds))
709-
log_progress(
710-
lgr.info, pbar_id,
711-
'Start checking pre-existing sibling configuration %s', ds,
712-
label='Query siblings',
713-
unit=' Siblings',
714-
)
715-
716-
for res in ds.foreach_dataset(
717-
_discover_all_remotes,
718-
recursive=recursive,
719-
recursion_limit=recursion_limit,
720-
return_type='generator',
721-
result_renderer='disabled',
722-
):
723-
# unwind result generator
724-
if 'result' in res:
725-
for name in res['result']:
726-
log_progress(
727-
lgr.info, pbar_id,
728-
'Discovered sibling %s in dataset at %s',
729-
name, res['path'],
730-
update=1,
731-
increment=True)
732-
if name in names:
733-
yield res['path'], name
734-
735-
log_progress(
736-
lgr.info, pbar_id,
737-
'Finished checking pre-existing sibling configuration %s', ds,
738-
)

0 commit comments

Comments
 (0)