Ticket #15562: #15562-include_patterns-1.4.diff

File #15562-include_patterns-1.4.diff, 5.0 KB (added by German M. Bravo, 12 years ago)

Patch updated for 1.4

  • django/contrib/staticfiles/finders.py

    diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
    index 7b4c7c8..30986e9 100644
    class BaseFinder(object):  
    2828        """
    2929        raise NotImplementedError()
    3030
    31     def list(self, ignore_patterns):
     31    def list(self, ignore_patterns, include_patterns):
    3232        """
    3333        Given an optional list of paths to ignore, this should return
    3434        a two item iterable consisting of the relative path and storage
    class FileSystemFinder(BaseFinder):  
    9696        if os.path.exists(path):
    9797            return path
    9898
    99     def list(self, ignore_patterns):
     99    def list(self, ignore_patterns, include_patterns):
    100100        """
    101101        List all files in all locations.
    102102        """
    103103        for prefix, root in self.locations:
    104104            storage = self.storages[root]
    105             for path in utils.get_files(storage, ignore_patterns):
     105            for path in utils.get_files(storage, ignore_patterns, include_patterns):
    106106                yield path, storage
    107107
    108108
    class AppDirectoriesFinder(BaseFinder):  
    128128                    self.apps.append(app)
    129129        super(AppDirectoriesFinder, self).__init__(*args, **kwargs)
    130130
    131     def list(self, ignore_patterns):
     131    def list(self, ignore_patterns, include_patterns):
    132132        """
    133133        List all files in all app storages.
    134134        """
    135135        for storage in self.storages.itervalues():
    136136            if storage.exists(''):  # check if storage location exists
    137                 for path in utils.get_files(storage, ignore_patterns):
     137                for path in utils.get_files(storage, ignore_patterns, include_patterns):
    138138                    yield path, storage
    139139
    140140    def find(self, path, all=False):
    class BaseStorageFinder(BaseFinder):  
    203203                return match
    204204        return []
    205205
    206     def list(self, ignore_patterns):
     206    def list(self, ignore_patterns, include_patterns):
    207207        """
    208208        List all files of the storage.
    209209        """
    210         for path in utils.get_files(self.storage, ignore_patterns):
     210        for path in utils.get_files(self.storage, ignore_patterns, include_patterns):
    211211            yield path, self.storage
    212212
    213213
  • django/contrib/staticfiles/management/commands/collectstatic.py

    diff --git a/django/contrib/staticfiles/management/commands/collectstatic.py b/django/contrib/staticfiles/management/commands/collectstatic.py
    index 18f8893..9f6005c 100644
    Type 'yes' to continue, or 'no' to cancel: """  
    116116
    117117        found_files = []
    118118        for finder in finders.get_finders():
    119             for path, storage in finder.list(self.ignore_patterns):
     119            for path, storage in finder.list(self.ignore_patterns, None):
    120120                # Prefix the relative path if the source storage contains it
    121121                if getattr(storage, 'prefix', None):
    122122                    prefixed_path = os.path.join(storage.prefix, path)
  • django/contrib/staticfiles/utils.py

    diff --git a/django/contrib/staticfiles/utils.py b/django/contrib/staticfiles/utils.py
    index f500ed6..21e979b 100644
    from django.core.exceptions import ImproperlyConfigured  
    66def matches_patterns(path, patterns=None):
    77    """
    88    Return True or False depending on whether the ``path`` should be
    9     ignored (if it matches any pattern in ``ignore_patterns``).
     9    ignored (if it matches any pattern in ``patterns``).
    1010    """
    1111    if patterns is None:
    1212        patterns = []
    def matches_patterns(path, patterns=None):  
    1515            return True
    1616    return False
    1717
    18 def get_files(storage, ignore_patterns=None, location=''):
     18def get_files(storage, ignore_patterns=None, include_patterns=None, location=''):
    1919    """
    2020    Recursively walk the storage directories yielding the paths
    2121    of all files that should be copied.
    2222    """
    2323    if ignore_patterns is None:
    2424        ignore_patterns = []
     25    if include_patterns is None:
     26        include_patterns = []
    2527    directories, files = storage.listdir(location)
    2628    for fn in files:
     29        if location:
     30            fn = os.path.normpath(os.path.join(location, fn)).replace('\\', '/')
    2731        if matches_patterns(fn, ignore_patterns):
    2832            continue
    29         if location:
    30             fn = os.path.join(location, fn)
     33        if include_patterns and not matches_patterns(fn, include_patterns):
     34            continue
    3135        yield fn
    3236    for dir in directories:
     37        if location:
     38            dir = os.path.normpath(os.path.join(location, dir)).replace('\\', '/')
    3339        if matches_patterns(dir, ignore_patterns):
    3440            continue
    35         if location:
    36             dir = os.path.join(location, dir)
    37         for fn in get_files(storage, ignore_patterns, dir):
     41        for fn in get_files(storage, ignore_patterns, include_patterns, dir):
    3842            yield fn
    3943
    4044def check_settings(base_url=None):
Back to Top