diff --git a/compressor/management/commands/mtime_cache.py b/compressor/management/commands/mtime_cache.py index 8d520a2..0f778a3 100644 --- a/compressor/management/commands/mtime_cache.py +++ b/compressor/management/commands/mtime_cache.py @@ -6,7 +6,7 @@ from django.core.management.base import NoArgsCommand, CommandError from compressor.cache import cache from compressor.conf import settings -from compressor.utils import get_mtime, get_mtime_cachekey +from compressor.utils import get_mtime, get_mtime_cachekey, walk class Command(NoArgsCommand): help = "Add or remove all mtime values from the cache" @@ -57,7 +57,7 @@ class Command(NoArgsCommand): files_to_add = set() keys_to_delete = set() - for root, dirs, files in os.walk(settings.MEDIA_ROOT, followlinks=options['follow_links']): + for root, dirs, files in walk(settings.MEDIA_ROOT, followlinks=options['follow_links']): for dir_ in dirs: if self.is_ignored(dir_): dirs.remove(dir_) diff --git a/compressor/utils.py b/compressor/utils.py index f11545e..21e97f4 100644 --- a/compressor/utils.py +++ b/compressor/utils.py @@ -61,3 +61,18 @@ def get_mod_func(callback): except ValueError: return callback, '' return callback[:dot], callback[dot+1:] + + +def walk(root, topdown=True, onerror=None, followlinks=False): + """ + A version of os.walk that can follow symlinks for Python < 2.6 + """ + for dirpath, dirnames, filenames in os.walk(root, topdown, onerror): + yield (dirpath, dirnames, filenames) + if followlinks: + for d in dirnames: + p = os.path.join(dirpath, d) + if os.path.islink(p): + for link_dirpath, link_dirnames, link_filenames in walk(p): + yield (link_dirpath, link_dirnames, link_filenames) +