Example #1
0
def main(command_name, command_dir, version, description, *args, **kwargs):
    #===============================================================================
    """
    Called by running script to execute command with command line arguments.
    """
    # The "package" keyword flags when running from a package zip __main__.py.
    package = utility.kwargs_get_boolean(kwargs, 'package', default=False)
    # The "standalone" keyword allows environment.py to skip the library search.
    standalone = utility.kwargs_get_boolean(kwargs,
                                            'standalone',
                                            default=False)
    # The "state_directory" keyword overrides ~/.<command_name> as the
    # directory used for runtime state files.
    state_directory = utility.kwargs_get_string(kwargs,
                                                'state_directory',
                                                default=None)
    try:
        # Pre-scan for verbose, debug, and dry-run options so that early code
        # can display verbose and debug messages, and obey dry-run.
        opts = cli.preprocess_options(base_cli_spec.options, args)
        utility.set_verbose(opts.verbose)
        utility.set_debug(opts.debug)

        # Load the configuration and state
        permanent_path = os.path.join(os.getcwd(), environment.config_name)
        local_path = os.path.join(os.getcwd(), environment.config_name_local)
        config = VoltConfig(permanent_path, local_path)

        # Initialize the environment
        environment.initialize(standalone, command_name, command_dir, version)

        # Initialize the state directory (for runtime state files).
        if state_directory is None:
            state_directory = '~/.%s' % environment.command_name
        state_directory = os.path.expandvars(
            os.path.expanduser(state_directory))
        utility.set_state_directory(state_directory)

        # Search for modules based on both this file's and the calling script's location.
        verbspace = load_verbspace(command_name, command_dir, config, version,
                                   description, package,
                                   environment.pro_version)

        # Make internal commands available to user commands via runner.verbspace().
        internal_verbspaces = {}
        if command_name not in internal_commands:
            for internal_command in internal_commands:
                internal_verbspace = load_verbspace(
                    internal_command, None, config, version,
                    'Internal "%s" command' % internal_command, package)
                internal_verbspaces[internal_command] = internal_verbspace

        # Run the command
        run_command(verbspace, internal_verbspaces, config, *args)

    except KeyboardInterrupt:
        sys.stderr.write('\n')
        utility.abort('break')
Example #2
0
def main(command_name, command_dir, version, description, *args, **kwargs):
#===============================================================================
    """
    Called by running script to execute command with command line arguments.
    """
    # The "package" keyword flags when running from a package zip __main__.py.
    package = utility.kwargs_get_boolean(kwargs, 'package', default=False)
    # The "standalone" keyword allows environment.py to skip the library search.
    standalone = utility.kwargs_get_boolean(kwargs, 'standalone', default=False)
    # The "state_directory" keyword overrides ~/.<command_name> as the
    # directory used for runtime state files.
    state_directory = utility.kwargs_get_string(kwargs, 'state_directory', default=None)
    try:
        # Pre-scan for verbose, debug, and dry-run options so that early code
        # can display verbose and debug messages, and obey dry-run.
        opts = cli.preprocess_options(base_cli_spec.options, args)
        utility.set_verbose(opts.verbose)
        utility.set_debug(opts.debug)

        # Load the configuration and state
        permanent_path = os.path.join(os.getcwd(), environment.config_name)
        local_path     = os.path.join(os.getcwd(), environment.config_name_local)
        config = VoltConfig(permanent_path, local_path)

        # Initialize the environment
        environment.initialize(standalone, command_name, command_dir, version)

        # Initialize the state directory (for runtime state files).
        if state_directory is None:
            state_directory = '~/.%s' % environment.command_name
        state_directory = os.path.expandvars(os.path.expanduser(state_directory))
        utility.set_state_directory(state_directory)

        # Search for modules based on both this file's and the calling script's location.
        verbspace = load_verbspace(command_name, command_dir, config, version,
                                   description, package)

        # Make internal commands available to user commands via runner.verbspace().
        internal_verbspaces = {}
        if command_name not in internal_commands:
            for internal_command in internal_commands:
                internal_verbspace = load_verbspace(internal_command, None, config, version,
                                                    'Internal "%s" command' % internal_command,
                                                    package)
                internal_verbspaces[internal_command] = internal_verbspace

        # Run the command
        run_command(verbspace, internal_verbspaces, config, *args)

    except KeyboardInterrupt:
        sys.stderr.write('\n')
        utility.abort('break')