Skip to content

Commit

Permalink
Sanitize spaces and ,s in organized filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
yarikoptic committed Nov 8, 2023
1 parent c567c8b commit 8d7b1a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions dandi/organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def _sanitize_value(value, field):
Of particular importance is _ which we use, as in BIDS, to separate
_key-value entries
"""
value = re.sub(r"[_*\\/<>:|\"'?%@;]", "-", value)
value = re.sub(r"[_*\\/<>:|\"'?%@;,\s]", "-", value)
if field != "extension":
value = value.replace(".", "-")
return value
Expand Down Expand Up @@ -814,7 +814,9 @@ def _get_metadata(path):
meta["path"] = path
return meta

if not devel_debug and jobs != 1: # Do not use joblib at all if number_of_jobs=1
if (
not devel_debug and jobs != 1
): # Do not use joblib at all if number_of_jobs=1
# Note: It is Python (pynwb) intensive, not IO, so ATM there is little
# to no benefit from Parallel without using multiproc! But that would
# complicate progress bar indication... TODO
Expand Down
17 changes: 15 additions & 2 deletions dandi/tests/test_organize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def test_sanitize_value() -> None:
assert _sanitize_value("_.ext", "extension") == "-.ext"
assert _sanitize_value("_.ext", "unrelated") == "--ext"
assert _sanitize_value("A;B", "unrelated") == "A-B"
# no spaces or tabs please
assert _sanitize_value("A B\t C", "unrelated") == "A-B--C"
assert _sanitize_value("A;B,C", "unrelated") == "A-B-C"
assert _sanitize_value("A\\/B", "unrelated") == "A--B"
assert _sanitize_value("A\"'B", "unrelated") == "A--B"

Expand Down Expand Up @@ -111,7 +114,9 @@ def c() -> Any: # shortcut
@pytest.mark.integration
@pytest.mark.parametrize("mode", no_move_modes)
@pytest.mark.parametrize("jobs", (1, -1))
def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str, jobs: int) -> None:
def test_organize_nwb_test_data(
nwb_test_data: Path, tmp_path: Path, mode: str, jobs: int
) -> None:
outdir = tmp_path / "organized"

relative = False
Expand Down Expand Up @@ -153,7 +158,15 @@ def test_organize_nwb_test_data(nwb_test_data: Path, tmp_path: Path, mode: str,

input_files = nwb_test_data / "v2.0.1"

cmd = ["-d", str(outdir), "--files-mode", mode, str(input_files), "--jobs", str(jobs)]
cmd = [
"-d",
str(outdir),
"--files-mode",
mode,
str(input_files),
"--jobs",
str(jobs),
]
r = CliRunner().invoke(organize, cmd)

# with @map_to_click_exceptions we loose original str of message somehow
Expand Down

0 comments on commit 8d7b1a6

Please sign in to comment.