mirror of
https://github.com/wassname/sloth.git
synced 2026-07-04 06:27:30 +08:00
remove obsolete CommandLineUtility
This commit is contained in:
@@ -247,85 +247,3 @@ class LaxOptionParser(OptionParser):
|
||||
raise Exception
|
||||
except:
|
||||
largs.append(arg)
|
||||
|
||||
|
||||
class CommandLineUtility(object):
|
||||
"""
|
||||
A CommandLineUtility has a number of commands, which can be manipulated
|
||||
by editing the self.commands dictionary.
|
||||
"""
|
||||
def __init__(self, argv=None):
|
||||
self.argv = argv or sys.argv[:]
|
||||
self.prog_name = os.path.basename(self.argv[0])
|
||||
|
||||
def main_help_text(self):
|
||||
"""
|
||||
Returns the script's main help text, as a string.
|
||||
"""
|
||||
usage = ['', "Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name,'']
|
||||
usage.append('Available subcommands:')
|
||||
commands = get_commands().keys()
|
||||
commands.sort()
|
||||
for cmd in commands:
|
||||
usage.append(' %s' % cmd)
|
||||
return '\n'.join(usage)
|
||||
|
||||
def fetch_command(self, subcommand):
|
||||
"""
|
||||
Tries to fetch the given subcommand, printing a message with the
|
||||
appropriate command called from the command line if it can't be found.
|
||||
"""
|
||||
try:
|
||||
app_name = get_commands()[subcommand]
|
||||
except KeyError:
|
||||
sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % \
|
||||
(subcommand, self.prog_name))
|
||||
sys.exit(1)
|
||||
if isinstance(app_name, BaseCommand):
|
||||
# If the command is already loaded, use it directly.
|
||||
klass = app_name
|
||||
else:
|
||||
klass = load_command_class(app_name, subcommand)
|
||||
return klass
|
||||
|
||||
def execute(self):
|
||||
"""
|
||||
Given the command-line arguments, this figures out which subcommand is
|
||||
being run, creates a parser appropriate to that command, and runs it.
|
||||
"""
|
||||
# Preprocess options to extract --settings and --pythonpath.
|
||||
# These options could affect the commands that are available, so they
|
||||
# must be processed early.
|
||||
parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
|
||||
version=sloth.VERSION,
|
||||
option_list=BaseCommand.option_list)
|
||||
try:
|
||||
options, args = parser.parse_args(self.argv)
|
||||
#handle_default_options(options)
|
||||
except:
|
||||
pass # Ignore any option errors at this point.
|
||||
|
||||
try:
|
||||
subcommand = self.argv[1]
|
||||
except IndexError:
|
||||
subcommand = 'help' # Display help if no arguments were given.
|
||||
|
||||
if subcommand == 'help':
|
||||
if len(args) > 2:
|
||||
self.fetch_command(args[2]).print_help(self.prog_name, args[2])
|
||||
else:
|
||||
parser.print_lax_help()
|
||||
sys.stdout.write(self.main_help_text() + '\n')
|
||||
sys.exit(1)
|
||||
# Special-cases: We want 'django-admin.py --version' and
|
||||
# 'django-admin.py --help' to work, for backwards compatibility.
|
||||
elif self.argv[1:] == ['--version']:
|
||||
# LaxOptionParser already takes care of printing the version.
|
||||
pass
|
||||
elif self.argv[1:] in (['--help'], ['-h']):
|
||||
parser.print_lax_help()
|
||||
sys.stdout.write(self.main_help_text() + '\n')
|
||||
else:
|
||||
self.fetch_command(subcommand).run_from_argv(self.argv)
|
||||
|
||||
from commands import get_commands
|
||||
|
||||
Reference in New Issue
Block a user