From bcc584ca2db058c7b9b49ada167324e12f1d9c26 Mon Sep 17 00:00:00 2001 From: Natalie Weires Date: Tue, 6 Feb 2024 11:33:55 -0500 Subject: [PATCH] Add check for existing output files during validation (#65) --- buildstockbatch/gcp/gcp.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buildstockbatch/gcp/gcp.py b/buildstockbatch/gcp/gcp.py index 39f511bf..aac22695 100644 --- a/buildstockbatch/gcp/gcp.py +++ b/buildstockbatch/gcp/gcp.py @@ -209,9 +209,18 @@ def validate_gcp_args(project_file): # Check that GCP bucket exists bucket = cfg["gcp"]["gcs"]["bucket"] + output_dir = os.path.join(cfg["gcp"]["gcs"]["prefix"], "results", "simulation_output") storage_client = storage.Client(project=gcp_project) assert storage_client.bucket(bucket).exists(), f"GCS bucket {bucket} does not exist in project {gcp_project}" + blobs = storage_client.bucket(bucket).list_blobs(prefix=os.path.join(output_dir, "results_job")) + for blob in blobs: + raise ValidationError( + f"Output files are already present in bucket {bucket}! For example, {blob.name} exists. " + "Remove these files or chose a different file prefix. " + f"https://console.cloud.google.com/storage/browser/{bucket}/{output_dir}" + ) + # Check that artifact registry repository exists repo = cfg["gcp"]["artifact_registry"]["repository"] ar_client = artifactregistry_v1.ArtifactRegistryClient()