PageRenderTime 15ms CodeModel.GetById 7ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/django/contrib/staticfiles/management/commands/findstatic.py

https://code.google.com/p/mango-py/
Python | 31 lines | 28 code | 3 blank | 0 comment | 6 complexity | a0f5fc42ba96e047f4f4c347821bdfed MD5 | raw file
 1import os
 2from optparse import make_option
 3from django.core.management.base import LabelCommand
 4from django.utils.encoding import smart_str, smart_unicode
 5
 6from django.contrib.staticfiles import finders
 7
 8class Command(LabelCommand):
 9    help = "Finds the absolute paths for the given static file(s)."
10    args = "[file ...]"
11    label = 'static file'
12    option_list = LabelCommand.option_list + (
13        make_option('--first', action='store_false', dest='all', default=True,
14                    help="Only return the first match for each static file."),
15    )
16
17    def handle_label(self, path, **options):
18        verbosity = int(options.get('verbosity', 1))
19        result = finders.find(path, all=options['all'])
20        path = smart_unicode(path)
21        if result:
22            if not isinstance(result, (list, tuple)):
23                result = [result]
24            output = u'\n  '.join(
25                (smart_unicode(os.path.realpath(path)) for path in result))
26            self.stdout.write(
27                smart_str(u"Found '%s' here:\n  %s\n" % (path, output)))
28        else:
29            if verbosity >= 1:
30                self.stderr.write(
31                    smart_str("No matching file found for '%s'.\n" % path))