Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CachedStaticSwiftStorage and ManifestStaticSwiftStorage #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leo-naeka
Copy link
Contributor

This pull request adds both CachedStaticSwiftStorage and ManifestStaticSwiftStorage, based on django.contrib.staticfiles equivalents : CachedStaticFilesStorage and ManifestStaticFilesStorage.

There's not much code added, it mainly relies on staticfiles' mixins, but there's 2 notable changes:

  • It normalizes the path, because some path may be relative and swift evaluates paths as a whole, nor like a filesystem where myapp/css/../img/background.png is myapp/img/background.png.
  • The ManifestStaticSwiftStorage overrides read_manifest to handle ClientException which indicates that the manifest doesn't exist (like IOError on filesystem).

try:
super(ManifestStaticSwiftStorage, self).read_manifest()
except swiftclient.ClientException:
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of silently swallowing the exception I would suggest to wrap it in IOError instead, like this (and maybe in the StaticSwiftStorage._open method instead of ManifestStaticSwiftStorage.read_manifest ):

except swiftclient.exceptions.ClientException as e:
    # django.contrib.staticfiles.storage.ManifestFilesMixin#read_manifest
    # When manifest file doesn't exist, the raised error must be an instance of IOError.
    raise IOError(e)

If you want to ignore the missing manifest error, it's possible by setting ManifestStaticSwiftStorage.manifest_strict property to False. So something like this will allow to make the ignoring of the error configurable:

class ManifestStaticSwiftStorage(ManifestFilesMixin, StaticSwiftStorage):
    manifest_strict = setting('SWIFT_MANIFEST_STRICT', True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants