Skip to content

Commit

Permalink
Restore downloading without --output
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmoore committed Sep 4, 2020
1 parent 171e122 commit bdf0686
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions ome_zarr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ def download(input_path: str, output_dir: str = ".") -> None:
nodes.append(node)
paths.append(node.zarr.zarr_path)

strip_common_prefix(paths)
common = strip_common_prefix(paths)
root = os.path.join(output_dir, common)

assert not os.path.exists(output_dir), f"{output_dir} already exists!"
assert not os.path.exists(root), f"{root} already exists!"
print("downloading...")
for path in paths:
print(" ", path)
Expand Down Expand Up @@ -92,9 +93,10 @@ def download(input_path: str, output_dir: str = ".") -> None:
f.write(json.dumps(metadata))


def strip_common_prefix(paths: List[str]) -> None:
def strip_common_prefix(paths: List[str]) -> str:
"""Find and remove the prefix common to all strings.
Returns the last element of the common prefix.
An exception is thrown if no common prefix exists.
>>> paths = ["a/b", "a/b/c"]
Expand All @@ -118,7 +120,11 @@ def strip_common_prefix(paths: List[str]) -> None:
for path in parts:
msg += f"{path}\n"
raise Exception(msg)
else:
common = parts[0][first_mismatch - 1]

for idx, path in enumerate(parts):
base = os.path.sep.join(path[first_mismatch - 1 :])
paths[idx] = base

return common
3 changes: 2 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def _rotate_and_test(self, *hierarchy: Path, reverse: bool = True):
firstpass.rotate(1)

copy = [str(x) for x in firstpass]
strip_common_prefix(copy)
common = strip_common_prefix(copy)
assert "d" == common
assert set(copy) == set(results)

if reverse:
Expand Down

0 comments on commit bdf0686

Please sign in to comment.