cms.management.commands.subcommands.base: 28 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/management/commands/subcommands/base.py

Stats: 0 executed, 26 missed, 2 excluded, 8 ignored

  1. # -*- coding: utf-8 -*-
  2. from django.core.management.base import BaseCommand, CommandError
  3. import sys
  4. class SubcommandsCommand(BaseCommand):
  5. subcommands = {}
  6. command_name = ''
  7. def __init__(self):
  8. super(SubcommandsCommand, self).__init__()
  9. for name, subcommand in self.subcommands.items():
  10. subcommand.command_name = '%s %s' % (self.command_name, name)
  11. def handle(self, *args, **options):
  12. stderr = getattr(self, 'stderr', sys.stderr)
  13. stdout = getattr(self, 'stdout', sys.stdout)
  14. if len(args) > 0:
  15. if args[0] in self.subcommands.keys():
  16. handle_command = self.subcommands.get(args[0])()
  17. handle_command.stdout = stdout
  18. handle_command.stderr = stderr
  19. handle_command.handle(*args[1:], **options)
  20. else:
  21. stderr.write("%r is not a valid subcommand for %r\n" % (args[0], self.command_name))
  22. stderr.write("Available subcommands are:\n")
  23. for subcommand in sorted(self.subcommands.keys()):
  24. stderr.write(" %r\n" % subcommand)
  25. raise CommandError('Invalid subcommand %r for %r' % (args[0], self.command_name))
  26. else:
  27. stderr.write("%r must be called with at least one argument, it's subcommand.\n" % self.command_name)
  28. stderr.write("Available subcommands are:\n")
  29. for subcommand in sorted(self.subcommands.keys()):
  30. stderr.write(" %r\n" % subcommand)
  31. raise CommandError('No subcommand given for %r' % self.command_name)