2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2010-10-20 09:33:24 +08:00
|
|
|
import os
|
|
|
|
from optparse import make_option
|
|
|
|
from django.core.management.base import LabelCommand
|
2012-07-21 16:00:10 +08:00
|
|
|
from django.utils.encoding import smart_text
|
2010-10-20 09:33:24 +08:00
|
|
|
|
|
|
|
from django.contrib.staticfiles import finders
|
|
|
|
|
|
|
|
class Command(LabelCommand):
|
|
|
|
help = "Finds the absolute paths for the given static file(s)."
|
|
|
|
args = "[file ...]"
|
|
|
|
label = 'static file'
|
|
|
|
option_list = LabelCommand.option_list + (
|
|
|
|
make_option('--first', action='store_false', dest='all', default=True,
|
|
|
|
help="Only return the first match for each static file."),
|
|
|
|
)
|
|
|
|
|
|
|
|
def handle_label(self, path, **options):
|
|
|
|
verbosity = int(options.get('verbosity', 1))
|
|
|
|
result = finders.find(path, all=options['all'])
|
2012-07-21 16:00:10 +08:00
|
|
|
path = smart_text(path)
|
2010-10-20 09:33:24 +08:00
|
|
|
if result:
|
2010-10-23 22:32:54 +08:00
|
|
|
if not isinstance(result, (list, tuple)):
|
|
|
|
result = [result]
|
2012-06-08 00:08:47 +08:00
|
|
|
output = '\n '.join(
|
2012-07-21 16:00:10 +08:00
|
|
|
(smart_text(os.path.realpath(path)) for path in result))
|
2012-06-08 00:08:47 +08:00
|
|
|
self.stdout.write("Found '%s' here:\n %s" % (path, output))
|
2010-10-20 09:33:24 +08:00
|
|
|
else:
|
|
|
|
if verbosity >= 1:
|
2012-05-19 19:51:54 +08:00
|
|
|
self.stderr.write("No matching file found for '%s'." % path)
|