Skip to content

Commit 4a55807

Browse files
authored
Allowing passing multiple job IDs to tlo batch-download command (#1313)
1 parent f8e6c23 commit 4a55807

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/tlo/cli.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,11 @@ def print_basic_job_details(job: dict):
469469

470470

471471
@cli.command()
472-
@click.argument("job_id", type=str)
472+
@click.argument("job_ids", type=str, nargs=-1)
473473
@click.option("--username", type=str, hidden=True)
474474
@click.option("--verbose", default=False, is_flag=True, hidden=True)
475475
@click.pass_context
476-
def batch_download(ctx, job_id, username, verbose):
476+
def batch_download(ctx, job_ids, username, verbose):
477477
"""Download output files for a job."""
478478
config = load_config(ctx.obj["config_file"])
479479

@@ -518,17 +518,18 @@ def walk_fileshare(dir_name):
518518
share_client = ShareClient.from_connection_string(config['STORAGE']['CONNECTION_STRING'],
519519
config['STORAGE']['FILESHARE'])
520520

521-
# if the job directory exist, exit with error
522-
top_level = f"{username}/{job_id}"
523-
destination = Path(".", "outputs", top_level)
524-
if os.path.exists(destination):
525-
print("ERROR: Local directory already exists. Please move or delete.")
526-
print("Directory:", destination)
527-
return
528-
529-
print(f"Downloading {top_level}")
530-
walk_fileshare(top_level)
531-
print("\rDownload complete. ")
521+
for job_id in job_ids:
522+
# if the job directory exist, print error and continue to next job_id
523+
top_level = f"{username}/{job_id}"
524+
destination = Path(".", "outputs", top_level)
525+
if os.path.exists(destination):
526+
print("ERROR: Local directory already exists. Please move or delete.")
527+
print("Directory:", destination)
528+
continue
529+
530+
print(f"Downloading {top_level}")
531+
walk_fileshare(top_level)
532+
print("\rDownload complete. ")
532533

533534

534535
def load_config(config_file):

0 commit comments

Comments
 (0)