def execute(self, argv=None, stdout=None, stderr=None): if argv is None: argv = sys.argv parser = LaxOptionParser(usage="%prog subcommand [options] [args]", version=wirecloud.platform.__version__, option_list=()) if stdout is None: stdout = sys.stdout if stderr is None: stderr = sys.stderr try: options, args = parser.parse_args(argv) except: pass # Ignore any option errors at this point. try: subcommand = argv[1] except IndexError: subcommand = 'help' # Display help if no arguments were given. if subcommand == 'help': if len(args) <= 2: parser.print_lax_help() stdout.write(self.main_help_text() + '\n') elif args[2] == '--commands': stdout.write(self.main_help_text(commands_only=True) + '\n') else: command = self.fetch_command(args[2]) if command is not None: command.print_help(self.prog_name, args[2], file=stdout) else: stdout.write(self.unknown_command_text(args[2]) + '\n') elif subcommand == 'version': stdout.write(parser.get_version() + '\n') elif '--version' in argv[1:]: # LaxOptionParser already takes care of printing the version. pass elif '--help' in argv[1:] or '-h' in argv[1:]: if len(args) <= 2: parser.print_lax_help() stdout.write(self.main_help_text() + '\n') else: command = self.fetch_command(args[1]) if command is not None: command.print_help(self.prog_name, args[1], file=stdout) else: stdout.write(self.unknown_command_text(args[1]) + '\n') else: command = self.fetch_command(subcommand) if command is not None: command.run_from_argv(argv, stdout=stdout, stderr=stderr) else: stdout.write(self.unknown_command_text(subcommand) + '\n')
def execute(self, argv=None, stdout=None, stderr=None): if argv is None: argv = sys.argv parser = LaxOptionParser(usage="%prog subcommand [options] [args]", version=wirecloud.platform.__version__, option_list=()) if stdout is None: stdout = sys.stdout if stderr is None: stderr = sys.stderr try: options, args = parser.parse_args(argv) except: pass # Ignore any option errors at this point. try: subcommand = argv[1] except IndexError: subcommand = 'help' # Display help if no arguments were given. if subcommand == 'help': if len(args) <= 2: parser.print_lax_help() stdout.write(self.main_help_text() + '\n') elif args[2] == '--commands': stdout.write(self.main_help_text(commands_only=True) + '\n') else: command = self.fetch_command(args[2]) if command is not None: command.print_help(self.prog_name, args[2], file=stdout) else: stdout.write(self.unknown_command_text(args[2]) + '\n') elif subcommand == 'version': stdout.write(parser.get_version() + '\n') elif '--version' in argv[1:]: # LaxOptionParser already takes care of printing the version. pass elif '--help' in argv[1:] or '-h' in argv[1:]: if len(args) <= 2: parser.print_lax_help() stdout.write(self.main_help_text() + '\n') else: command = self.fetch_command(args[1]) if command is not None: command.print_help(self.prog_name, args[1], file=stdout) else: stdout.write(self.unknown_command_text(args[1]) + '\n') else: command = self.fetch_command(subcommand) if command is not None: command.run_from_argv(argv, stdout=stdout, stderr=stderr) else: stdout.write(self.unknown_command_text(subcommand) + '\n')
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=get_version(), option_list=ServerCommand.option_list) try: options, args = parser.parse_args(self.argv) handle_default_options(options) except: # Needed because parser.parse_args can raise SystemExit pass # Ignore any option errors at this point. try: subcommand = self.argv[1] except IndexError: subcommand = 'help' # Display help if no arguments were given. no_settings_commands = [ 'help', 'version', '--help', '--version', '-h', 'compilemessages', 'makemessages', 'startapp', 'startproject', ] try: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc # A handful of built-in management commands work without settings. # Load the default settings -- where INSTALLED_APPS is empty. if subcommand in no_settings_commands: settings.configure() if settings.configured: django.setup() self.autocomplete() if subcommand == 'help': if len(args) <= 2: parser.print_lax_help() sys.stdout.write(self.main_help_text() + '\n') elif args[2] == '--commands': sys.stdout.write(self.main_help_text(commands_only=True) + '\n') else: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) elif subcommand == 'version': sys.stdout.write(parser.get_version() + '\n') # 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.start_server()
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=get_version(), option_list=ServerCommand.option_list) try: options, args = parser.parse_args(self.argv) handle_default_options(options) except: # Needed because parser.parse_args can raise SystemExit pass # Ignore any option errors at this point. try: subcommand = self.argv[1] except IndexError: subcommand = 'help' # Display help if no arguments were given. no_settings_commands = [ 'help', 'version', '--help', '--version', '-h', 'compilemessages', 'makemessages', 'startapp', 'startproject', ] try: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc # A handful of built-in management commands work without settings. # Load the default settings -- where INSTALLED_APPS is empty. if subcommand in no_settings_commands: settings.configure() if settings.configured: django.setup() self.autocomplete() if subcommand == 'help': if len(args) <= 2: parser.print_lax_help() sys.stdout.write(self.main_help_text() + '\n') elif args[2] == '--commands': sys.stdout.write( self.main_help_text(commands_only=True) + '\n') else: self.fetch_command(args[2]).print_help(self.prog_name, args[2]) elif subcommand == 'version': sys.stdout.write(parser.get_version() + '\n') # 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.start_server()