コード例 #1
0
ファイル: __init__.py プロジェクト: davemerwin/pinax
 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.
     """
     parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
         version=pinax.get_version(),
         option_list=BaseCommand.option_list)
     try:
         options, args = parser.parse_args(self.argv)
         handle_default_options(options)
     except:
         pass
     
     try:
         subcommand = self.argv[1]
     except IndexError:
         sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
         sys.exit(1)
     
     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.stderr.write(self.main_help_text() + "\n")
             sys.exit(1)
     elif self.argv[1:] == ["--version"]:
         pass
     elif self.argv[1:] in [["--help"], ["-h"]]:
         parser.print_lax_help()
         sys.stderr.write(self.main_help_text() + "\n")
     else:
         self.fetch_command(subcommand).run_from_argv(self.argv)
コード例 #2
0
ファイル: __init__.py プロジェクト: jialei/Join-the-Event
    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.
        """
        parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
                                 version=pinax.get_version(),
                                 option_list=BaseCommand.option_list)
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            pass

        try:
            subcommand = self.argv[1]
        except IndexError:
            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
            sys.exit(1)

        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.stderr.write(self.main_help_text() + '\n')
                sys.exit(1)
        elif self.argv[1:] == ['--version']:
            pass
        elif self.argv[1:] in [['--help'], ['-h']]:
            parser.print_lax_help()
            sys.stderr.write(self.main_help_text() + '\n')
        else:
            self.fetch_command(subcommand).run_from_argv(self.argv)
コード例 #3
0
    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')
コード例 #4
0
    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')
コード例 #5
0
ファイル: manage.py プロジェクト: Robinlovelace/wirecloud
    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=django.get_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:
            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
            sys.exit(1)

        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.stderr.write(self.main_help_text() + '\n')
                sys.exit(1)
        # Special-cases: We want 'manage.py --version' and
        # 'manage.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:] == ['--help']:
            parser.print_lax_help()
            sys.stderr.write(self.main_help_text() + '\n')
        else:
            from django.db import connections, DEFAULT_DB_ALIAS
            db = options.__dict__.get('database', DEFAULT_DB_ALIAS)
            mysql_workaround = subcommand == "syncdb" and settings.DATABASES[db]['ENGINE'] == "mysql"
            if mysql_workaround:
                connection = connections[db]
                cursor = connection.cursor()
                cursor.execute("SET FOREIGN_KEY_CHECKS = 0")

            self.fetch_command(subcommand).run_from_argv(self.argv)

            if mysql_workaround:
                cursor = connection.cursor()
                cursor.execute("SET FOREIGN_KEY_CHECKS = 1")
コード例 #6
0
ファイル: manage.py プロジェクト: Yanual/ezwebplatform
    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=django.get_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:
            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name)
            sys.exit(1)

        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.stderr.write(self.main_help_text() + '\n')
                sys.exit(1)
        # Special-cases: We want 'manage.py --version' and
        # 'manage.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:] == ['--help']:
            parser.print_lax_help()
            sys.stderr.write(self.main_help_text() + '\n')
        else:
            mysql_workaround = subcommand == "syncdb" and settings.DATABASE_ENGINE == "mysql"
            if mysql_workaround:
                from django.db import connection
                cursor = connection.cursor()
                cursor.execute("SET FOREIGN_KEY_CHECKS = 0")

            self.fetch_command(subcommand).run_from_argv(self.argv)

            if mysql_workaround:
                cursor = connection.cursor()
                cursor.execute("SET FOREIGN_KEY_CHECKS = 1")
コード例 #7
0
ファイル: manage.py プロジェクト: gvsurenderreddy/synnefo-1
    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.
        """

        # --settings-dir option
        # will remove it later to avoid django commands from raising errors
        option_list = BaseCommand.option_list + (
            make_option(
                '--settings-dir',
                action='store',
                dest='settings_dir',
                default=None,
                help='Load *.conf files from directory as settings'),)

        # 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_component_version('webproject'),
                                 option_list=option_list)
        self.autocomplete()
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            pass  # Ignore any option errors at this point.

        # user provides custom settings dir
        # set it as environmental variable and remove it from self.argv
        if options.settings_dir:
            os.environ['SYNNEFO_SETTINGS_DIR'] = options.settings_dir
            for arg in self.argv:
                if arg.startswith('--settings-dir'):
                    self.argv.remove(arg)

        try:
            subcommand = self.argv[1]
        except IndexError:
            subcommand = 'help'  # Display help if no arguments were given.

        # Encode stdout. This check is required because of the way python
        # checks if something is tty:
        # https://bugzilla.redhat.com/show_bug.cgi?id=841152
        if subcommand not in ['test'] and 'shell' not in subcommand:
            sys.stdout = EncodedStream(sys.stdout)
            sys.stderr = EncodedStream(sys.stderr)

        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:
            sub_command = self.fetch_command(subcommand)
            # NOTE: This is an ugly workaround to bypass the problem with
            # the required permissions for the named pipes that Pithos backend
            # is creating in order to communicate with XSEG.
            if subcommand == 'test' or\
               subcommand.startswith('image-') or\
               subcommand.startswith('snapshot-') or\
               subcommand.startswith('file-'):
                # Set common umask for known commands
                os.umask(0o007)
            # Allow command to define a custom umask
            cmd_umask = getattr(sub_command, 'umask', None)
            if cmd_umask is not None:
                os.umask(cmd_umask)
            sub_command.run_from_argv(self.argv)
コード例 #8
0
    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.
        """

        # --settings-dir option
        # will remove it later to avoid django commands from raising errors
        option_list = BaseCommand.option_list + (
            make_option('--settings-dir',
                action='store',
                dest='settings_dir',
                default=None,
                help='Load *.conf files from directory as settings'),)

        # 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_component_version('webproject'),
                                 option_list=option_list)
        self.autocomplete()
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            pass  # Ignore any option errors at this point.

        # user provides custom settings dir
        # set it as environmental variable and remove it from self.argv
        if options.settings_dir:
            os.environ['SYNNEFO_SETTINGS_DIR'] = options.settings_dir
            for arg in self.argv:
                if arg.startswith('--settings-dir'):
                    self.argv.remove(arg)

        try:
            subcommand = self.argv[1]
        except IndexError:
            subcommand = 'help'  # Display help if no arguments were given.

        # Encode stdout. This check is required because of the way python
        # checks if something is tty:
        # https://bugzilla.redhat.com/show_bug.cgi?id=841152
        if not subcommand in ['test'] and not 'shell' in subcommand:
            sys.stdout = EncodedStdOut(sys.stdout)

        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)
コード例 #9
0
ファイル: server.py プロジェクト: blueantelope/-Antelope.CI
    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()
コード例 #10
0
ファイル: server.py プロジェクト: blueantelope/-Antelope.CI
    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()