PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/django/contrib/staticfiles/utils.py

https://code.google.com/p/mango-py/
Python | 51 lines | 45 code | 2 blank | 4 comment | 5 complexity | 69ffdd137c56b08b3a2b97b33efd0b93 MD5 | raw file
 1import os
 2import fnmatch
 3from django.conf import settings
 4from django.core.exceptions import ImproperlyConfigured
 5
 6def is_ignored(path, ignore_patterns=[]):
 7    """
 8    Return True or False depending on whether the ``path`` should be
 9    ignored (if it matches any pattern in ``ignore_patterns``).
10    """
11    for pattern in ignore_patterns:
12        if fnmatch.fnmatchcase(path, pattern):
13            return True
14    return False
15
16def get_files(storage, ignore_patterns=[], location=''):
17    """
18    Recursively walk the storage directories yielding the paths
19    of all files that should be copied.
20    """
21    directories, files = storage.listdir(location)
22    for fn in files:
23        if is_ignored(fn, ignore_patterns):
24            continue
25        if location:
26            fn = os.path.join(location, fn)
27        yield fn
28    for dir in directories:
29        if is_ignored(dir, ignore_patterns):
30            continue
31        if location:
32            dir = os.path.join(location, dir)
33        for fn in get_files(storage, ignore_patterns, dir):
34            yield fn
35
36def check_settings():
37    """
38    Checks if the staticfiles settings have sane values.
39
40    """
41    if not settings.STATIC_URL:
42        raise ImproperlyConfigured(
43            "You're using the staticfiles app "
44            "without having set the required STATIC_URL setting.")
45    if settings.MEDIA_URL == settings.STATIC_URL:
46        raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
47                                   "settings must have different values")
48    if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
49            (settings.MEDIA_ROOT == settings.STATIC_ROOT)):
50        raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
51                                   "settings must have different values")