Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add _check_top_level_folder option. #381

Merged
merged 3 commits into from
May 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions datashuttle/datashuttle.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def create_folders(
["ephys", "behav"])
"""
self._start_log("create-folders", local_vars=locals())
self._check_top_level_folder(top_level_folder)

utils.log("\nFormatting Names...")
ds_logger.log_names(["sub_names", "ses_names"], [sub_names, ses_names])
Expand Down Expand Up @@ -353,6 +354,8 @@ def upload_custom(
if init_log:
self._start_log("upload-custom", local_vars=locals())

self._check_top_level_folder(top_level_folder)

TransferData(
self.cfg,
"upload",
Expand Down Expand Up @@ -424,6 +427,8 @@ def download_custom(
if init_log:
self._start_log("download-custom", local_vars=locals())

self._check_top_level_folder(top_level_folder)

TransferData(
self.cfg,
"download",
Expand Down Expand Up @@ -1451,3 +1456,16 @@ def _update_settings_with_new_canonical_keys(self, settings: Dict):
for key in ["overwrite_existing_files", "dry_run"]:
if key not in settings["tui"]:
settings["tui"][key] = canonical_tui_configs["tui"][key]

def _check_top_level_folder(self, top_level_folder):
"""
Raise an error if ``top_level_folder`` not correct.
"""
canonical_top_level_folders = canonical_folders.get_top_level_folders()

if top_level_folder not in canonical_top_level_folders:
utils.log_and_raise_error(
f"`top_level_folder` must be one of "
f"{canonical_top_level_folders}",
ValueError,
)