Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 2.2KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import fnmatch
  2. import os
  3. from django.conf import settings
  4. from django.core.exceptions import ImproperlyConfigured
  5. def matches_patterns(path, 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. return any(fnmatch.fnmatchcase(path, pattern) for pattern in patterns)
  11. def get_files(storage, ignore_patterns=None, location=""):
  12. """
  13. Recursively walk the storage directories yielding the paths
  14. of all files that should be copied.
  15. """
  16. if ignore_patterns is None:
  17. ignore_patterns = []
  18. directories, files = storage.listdir(location)
  19. for fn in files:
  20. # Match only the basename.
  21. if matches_patterns(fn, ignore_patterns):
  22. continue
  23. if location:
  24. fn = os.path.join(location, fn)
  25. # Match the full file path.
  26. if matches_patterns(fn, ignore_patterns):
  27. continue
  28. yield fn
  29. for dir in directories:
  30. if matches_patterns(dir, ignore_patterns):
  31. continue
  32. if location:
  33. dir = os.path.join(location, dir)
  34. yield from get_files(storage, ignore_patterns, dir)
  35. def check_settings(base_url=None):
  36. """
  37. Check if the staticfiles settings have sane values.
  38. """
  39. if base_url is None:
  40. base_url = settings.STATIC_URL
  41. if not base_url:
  42. raise ImproperlyConfigured(
  43. "You're using the staticfiles app "
  44. "without having set the required STATIC_URL setting."
  45. )
  46. if settings.MEDIA_URL == base_url:
  47. raise ImproperlyConfigured(
  48. "The MEDIA_URL and STATIC_URL settings must have different values"
  49. )
  50. if (
  51. settings.DEBUG
  52. and settings.MEDIA_URL
  53. and settings.STATIC_URL
  54. and settings.MEDIA_URL.startswith(settings.STATIC_URL)
  55. ):
  56. raise ImproperlyConfigured(
  57. "runserver can't serve media if MEDIA_URL is within STATIC_URL."
  58. )
  59. if (settings.MEDIA_ROOT and settings.STATIC_ROOT) and (
  60. settings.MEDIA_ROOT == settings.STATIC_ROOT
  61. ):
  62. raise ImproperlyConfigured(
  63. "The MEDIA_ROOT and STATIC_ROOT settings must have different values"
  64. )