2011-01-02 09:32:17 +08:00
|
|
|
import os
|
2010-10-20 09:33:24 +08:00
|
|
|
import fnmatch
|
2010-11-12 05:43:49 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2010-10-20 09:33:24 +08:00
|
|
|
|
2011-08-11 22:07:39 +08:00
|
|
|
def matches_patterns(path, patterns=None):
|
2010-10-20 09:33:24 +08:00
|
|
|
"""
|
2011-01-16 07:38:00 +08:00
|
|
|
Return True or False depending on whether the ``path`` should be
|
|
|
|
ignored (if it matches any pattern in ``ignore_patterns``).
|
2010-10-20 09:33:24 +08:00
|
|
|
"""
|
2011-08-11 22:07:39 +08:00
|
|
|
if patterns is None:
|
|
|
|
patterns = []
|
|
|
|
for pattern in patterns:
|
2011-01-16 07:38:00 +08:00
|
|
|
if fnmatch.fnmatchcase(path, pattern):
|
|
|
|
return True
|
|
|
|
return False
|
2010-10-20 09:33:24 +08:00
|
|
|
|
2011-08-11 22:07:39 +08:00
|
|
|
def get_files(storage, ignore_patterns=None, location=''):
|
2011-01-16 07:38:00 +08:00
|
|
|
"""
|
|
|
|
Recursively walk the storage directories yielding the paths
|
|
|
|
of all files that should be copied.
|
|
|
|
"""
|
2011-08-11 22:07:39 +08:00
|
|
|
if ignore_patterns is None:
|
|
|
|
ignore_patterns = []
|
2010-10-20 09:33:24 +08:00
|
|
|
directories, files = storage.listdir(location)
|
2011-01-16 07:38:00 +08:00
|
|
|
for fn in files:
|
2011-08-11 22:07:39 +08:00
|
|
|
if matches_patterns(fn, ignore_patterns):
|
2011-01-16 07:38:00 +08:00
|
|
|
continue
|
|
|
|
if location:
|
|
|
|
fn = os.path.join(location, fn)
|
|
|
|
yield fn
|
2010-10-20 09:33:24 +08:00
|
|
|
for dir in directories:
|
2011-08-11 22:07:39 +08:00
|
|
|
if matches_patterns(dir, ignore_patterns):
|
2010-10-20 09:33:24 +08:00
|
|
|
continue
|
|
|
|
if location:
|
2011-01-02 09:32:17 +08:00
|
|
|
dir = os.path.join(location, dir)
|
2011-01-16 07:38:00 +08:00
|
|
|
for fn in get_files(storage, ignore_patterns, dir):
|
|
|
|
yield fn
|
2010-11-12 05:43:49 +08:00
|
|
|
|
2011-08-15 02:15:04 +08:00
|
|
|
def check_settings(base_url=None):
|
2010-11-12 05:43:49 +08:00
|
|
|
"""
|
2011-02-01 22:57:10 +08:00
|
|
|
Checks if the staticfiles settings have sane values.
|
|
|
|
|
2010-11-12 05:43:49 +08:00
|
|
|
"""
|
2011-08-15 16:22:22 +08:00
|
|
|
if base_url is None:
|
2011-08-15 02:15:04 +08:00
|
|
|
base_url = settings.STATIC_URL
|
|
|
|
if not base_url:
|
2011-02-01 22:57:10 +08:00
|
|
|
raise ImproperlyConfigured(
|
|
|
|
"You're using the staticfiles app "
|
|
|
|
"without having set the required STATIC_URL setting.")
|
2011-08-15 02:15:04 +08:00
|
|
|
if settings.MEDIA_URL == base_url:
|
2010-11-17 23:36:26 +08:00
|
|
|
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
|
|
|
|
"settings must have different values")
|
|
|
|
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
|
|
|
|
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
|
|
|
|
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
|
|
|
|
"settings must have different values")
|