2016-03-14 04:17:05 +01:00
|
|
|
import errno
|
|
|
|
import os
|
2017-01-04 01:03:08 +01:00
|
|
|
from datetime import datetime, timedelta
|
2015-01-28 13:35:27 +01:00
|
|
|
|
2016-03-14 04:17:05 +01:00
|
|
|
from django.conf import settings
|
2012-05-16 13:21:46 +02:00
|
|
|
from django.contrib.staticfiles.storage import CachedStaticFilesStorage
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.core.files import storage
|
2016-02-09 16:00:14 +01:00
|
|
|
from django.utils import timezone
|
2011-01-08 11:03:27 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
2011-01-08 11:03:27 +01:00
|
|
|
class DummyStorage(storage.Storage):
|
|
|
|
"""
|
2017-01-04 01:22:19 +01:00
|
|
|
A storage class that implements get_modified_time() but raises
|
|
|
|
NotImplementedError for path().
|
2011-01-08 11:03:27 +01:00
|
|
|
"""
|
|
|
|
def _save(self, name, content):
|
|
|
|
return 'dummy'
|
|
|
|
|
|
|
|
def delete(self, name):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def exists(self, name):
|
|
|
|
pass
|
|
|
|
|
2016-02-09 16:00:14 +01:00
|
|
|
def get_modified_time(self, name):
|
2017-01-04 01:22:19 +01:00
|
|
|
return datetime(1970, 1, 1, tzinfo=timezone.utc)
|
2012-05-16 13:21:46 +02:00
|
|
|
|
|
|
|
|
2016-03-14 04:17:05 +01:00
|
|
|
class PathNotImplementedStorage(storage.Storage):
|
|
|
|
|
|
|
|
def _save(self, name, content):
|
|
|
|
return 'dummy'
|
|
|
|
|
|
|
|
def _path(self, name):
|
|
|
|
return os.path.join(settings.STATIC_ROOT, name)
|
|
|
|
|
|
|
|
def exists(self, name):
|
|
|
|
return os.path.exists(self._path(name))
|
|
|
|
|
|
|
|
def listdir(self, path):
|
|
|
|
path = self._path(path)
|
|
|
|
directories, files = [], []
|
|
|
|
for entry in os.listdir(path):
|
|
|
|
if os.path.isdir(os.path.join(path, entry)):
|
|
|
|
directories.append(entry)
|
|
|
|
else:
|
|
|
|
files.append(entry)
|
|
|
|
return directories, files
|
|
|
|
|
|
|
|
def delete(self, name):
|
|
|
|
name = self._path(name)
|
2016-05-26 17:36:00 +02:00
|
|
|
try:
|
|
|
|
os.remove(name)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno != errno.ENOENT:
|
|
|
|
raise
|
2016-03-14 04:17:05 +01:00
|
|
|
|
|
|
|
def path(self, name):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2017-01-04 01:03:08 +01:00
|
|
|
class NeverCopyRemoteStorage(PathNotImplementedStorage):
|
|
|
|
"""
|
|
|
|
Return a future modified time for all files so that nothing is collected.
|
|
|
|
"""
|
|
|
|
def get_modified_time(self, name):
|
|
|
|
return datetime.now() + timedelta(days=30)
|
|
|
|
|
|
|
|
|
2016-12-19 17:05:48 +01:00
|
|
|
class QueryStringStorage(storage.Storage):
|
|
|
|
def url(self, path):
|
|
|
|
return path + '?a=b&c=d'
|
|
|
|
|
|
|
|
|
2012-05-16 13:21:46 +02:00
|
|
|
class SimpleCachedStaticFilesStorage(CachedStaticFilesStorage):
|
|
|
|
|
|
|
|
def file_hash(self, name, content=None):
|
|
|
|
return 'deploy12345'
|
2016-02-27 21:30:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ExtraPatternsCachedStaticFilesStorage(CachedStaticFilesStorage):
|
|
|
|
"""
|
|
|
|
A storage class to test pattern substitutions with more than one pattern
|
|
|
|
entry. The added pattern rewrites strings like "url(...)" to JS_URL("...").
|
|
|
|
"""
|
|
|
|
patterns = tuple(CachedStaticFilesStorage.patterns) + (
|
|
|
|
(
|
|
|
|
"*.js", (
|
|
|
|
(r"""(url\(['"]{0,1}\s*(.*?)["']{0,1}\))""", 'JS_URL("%s")'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|