PageRenderTime 38ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/django/contrib/staticfiles/utils.py

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