From e9e364eedda9e11aa65df690bee2dc1b83c4843d Mon Sep 17 00:00:00 2001 From: Matthew Tretter Date: Sun, 12 Feb 2012 16:18:34 -0500 Subject: [PATCH] Rename cache_state_backend to image_cache_backend Related names (like the package and class names) have also been updated. --- .../{cachestate/__init__.py => imagecache.py} | 30 +++++++++---------- imagekit/models.py | 22 +++++++------- imagekit/settings.py | 6 ++-- 3 files changed, 29 insertions(+), 29 deletions(-) rename imagekit/{cachestate/__init__.py => imagecache.py} (67%) diff --git a/imagekit/cachestate/__init__.py b/imagekit/imagecache.py similarity index 67% rename from imagekit/cachestate/__init__.py rename to imagekit/imagecache.py index e9ee56c..3784957 100644 --- a/imagekit/cachestate/__init__.py +++ b/imagekit/imagecache.py @@ -2,9 +2,9 @@ from django.core.exceptions import ImproperlyConfigured from django.utils.importlib import import_module -class PessimisticCacheStateBackend(object): +class PessimisticImageCacheBackend(object): """ - A very safe cache state backend. Guarantees that files will always be + A very safe image cache backend. Guarantees that files will always be available, but at the cost of hitting the storage backend. """ @@ -30,7 +30,7 @@ class PessimisticCacheStateBackend(object): file.delete(save=False) -class NonValidatingCacheStateBackend(object): +class NonValidatingImageCacheBackend(object): """ A backend that is super optimistic about the existence of spec files. It will hit your file storage much less frequently than the pessimistic @@ -41,7 +41,7 @@ class NonValidatingCacheStateBackend(object): def validate(self, file): """ - NonValidatingCacheStateBackend has faith, so validate's a no-op. + NonValidatingImageCacheBackend has faith, so validate's a no-op. """ pass @@ -57,31 +57,31 @@ class NonValidatingCacheStateBackend(object): file.delete(save=False) -_default_cache_state_backend = None +_default_image_cache_backend = None -def get_default_cache_state_backend(): +def get_default_image_cache_backend(): """ - Get the default cache state backend. Uses the same method as + Get the default image cache backend. Uses the same method as django.core.file.storage.get_storage_class """ - global _default_cache_state_backend - if not _default_cache_state_backend: - from ..settings import DEFAULT_CACHE_STATE_BACKEND as import_path + global _default_image_cache_backend + if not _default_image_cache_backend: + from .settings import DEFAULT_IMAGE_CACHE_BACKEND as import_path try: dot = import_path.rindex('.') except ValueError: - raise ImproperlyConfigured("%s isn't a cache state backend module." % \ + raise ImproperlyConfigured("%s isn't an image cache backend module." % \ import_path) module, classname = import_path[:dot], import_path[dot+1:] try: mod = import_module(module) except ImportError, e: - raise ImproperlyConfigured('Error importing cache state module %s: "%s"' % (module, e)) + raise ImproperlyConfigured('Error importing image cache backend module %s: "%s"' % (module, e)) try: cls = getattr(mod, classname) - _default_cache_state_backend = cls() + _default_image_cache_backend = cls() except AttributeError: - raise ImproperlyConfigured('Cache state backend module "%s" does not define a "%s" class.' % (module, classname)) - return _default_cache_state_backend + raise ImproperlyConfigured('Image cache backend module "%s" does not define a "%s" class.' % (module, classname)) + return _default_image_cache_backend diff --git a/imagekit/models.py b/imagekit/models.py index a6fadfb..1ba7405 100755 --- a/imagekit/models.py +++ b/imagekit/models.py @@ -12,7 +12,7 @@ from imagekit.utils import img_to_fobj, open_image, \ format_to_extension, extension_to_format, UnknownFormatError, \ UnknownExtensionError from imagekit.processors import ProcessorPipeline, AutoConvert -from .cachestate import get_default_cache_state_backend +from .imagecache import get_default_image_cache_backend class _ImageSpecMixin(object): @@ -64,7 +64,7 @@ class ImageSpec(_ImageSpecMixin): def __init__(self, processors=None, format=None, options={}, image_field=None, pre_cache=None, storage=None, cache_to=None, - autoconvert=True, cache_state_backend=None): + autoconvert=True, image_cache_backend=None): """ :param processors: A list of processors to run on the original image. :param format: The format of the output file. If not provided, @@ -96,9 +96,9 @@ class ImageSpec(_ImageSpecMixin): this extension, it's only a recommendation. :param autoconvert: Specifies whether the AutoConvert processor should be run before saving. - :param cache_state_backend: An object responsible for managing the state + :param image_cache_backend: An object responsible for managing the state of cached files. Defaults to an instance of - IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND + IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND """ @@ -112,8 +112,8 @@ class ImageSpec(_ImageSpecMixin): self.pre_cache = pre_cache self.storage = storage self.cache_to = cache_to - self.cache_state_backend = cache_state_backend or \ - get_default_cache_state_backend() + self.image_cache_backend = image_cache_backend or \ + get_default_image_cache_backend() def contribute_to_class(self, cls, name): setattr(cls, name, _ImageSpecDescriptor(self, name)) @@ -133,9 +133,9 @@ class ImageSpec(_ImageSpecMixin): post_delete.connect(ImageSpec._post_delete_receiver, sender=cls, dispatch_uid=uid) - # Register the field with the cache_state_backend + # Register the field with the image_cache_backend try: - self.cache_state_backend.register_field(cls, self, name) + self.image_cache_backend.register_field(cls, self, name) except AttributeError: pass @@ -264,13 +264,13 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile): file = property(_get_file, ImageFieldFile._set_file, ImageFieldFile._del_file) def clear(self): - return self.field.cache_state_backend.clear(self) + return self.field.image_cache_backend.clear(self) def invalidate(self): - return self.field.cache_state_backend.invalidate(self) + return self.field.image_cache_backend.invalidate(self) def validate(self): - return self.field.cache_state_backend.validate(self) + return self.field.image_cache_backend.validate(self) def generate(self, save=True): """ diff --git a/imagekit/settings.py b/imagekit/settings.py index d02f718..d84030d 100644 --- a/imagekit/settings.py +++ b/imagekit/settings.py @@ -1,5 +1,5 @@ from django.conf import settings -DEFAULT_CACHE_STATE_BACKEND = getattr(settings, - 'IMAGEKIT_DEFAULT_CACHE_STATE_BACKEND', - 'imagekit.cachestate.PessimisticCacheStateBackend') +DEFAULT_IMAGE_CACHE_BACKEND = getattr(settings, + 'IMAGEKIT_DEFAULT_IMAGE_CACHE_BACKEND', + 'imagekit.imagecache.PessimisticImageCacheBackend')