Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 3
0
def run_command(verbspace, internal_verbspaces, config, *args, **kwargs):
#===============================================================================
    """
    Run a command after parsing the command line arguments provided.
    """
    # Parse the command line.
    parser = VoltCLIParser(verbspace)
    command = parser.parse(*args)

    # Initialize utility function options according to parsed options.
    utility.set_verbose(command.opts.verbose)
    utility.set_debug(  command.opts.debug)

    # Run the command. Pass along kwargs. This allows verbs calling other verbs
    # to add keyword arguments like "classpath".
    runner = VerbRunner(command, verbspace, internal_verbspaces, config, **kwargs)
    runner.execute()
Ejemplo n.º 4
0
def run_command(verbspace, internal_verbspaces, config, *args, **kwargs):
    #===============================================================================
    """
    Run a command after parsing the command line arguments provided.
    """
    # Parse the command line.
    parser = VoltCLIParser(verbspace)
    command = parser.parse(*args)
    """
    Read username/password from txt file
    """
    if hasattr(command.opts,
               'credentials') and command.opts.credentials is not None:
        credentials = command.opts.credentials
        try:
            credentialsFile = open(credentials, "r")
        except IOError:
            print("Credentials file not found or permission denied.")
        else:
            content = ""
            for line in credentialsFile:
                content += line
            user, usr, password, pswd = content.replace(':', ' ').split()
            command.opts.username = usr
            command.opts.password = pswd
            credentialsFile.close()

    # Initialize utility function options according to parsed options.
    utility.set_verbose(command.opts.verbose)
    utility.set_debug(command.opts.debug)
    if hasattr(command.opts, 'dryrun'):
        utility.set_dryrun(command.opts.dryrun)

    # Run the command. Pass along kwargs. This allows verbs calling other verbs
    # to add keyword arguments like "classpath".
    runner = VerbRunner(command, verbspace, internal_verbspaces, config,
                        **kwargs)
    runner.execute()