Ticket #15562: #15562-include_patterns.diff
File #15562-include_patterns.diff, 4.4 KB (added by , 14 years ago) |
---|
-
django/contrib/staticfiles/finders.py
95 95 if os.path.exists(path): 96 96 return path 97 97 98 def list(self, ignore_patterns ):98 def list(self, ignore_patterns, include_patterns): 99 99 """ 100 100 List all files in all locations. 101 101 """ 102 102 for prefix, root in self.locations: 103 103 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): 105 105 yield path, storage 106 106 107 107 … … 127 127 self.apps.append(app) 128 128 super(AppDirectoriesFinder, self).__init__(*args, **kwargs) 129 129 130 def list(self, ignore_patterns ):130 def list(self, ignore_patterns, include_patterns): 131 131 """ 132 132 List all files in all app storages. 133 133 """ 134 134 for storage in self.storages.itervalues(): 135 135 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): 137 137 yield path, storage 138 138 139 139 def find(self, path, all=False): … … 202 202 return match 203 203 return [] 204 204 205 def list(self, ignore_patterns ):205 def list(self, ignore_patterns, include_patterns): 206 206 """ 207 207 List all files of the storage. 208 208 """ 209 for path in utils.get_files(self.storage, ignore_patterns ):209 for path in utils.get_files(self.storage, ignore_patterns, include_patterns): 210 210 yield path, self.storage 211 211 212 212 class DefaultStorageFinder(BaseStorageFinder): -
django/contrib/staticfiles/utils.py
3 3 from django.conf import settings 4 4 from django.core.exceptions import ImproperlyConfigured 5 5 6 def is_ignored(path, ignore_patterns=[]):6 def matches(path, patterns=[]): 7 7 """ 8 Return True or False depending on whether the ``path`` should be9 i gnored (if it matches any pattern in ``ignore_patterns``).8 Return True or False depending on whether the ``path`` matches any pattern 9 in ``patterns``. 10 10 """ 11 for pattern in ignore_patterns:11 for pattern in patterns: 12 12 if fnmatch.fnmatchcase(path, pattern): 13 13 return True 14 14 return False 15 15 16 def get_files(storage, ignore_patterns=[], location=''): 16 def is_ignored(path, ignore_patterns=[]): 17 return matches(path, ignore_patterns) 18 19 def is_included(path, include_patterns=[]): 20 if not include_patterns: 21 return True 22 return matches(path, include_patterns) 23 24 def get_files(storage, ignore_patterns=[], include_patterns=[], location=''): 17 25 """ 18 26 Recursively walk the storage directories yielding the paths 19 27 of all files that should be copied. 20 28 """ 21 29 directories, files = storage.listdir(location) 22 30 for fn in files: 31 if location: 32 fn = os.path.normpath(os.path.join(location, fn)) 23 33 if is_ignored(fn, ignore_patterns): 24 34 continue 25 if location:26 fn = os.path.join(location, fn)35 if not is_included(fn, include_patterns): 36 continue 27 37 yield fn 28 38 for dir in directories: 39 if location: 40 dir = os.path.normpath(os.path.join(location, dir)) 29 41 if is_ignored(dir, ignore_patterns): 30 42 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): 34 44 yield fn 35 45 36 46 def check_settings(): -
django/contrib/staticfiles/collectstatic.py
77 77 raise CommandError("Collecting static files cancelled.") 78 78 79 79 for finder in finders.get_finders(): 80 for path, storage in finder.list(ignore_patterns ):80 for path, storage in finder.list(ignore_patterns, []): 81 81 # Prefix the relative path if the source storage contains it 82 82 if getattr(storage, 'prefix', None): 83 83 prefixed_path = os.path.join(storage.prefix, path)