Add delete functionality for gcs_api_utils.
Test: gcs_api_utils_test.py
Bug: 111446669
Change-Id: I2ec45ee3590db8289c525dda523d0d157b71be40
diff --git a/utils/python/gcs/gcs_api_utils.py b/utils/python/gcs/gcs_api_utils.py
index ed95554..b6826b3 100644
--- a/utils/python/gcs/gcs_api_utils.py
+++ b/utils/python/gcs/gcs_api_utils.py
@@ -228,8 +228,7 @@
dest_dest_path: destination file path in GCS.
Returns:
- True, if the move was susccessful.
- False, if the move failed.
+ True if susccessful, False otherwise.
"""
client = storage.Client(credentials=self._credentials)
bucket = client.get_bucket(self._bucket_name)
@@ -242,3 +241,22 @@
e)
return False
return True
+
+ def DeleteFile(self, file_path):
+ """Deletes a blob, which effectively deletes its corresponding file.
+
+ Args:
+ file_path: string, path to the file to remove.
+
+ Returns:
+ True if successful, False otherwise.
+ """
+ client = storage.Client(credentials=self._credentials)
+ bucket = client.get_bucket(self._bucket_name)
+ blob = bucket.blob(file_path)
+ try:
+ blob.delete()
+ except exceptions.NotFound as e:
+ logging.exception('file delete was unsuccessful with error %s.', e)
+ return False
+ return True