Storage backends: added exists() method

This method returns whether the file exists on the backend.
This commit is contained in:
2017-06-06 15:33:05 +02:00
parent d6506b6402
commit 2ad8c5186c
4 changed files with 29 additions and 1 deletions

View File

@@ -149,5 +149,9 @@ class Blob(metaclass=abc.ABCMeta):
Only performs an actual action on backends that support temporary links.
"""
@abc.abstractmethod
def exists(self) -> bool:
"""Returns True iff the file exists on the storage backend."""
Bl = typing.TypeVar('Bl', bound=Blob)

View File

@@ -180,6 +180,11 @@ class GoogleCloudStorageBlob(Blob):
def make_public(self):
self.gblob.make_public()
def exists(self) -> bool:
# Reload to get the actual file properties from Google.
self.gblob.reload()
return self.gblob.exists()
def update_file_name(node):
"""Assign to the CGS blob the same name of the asset node. This way when

View File

@@ -100,3 +100,6 @@ class LocalBlob(Blob):
def make_public(self):
# No-op on this storage backend.
pass
def exists(self) -> bool:
return self.abspath().exists()