|
@@ -55,7 +55,9 @@ class FileSystemFinder(BaseFinder):
|
|
|
self.locations.add((prefix, root))
|
|
|
# Don't initialize multiple storages for the same location
|
|
|
for prefix, root in self.locations:
|
|
|
- self.storages[root] = FileSystemStorage(location=root)
|
|
|
+ filesystem_storage = FileSystemStorage(location=root)
|
|
|
+ filesystem_storage.prefix = prefix
|
|
|
+ self.storages[root] = filesystem_storage
|
|
|
|
|
|
super(FileSystemFinder, self).__init__(*args, **kwargs)
|
|
|
|
|
@@ -94,7 +96,7 @@ class FileSystemFinder(BaseFinder):
|
|
|
for prefix, root in self.locations:
|
|
|
storage = self.storages[root]
|
|
|
for path in utils.get_files(storage, ignore_patterns):
|
|
|
- yield path, prefix, storage
|
|
|
+ yield path, storage
|
|
|
|
|
|
|
|
|
class AppDirectoriesFinder(BaseFinder):
|
|
@@ -105,14 +107,18 @@ class AppDirectoriesFinder(BaseFinder):
|
|
|
storage_class = AppStaticStorage
|
|
|
|
|
|
def __init__(self, apps=None, *args, **kwargs):
|
|
|
- # Maps app modules to appropriate storage instances
|
|
|
+ # The list of apps that are handled
|
|
|
+ self.apps = []
|
|
|
+ # Mapping of app module paths to storage instances
|
|
|
self.storages = SortedDict()
|
|
|
- if apps is not None:
|
|
|
- self.apps = apps
|
|
|
- else:
|
|
|
- self.apps = models.get_apps()
|
|
|
- for app in self.apps:
|
|
|
- self.storages[app] = self.storage_class(app)
|
|
|
+ if apps is None:
|
|
|
+ apps = settings.INSTALLED_APPS
|
|
|
+ for app in apps:
|
|
|
+ app_storage = self.storage_class(app)
|
|
|
+ if os.path.isdir(app_storage.location):
|
|
|
+ self.storages[app] = app_storage
|
|
|
+ if app not in self.apps:
|
|
|
+ self.apps.append(app)
|
|
|
super(AppDirectoriesFinder, self).__init__(*args, **kwargs)
|
|
|
|
|
|
def list(self, ignore_patterns):
|
|
@@ -121,9 +127,8 @@ class AppDirectoriesFinder(BaseFinder):
|
|
|
"""
|
|
|
for storage in self.storages.itervalues():
|
|
|
if storage.exists(''): # check if storage location exists
|
|
|
- prefix = storage.get_prefix()
|
|
|
for path in utils.get_files(storage, ignore_patterns):
|
|
|
- yield path, prefix, storage
|
|
|
+ yield path, storage
|
|
|
|
|
|
def find(self, path, all=False):
|
|
|
"""
|
|
@@ -131,29 +136,29 @@ class AppDirectoriesFinder(BaseFinder):
|
|
|
"""
|
|
|
matches = []
|
|
|
for app in self.apps:
|
|
|
- app_matches = self.find_in_app(app, path)
|
|
|
- if app_matches:
|
|
|
+ match = self.find_in_app(app, path)
|
|
|
+ if match:
|
|
|
if not all:
|
|
|
- return app_matches
|
|
|
- matches.append(app_matches)
|
|
|
+ return match
|
|
|
+ matches.append(match)
|
|
|
return matches
|
|
|
|
|
|
def find_in_app(self, app, path):
|
|
|
"""
|
|
|
Find a requested static file in an app's static locations.
|
|
|
"""
|
|
|
- storage = self.storages[app]
|
|
|
- prefix = storage.get_prefix()
|
|
|
- if prefix:
|
|
|
- prefix = '%s%s' % (prefix, os.sep)
|
|
|
- if not path.startswith(prefix):
|
|
|
- return None
|
|
|
- path = path[len(prefix):]
|
|
|
- # only try to find a file if the source dir actually exists
|
|
|
- if storage.exists(path):
|
|
|
- matched_path = storage.path(path)
|
|
|
- if matched_path:
|
|
|
- return matched_path
|
|
|
+ storage = self.storages.get(app, None)
|
|
|
+ if storage:
|
|
|
+ if storage.prefix:
|
|
|
+ prefix = '%s%s' % (storage.prefix, os.sep)
|
|
|
+ if not path.startswith(prefix):
|
|
|
+ return None
|
|
|
+ path = path[len(prefix):]
|
|
|
+ # only try to find a file if the source dir actually exists
|
|
|
+ if storage.exists(path):
|
|
|
+ matched_path = storage.path(path)
|
|
|
+ if matched_path:
|
|
|
+ return matched_path
|
|
|
|
|
|
|
|
|
class BaseStorageFinder(BaseFinder):
|
|
@@ -196,7 +201,7 @@ class BaseStorageFinder(BaseFinder):
|
|
|
List all files of the storage.
|
|
|
"""
|
|
|
for path in utils.get_files(self.storage, ignore_patterns):
|
|
|
- yield path, '', self.storage
|
|
|
+ yield path, self.storage
|
|
|
|
|
|
class DefaultStorageFinder(BaseStorageFinder):
|
|
|
"""
|