Skip to content
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
40 changes: 21 additions & 19 deletions cosipy/utilities/setup_cosipy/setup_cosipy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Generate sample configuration files for COSIPY.
"""Generate sample configuration files for COSIPY.

Usage:

Expand Down Expand Up @@ -111,30 +110,33 @@ def copy_file_to_target(
"""

target_path = f"{target_dir}/{basename}"
decision = True
source_path = f"{source_dir}/{basename}"
overwrite = True # otherwise no file created if missing

if not silent_overwrite and os.path.isfile(target_path):
decision = input(
f"{basename} already exists in {target_dir}/\nOverwrite?\n"
)
decision = strtobool(decision)
if decision:
shutil.copyfile(
f"{source_dir}/{basename}", target_path, follow_symlinks=True
)
prompt = f"{basename} already exists in {target_dir}/\nReplace target? [y/N] "
overwrite = get_user_confirmation(prompt)
if overwrite:
shutil.copyfile(source_path, target_path, follow_symlinks=True)
else:
print("Skipping...")

def get_user_confirmation(prompt: str) -> bool:
"""Get user confirmation.

def strtobool(val: str) -> bool:
"""Convert user input to bool."""
val = val.lower()
if val in ("y", "yes"):
return True
elif val in ("n", "no"):
return False
Args:
prompt: Prompt to display to user.

Returns:
True if user confirms, False otherwise.
"""
user_input: str = input(prompt).lower().strip()
if user_input not in ("y", "yes", "n", "no", ""):
print("Please enter 'yes' or 'no'.\n")
return get_user_confirmation(prompt)
return user_input in ("y", "yes")

def main():

args = get_user_arguments()

sample_path = get_sample_directory()
Expand Down