Ticket #15562: #15562-include_patterns.diff

File #15562-include_patterns.diff, 4.4 KB (added by German M. Bravo, 14 years ago)
  • django/contrib/staticfiles/finders.py

     
    9595        if os.path.exists(path):
    9696            return path
    9797
    98     def list(self, ignore_patterns):
     98    def list(self, ignore_patterns, include_patterns):
    9999        """
    100100        List all files in all locations.
    101101        """
    102102        for prefix, root in self.locations:
    103103            storage = self.storages[root]
    104             for path in utils.get_files(storage, ignore_patterns):
     104            for path in utils.get_files(storage, ignore_patterns, include_patterns):
    105105                yield path, storage
    106106
    107107
     
    127127                    self.apps.append(app)
    128128        super(AppDirectoriesFinder, self).__init__(*args, **kwargs)
    129129
    130     def list(self, ignore_patterns):
     130    def list(self, ignore_patterns, include_patterns):
    131131        """
    132132        List all files in all app storages.
    133133        """
    134134        for storage in self.storages.itervalues():
    135135            if storage.exists(''): # check if storage location exists
    136                 for path in utils.get_files(storage, ignore_patterns):
     136                for path in utils.get_files(storage, ignore_patterns, include_patterns):
    137137                    yield path, storage
    138138
    139139    def find(self, path, all=False):
     
    202202                return match
    203203        return []
    204204
    205     def list(self, ignore_patterns):
     205    def list(self, ignore_patterns, include_patterns):
    206206        """
    207207        List all files of the storage.
    208208        """
    209         for path in utils.get_files(self.storage, ignore_patterns):
     209        for path in utils.get_files(self.storage, ignore_patterns, include_patterns):
    210210            yield path, self.storage
    211211
    212212class DefaultStorageFinder(BaseStorageFinder):
  • django/contrib/staticfiles/utils.py

     
    33from django.conf import settings
    44from django.core.exceptions import ImproperlyConfigured
    55
    6 def is_ignored(path, ignore_patterns=[]):
     6def matches(path, patterns=[]):
    77    """
    8     Return True or False depending on whether the ``path`` should be
    9     ignored (if it matches any pattern in ``ignore_patterns``).
     8    Return True or False depending on whether the ``path`` matches any pattern
     9    in ``patterns``.
    1010    """
    11     for pattern in ignore_patterns:
     11    for pattern in patterns:
    1212        if fnmatch.fnmatchcase(path, pattern):
    1313            return True
    1414    return False
    1515
    16 def get_files(storage, ignore_patterns=[], location=''):
     16def is_ignored(path, ignore_patterns=[]):
     17    return matches(path, ignore_patterns)
     18
     19def is_included(path, include_patterns=[]):
     20    if not include_patterns:
     21        return True
     22    return matches(path, include_patterns)
     23
     24def get_files(storage, ignore_patterns=[], include_patterns=[], location=''):
    1725    """
    1826    Recursively walk the storage directories yielding the paths
    1927    of all files that should be copied.
    2028    """
    2129    directories, files = storage.listdir(location)
    2230    for fn in files:
     31        if location:
     32            fn = os.path.normpath(os.path.join(location, fn))
    2333        if is_ignored(fn, ignore_patterns):
    2434            continue
    25         if location:
    26             fn = os.path.join(location, fn)
     35        if not is_included(fn, include_patterns):
     36            continue
    2737        yield fn
    2838    for dir in directories:
     39        if location:
     40            dir = os.path.normpath(os.path.join(location, dir))
    2941        if is_ignored(dir, ignore_patterns):
    3042            continue
    31         if location:
    32             dir = os.path.join(location, dir)
    33         for fn in get_files(storage, ignore_patterns, dir):
     43        for fn in get_files(storage, ignore_patterns, include_patterns, dir):
    3444            yield fn
    3545
    3646def check_settings():
  • django/contrib/staticfiles/collectstatic.py

     
    7777                raise CommandError("Collecting static files cancelled.")
    7878
    7979        for finder in finders.get_finders():
    80             for path, storage in finder.list(ignore_patterns):
     80            for path, storage in finder.list(ignore_patterns, []):
    8181                # Prefix the relative path if the source storage contains it
    8282                if getattr(storage, 'prefix', None):
    8383                    prefixed_path = os.path.join(storage.prefix, path)
Back to Top