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