2016-03-14 03:17:05 +00:00
|
|
|
import os
|
2017-01-04 00:03:08 +00:00
|
|
|
from datetime import datetime, timedelta
|
2015-01-28 12:35:27 +00:00
|
|
|
|
2016-03-14 03:17:05 +00:00
|
|
|
from django.conf import settings
|
2018-10-27 14:30:28 +00:00
|
|
|
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.core.files import storage
|
2016-02-09 15:00:14 +00:00
|
|
|
from django.utils import timezone
|
2011-01-08 10:03:27 +00:00
|
|
|
|
2013-11-02 21:34:05 +00:00
|
|
|
|
2011-01-08 10:03:27 +00:00
|
|
|
class DummyStorage(storage.Storage):
|
|
|
|
"""
|
2017-01-04 00:22:19 +00:00
|
|
|
A storage class that implements get_modified_time() but raises
|
|
|
|
NotImplementedError for path().
|
2011-01-08 10:03:27 +00:00
|
|
|
"""
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2011-01-08 10:03:27 +00:00
|
|
|
def _save(self, name, content):
|
2022-02-03 19:24:19 +00:00
|
|
|
return "dummy"
|
2011-01-08 10:03:27 +00:00
|
|
|
|
|
|
|
def delete(self, name):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def exists(self, name):
|
|
|
|
pass
|
|
|
|
|
2016-02-09 15:00:14 +00:00
|
|
|
def get_modified_time(self, name):
|
2017-01-04 00:22:19 +00:00
|
|
|
return datetime(1970, 1, 1, tzinfo=timezone.utc)
|
2012-05-16 11:21:46 +00:00
|
|
|
|
|
|
|
|
2016-03-14 03:17:05 +00:00
|
|
|
class PathNotImplementedStorage(storage.Storage):
|
|
|
|
def _save(self, name, content):
|
2022-02-03 19:24:19 +00:00
|
|
|
return "dummy"
|
2016-03-14 03:17:05 +00:00
|
|
|
|
|
|
|
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 = [], []
|
2021-06-06 06:56:34 +00:00
|
|
|
with os.scandir(path) as entries:
|
|
|
|
for entry in entries:
|
|
|
|
if entry.is_dir():
|
|
|
|
directories.append(entry.name)
|
|
|
|
else:
|
|
|
|
files.append(entry.name)
|
2016-03-14 03:17:05 +00:00
|
|
|
return directories, files
|
|
|
|
|
|
|
|
def delete(self, name):
|
|
|
|
name = self._path(name)
|
2017-09-07 12:16:21 +00:00
|
|
|
try:
|
2016-05-26 15:36:00 +00:00
|
|
|
os.remove(name)
|
2017-09-07 12:16:21 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
2016-03-14 03:17:05 +00:00
|
|
|
|
|
|
|
def path(self, name):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
2017-01-04 00:03:08 +00:00
|
|
|
class NeverCopyRemoteStorage(PathNotImplementedStorage):
|
|
|
|
"""
|
|
|
|
Return a future modified time for all files so that nothing is collected.
|
|
|
|
"""
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2017-01-04 00:03:08 +00:00
|
|
|
def get_modified_time(self, name):
|
|
|
|
return datetime.now() + timedelta(days=30)
|
|
|
|
|
|
|
|
|
2016-12-19 16:05:48 +00:00
|
|
|
class QueryStringStorage(storage.Storage):
|
|
|
|
def url(self, path):
|
2022-02-03 19:24:19 +00:00
|
|
|
return path + "?a=b&c=d"
|
2016-12-19 16:05:48 +00:00
|
|
|
|
|
|
|
|
2018-10-27 14:30:28 +00:00
|
|
|
class SimpleStorage(ManifestStaticFilesStorage):
|
2012-05-16 11:21:46 +00:00
|
|
|
def file_hash(self, name, content=None):
|
2022-02-03 19:24:19 +00:00
|
|
|
return "deploy12345"
|
2016-02-27 20:30:07 +00:00
|
|
|
|
|
|
|
|
2018-10-27 14:30:28 +00:00
|
|
|
class ExtraPatternsStorage(ManifestStaticFilesStorage):
|
2016-02-27 20:30:07 +00:00
|
|
|
"""
|
|
|
|
A storage class to test pattern substitutions with more than one pattern
|
|
|
|
entry. The added pattern rewrites strings like "url(...)" to JS_URL("...").
|
|
|
|
"""
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2018-10-27 14:30:28 +00:00
|
|
|
patterns = tuple(ManifestStaticFilesStorage.patterns) + (
|
2016-02-27 20:30:07 +00:00
|
|
|
(
|
2022-02-03 19:24:19 +00:00
|
|
|
"*.js",
|
|
|
|
(
|
2021-05-31 07:05:36 +00:00
|
|
|
(
|
|
|
|
r"""(?P<matched>url\(['"]{0,1}\s*(?P<url>.*?)["']{0,1}\))""",
|
|
|
|
'JS_URL("%(url)s")',
|
|
|
|
),
|
2016-02-27 20:30:07 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2020-04-26 20:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NoneHashStorage(ManifestStaticFilesStorage):
|
|
|
|
def file_hash(self, name, content=None):
|
|
|
|
return None
|
2021-06-05 12:30:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NoPostProcessReplacedPathStorage(ManifestStaticFilesStorage):
|
|
|
|
max_post_process_passes = 0
|