Added a custom walk function (like os.walk) that supports symlinks for Python<2.6 compatibility.
This commit is contained in:
@@ -6,7 +6,7 @@ from django.core.management.base import NoArgsCommand, CommandError
|
|||||||
|
|
||||||
from compressor.cache import cache
|
from compressor.cache import cache
|
||||||
from compressor.conf import settings
|
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):
|
class Command(NoArgsCommand):
|
||||||
help = "Add or remove all mtime values from the cache"
|
help = "Add or remove all mtime values from the cache"
|
||||||
@@ -57,7 +57,7 @@ class Command(NoArgsCommand):
|
|||||||
files_to_add = set()
|
files_to_add = set()
|
||||||
keys_to_delete = 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:
|
for dir_ in dirs:
|
||||||
if self.is_ignored(dir_):
|
if self.is_ignored(dir_):
|
||||||
dirs.remove(dir_)
|
dirs.remove(dir_)
|
||||||
|
@@ -61,3 +61,18 @@ def get_mod_func(callback):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
return callback, ''
|
return callback, ''
|
||||||
return callback[:dot], callback[dot+1:]
|
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)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user