Skip to content

Commit 491cb44

Browse files
committed
Support Downloading series memeber with diff names
1 parent f7dd4d4 commit 491cb44

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

py_src/fusion/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
"tar",
113113
]
114114

115+
FILENAME_CLEAN_RE = re.compile(r"[^a-zA-Z0-9_\-]")
116+
115117
re_str_1 = re.compile("(.)([A-Z][a-z]+)")
116118
re_str_2 = re.compile("([a-z0-9])([A-Z])")
117119

@@ -568,6 +570,7 @@ def distribution_to_filename(
568570
sep = "/"
569571
if "\\" in root_folder:
570572
sep = "\\"
573+
final_name = _clean_filename(final_name)
571574
return f"{root_folder}{sep}{final_name}"
572575

573576

@@ -764,6 +767,15 @@ def path_to_url(x: str, is_raw: bool = False, is_download: bool = False) -> str:
764767
return "/".join(distribution_to_url("", dataset, date, ext, catalog, is_download).split("/")[1:])
765768

766769

770+
def _clean_filename(filename: str) -> str:
771+
path = Path(filename)
772+
stem = path.stem
773+
ext = path.suffix
774+
new_stem = FILENAME_CLEAN_RE.sub("_", stem)
775+
new_base = new_stem + ext
776+
return new_base
777+
778+
767779
def upload_files( # noqa: PLR0913
768780
fs_fusion: fsspec.AbstractFileSystem,
769781
fs_local: fsspec.AbstractFileSystem,

py_tests/test_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from fusion.fusion import Fusion
2121
from fusion.utils import (
2222
PathLikeT,
23+
_clean_filename,
2324
_filename_to_distribution,
2425
_merge_responses,
2526
convert_date_format,
@@ -523,6 +524,11 @@ def test_path_to_url() -> None:
523524
)
524525

525526

527+
def test_clean_filename() -> None:
528+
cleaned = _clean_filename("bad name:report.csv")
529+
assert cleaned == "bad_name_report.csv"
530+
531+
526532
def test_filename_to_distribution() -> None:
527533
file_name = "dataset__catalog__datasetseries.csv"
528534
catalog, dataset, datasetseries, file_format = _filename_to_distribution(file_name)

0 commit comments

Comments
 (0)