From 4d4f3df1ab0b74fbee94d4b8bbed61c53cccdfa7 Mon Sep 17 00:00:00 2001 From: mrland99 Date: Sat, 12 Nov 2022 00:12:37 -0500 Subject: [PATCH] added functionality to latch test-data upload Added the option to specify destination folder to write test-data to --- latch_cli/main.py | 9 +++++++-- latch_cli/services/test_data/upload.py | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/latch_cli/main.py b/latch_cli/main.py index c2c91154..8f37dbf6 100644 --- a/latch_cli/main.py +++ b/latch_cli/main.py @@ -506,6 +506,11 @@ def test_data(ctx): @test_data.command("upload") @click.argument("src_path", nargs=1, type=click.Path(exists=True)) +@click.option( + "--s3_path", + default = None, + type=str, + help=("Destination folder path to write to on s3 (omit s3 Bucket prefix).")) @click.option( "--dont-confirm-overwrite", "-d", @@ -514,13 +519,13 @@ def test_data(ctx): type=bool, help=("Automatically overwrite any files without asking for confirmation."), ) -def test_data_upload(src_path: str, dont_confirm_overwrite: bool): +def test_data_upload(src_path: str, s3_path: str, dont_confirm_overwrite: bool): """Upload test data object.""" from latch_cli.services.test_data.upload import upload try: - s3_url = upload(src_path, dont_confirm_overwrite) + s3_url = upload(src_path, s3_path, dont_confirm_overwrite) click.secho(f"Successfully uploaded to {s3_url}", fg="green") except Exception as e: CrashReporter.report() diff --git a/latch_cli/services/test_data/upload.py b/latch_cli/services/test_data/upload.py index cf114827..2df06f6d 100644 --- a/latch_cli/services/test_data/upload.py +++ b/latch_cli/services/test_data/upload.py @@ -5,6 +5,7 @@ import boto3 import botocore import click +import os from latch_cli.services.test_data.utils import _retrieve_creds from latch_cli.utils import account_id_from_token, retrieve_or_login @@ -12,7 +13,7 @@ BUCKET = "latch-public" -def upload(src_path: str, dont_confirm_overwrite: bool = True) -> str: +def upload(src_path: str, s3_path: str = None, dont_confirm_overwrite: bool = True) -> str: """Uploads a local file/folder to a managed bucket. Args: @@ -39,7 +40,10 @@ def upload(src_path: str, dont_confirm_overwrite: bool = True) -> str: if account_id is None or account_id == "": account_id = account_id_from_token(retrieve_or_login()) - allowed_key = str((Path("test-data") / account_id).joinpath(src_path)) + if s3_path is None: + allowed_key = str((Path("test-data") / account_id).joinpath(src_path)) + else: + allowed_key = str((Path("test-data") / account_id).joinpath(s3_path)) upload_helper( Path(src_path).resolve(),