Skip to content

Commit

Permalink
added exists method for gcstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
kalessin committed Jun 7, 2024
1 parent fa636c4 commit 179e57f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shub_workflow/deliver/futils.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ def exists(path, aws_key=None, aws_secret=None, aws_token=None, **kwargs):
if check_s3_path(path):
fs = S3FileSystem(**s3_credentials(aws_key, aws_secret, aws_token, region), **kwargs)
return fs.exists(path)
if check_gcs_path(path):
return gcstorage.exists(path)
return os_exists(path)


Expand Down
10 changes: 10 additions & 0 deletions shub_workflow/deliver/gcstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,13 @@ def cp_file(src: str, dest: str):
dest_bucket = storage_client.bucket(dest_bucket_name)
bucket.copy_blob(bucket.blob(src_blob_name), dest_bucket, dest_blob_name)
_LOGGER.info(f"Copied {src} to {dest}")


def exists(src: str) -> bool:
storage_client = storage.Client()
m = _GS_FOLDER_RE.match(src)
assert m is not None, "Source must be in the format gs://<bucket>/<blob>"
src_bucket_name, src_blob_name = m.groups()

bucket = storage_client.bucket(src_bucket_name)
return bucket.blob(src_blob_name).exists()

0 comments on commit 179e57f

Please sign in to comment.