Skip to content

Instantly share code, notes, and snippets.

@sid22
Created May 8, 2020 18:01
Show Gist options
  • Save sid22/86232cb9bbb9d0af6637c3dfde13dd74 to your computer and use it in GitHub Desktop.
Save sid22/86232cb9bbb9d0af6637c3dfde13dd74 to your computer and use it in GitHub Desktop.
class CustomManifestS3Boto3Storage(ManifestFilesMixin, S3Boto3Storage):
# FIXME this seems to be a bug in ManifestFilesMixin with S3Boto3Storages
# ManifestFilesMixin is expecting a FileNotFound error but
# S3Boto3Storages is throwing an IOError
manifest_location = os.path.abspath(
settings.BASE_DIR
)
manifest_storage = FileSystemStorage(location=manifest_location)
def read_manifest(self):
try:
with self.manifest_storage.open(self.manifest_name) as manifest:
return manifest.read().decode("utf-8")
except IOError:
return None
def save_manifest(self):
payload = {"paths": self.hashed_files, "version": self.manifest_version}
if self.manifest_storage.exists(self.manifest_name):
self.manifest_storage.delete(self.manifest_name)
contents = json.dumps(payload).encode("utf-8")
self.manifest_storage._save(self.manifest_name, ContentFile(contents))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment