1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #19879 -- Have 'findstatic' says on which directories it searched the relative paths.

Added searched_locations in finders module. Added verbosity flag level 2 on 'findstatic'
command that will output the directories on which it searched the relative paths.

Reported by ccurvey. Initial patch by Jonas Svensson and Vajrasky Kok.
This commit is contained in:
Vajrasky Kok
2013-11-16 22:55:50 +08:00
committed by Jannis Leidel
parent 935e6c1dfc
commit 6a9ed7d403
5 changed files with 100 additions and 3 deletions

View File

@@ -12,11 +12,15 @@ from django.utils import six, lru_cache
from django.contrib.staticfiles import utils
# To keep track on which directories the finder has searched the static files.
searched_locations = []
class BaseFinder(object):
"""
A base file finder to be used for custom staticfiles finder classes.
"""
def find(self, path, all=False):
"""
Given a relative file path this ought to find an
@@ -75,6 +79,8 @@ class FileSystemFinder(BaseFinder):
"""
matches = []
for prefix, root in self.locations:
if root not in searched_locations:
searched_locations.append(root)
matched_path = self.find_location(root, path, prefix)
if matched_path:
if not all:
@@ -147,6 +153,9 @@ class AppDirectoriesFinder(BaseFinder):
"""
matches = []
for app in self.apps:
app_location = self.storages[app].location
if app_location not in searched_locations:
searched_locations.append(app_location)
match = self.find_in_app(app, path)
if match:
if not all:
@@ -195,6 +204,8 @@ class BaseStorageFinder(BaseFinder):
except NotImplementedError:
pass
else:
if self.storage.location not in searched_locations:
searched_locations.append(self.storage.location)
if self.storage.exists(path):
match = self.storage.path(path)
if all:
@@ -232,6 +243,7 @@ def find(path, all=False):
If ``all`` is ``False`` (default), return the first matching
absolute path (or ``None`` if no match). Otherwise return a list.
"""
searched_locations[:] = []
matches = []
for finder in get_finders():
result = finder.find(path, all=all)

View File

@@ -21,15 +21,25 @@ class Command(LabelCommand):
verbosity = int(options.get('verbosity', 1))
result = finders.find(path, all=options['all'])
path = force_text(path)
if verbosity >= 2:
searched_locations = ("Looking in the following locations:\n %s" %
"\n ".join(force_text(location)
for location in finders.searched_locations))
else:
searched_locations = ''
if result:
if not isinstance(result, (list, tuple)):
result = [result]
result = (force_text(os.path.realpath(path)) for path in result)
if verbosity >= 1:
output = '\n '.join(result)
return "Found '%s' here:\n %s" % (path, output)
file_list = '\n '.join(result)
return ("Found '%s' here:\n %s\n%s" %
(path, file_list, searched_locations))
else:
return '\n'.join(result)
else:
message = ["No matching file found for '%s'." % path]
if verbosity >= 2:
message.append(searched_locations)
if verbosity >= 1:
self.stderr.write("No matching file found for '%s'." % path)
self.stderr.write('\n'.join(message))