예제 #1
0
    def execute(self):
        try:
            subcommand = self.argv[1]
        except:
            subcommand = 'help'

        # Check for platform requirements. (Python version)
        if sys.version_info[0] < 3 or sys.version_info[1] <= 5:
            print('WARNING')
            print(
                'WARNING: Your Python version is not officially supported by PyPlanet, please upgrade your Python!'
            )
            print('WARNING')
        if sys.version_info[0] > 3 or sys.version_info[1] > 8:
            print('WARNING')
            print(
                'WARNING: Your Python version is untested and most likely not working with PyPlanet!'
            )
            print('WARNING')

        # Root parser.
        parser = CommandParser(None,
                               usage='%(prog)s subcommand [options] [args]',
                               add_help=False)
        parser.add_argument('--settings')
        parser.add_argument('--pool')
        parser.add_argument('--pythonpath')
        parser.add_argument('args', nargs='*')
        try:
            options, args = parser.parse_known_args(self.argv[2:])
            handle_default_options(options)
        except CommandError:
            pass  # Ignore any option errors at this point.

        try:
            settings.APPS
        except ImproperlyConfigured as e:
            self.settings_exception = e

        # TODO: Load some parts of the app (with the provided pool or default pool) so we can load commands from apps.

        self.autocomplete()

        if subcommand == 'help':
            if '--commands' in args:
                sys.stdout.write(
                    self.main_help_text(commands_only=True) + '\n')
            elif len(options.args) < 1:
                sys.stdout.write(self.main_help_text() + '\n')
            else:
                self.fetch_command(options.args[0]).print_help(
                    self.prog_name, options.args[0])
            # Special-cases: We want 'pyplanet --version' and
            # 'pyplanet --help' to work, for backwards compatibility.
        elif subcommand == 'version' or self.argv[1:] == ['--version']:
            sys.stdout.write(self.version + '\n')
        elif self.argv[1:] in (['--help'], ['-h']):
            sys.stdout.write(self.main_help_text() + '\n')
        else:
            self.fetch_command(subcommand).run_from_argv(self.argv)
예제 #2
0
    def execute(self):
        try:
            subcommand = self.argv[1]
        except:
            subcommand = 'help'

        # Root parser.
        parser = CommandParser(None,
                               usage='%(prog)s subcommand [options] [args]',
                               add_help=False)
        parser.add_argument('--settings')
        parser.add_argument('--pool')
        parser.add_argument('--pythonpath')
        parser.add_argument('args', nargs='*')
        try:
            options, args = parser.parse_known_args(self.argv[2:])
            handle_default_options(options)
        except CommandError:
            pass  # Ignore any option errors at this point.

        try:
            settings.APPS
        except ImproperlyConfigured as e:
            self.settings_exception = e

        # TODO: Load some parts of the app (with the provided pool or default pool) so we can load commands from apps.

        self.autocomplete()

        if subcommand == 'help':
            if '--commands' in args:
                sys.stdout.write(
                    self.main_help_text(commands_only=True) + '\n')
            elif len(options.args) < 1:
                sys.stdout.write(self.main_help_text() + '\n')
            else:
                self.fetch_command(options.args[0]).print_help(
                    self.prog_name, options.args[0])
            # Special-cases: We want 'pyplanet --version' and
            # 'pyplanet --help' to work, for backwards compatibility.
        elif subcommand == 'version' or self.argv[1:] == ['--version']:
            sys.stdout.write(self.version + '\n')
        elif self.argv[1:] in (['--help'], ['-h']):
            sys.stdout.write(self.main_help_text() + '\n')
        else:
            self.fetch_command(subcommand).run_from_argv(self.argv)