Changed core.management print_help() methods to accept a prog_name argument instead of an argv list, in an attempt to figure out why auto reloading stopped working

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6089 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-09-11 03:46:35 +00:00
parent c554858f6b
commit a247c726c2
2 changed files with 13 additions and 13 deletions

View File

@ -51,11 +51,11 @@ class ManagementUtility(object):
names = [f[:-3] for f in os.listdir(command_dir) if not f.startswith('_') and f.endswith('.py')]
return dict([(name, load_command_class(name)) for name in names])
def print_help(self, argv):
def print_help(self, prog_name):
"""
Returns the help message, as a string.
"""
prog_name = os.path.basename(argv[0])
prog_name = os.path.basename(prog_name)
usage = ['%s <subcommand> [options] [args]' % prog_name]
usage.append('Django command line tool, version %s' % django.get_version())
usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % prog_name)
@ -66,7 +66,7 @@ class ManagementUtility(object):
usage.append(' %s' % cmd)
print '\n'.join(usage)
def fetch_command(self, subcommand, command_name):
def fetch_command(self, subcommand, prog_name):
"""
Tries to fetch the given subcommand, printing a message with the
appropriate command called from the command line (usually
@ -75,13 +75,13 @@ class ManagementUtility(object):
try:
return self.commands[subcommand]
except KeyError:
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, command_name))
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, prog_name))
sys.exit(1)
def execute(self, argv=None):
"""
Figures out which command is being run (the first arg), creates a parser
appropriate to that command, and runs it.
Given the command-line arguments, this figures out which subcommand is
being run, creates a parser appropriate to that command, and runs it.
"""
if argv is None:
argv = sys.argv
@ -93,17 +93,17 @@ class ManagementUtility(object):
if subcommand == 'help':
if len(argv) > 2:
self.fetch_command(argv[2], argv[0]).print_help(argv[2:])
self.fetch_command(argv[2], argv[0]).print_help(argv[0])
else:
self.print_help(argv)
self.print_help(argv[0])
# Special-cases: We want 'django-admin.py --version' and
# 'django-admin.py --help' to work, for backwards compatibility.
elif argv[1:] == ['--version']:
print django.get_version()
elif argv[1:] == ['--help']:
self.print_help(argv)
self.print_help(argv[0])
else:
self.fetch_command(subcommand, argv[0]).run(argv[1:])
self.fetch_command(subcommand, argv[0]).run_from_argv(argv[1:])
class ProjectManagementUtility(ManagementUtility):
"""

View File

@ -49,11 +49,11 @@ class BaseCommand(object):
version=self.get_version(),
option_list=self.option_list)
def print_help(self, argv):
parser = self.create_parser(argv[0])
def print_help(self, prog_name):
parser = self.create_parser(prog_name)
parser.print_help()
def run(self, argv):
def run_from_argv(self, argv):
parser = self.create_parser(argv[0])
options, args = parser.parse_args(argv[1:])
if options.settings: