Exemplo n.º 1
0
def _help(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    if command is not None:
        _help_command(command)
    else:
        directory = util.dcos_path()
        logger.debug("DCOS Path: {!r}".format(directory))

        paths = subcommand.list_paths()
        with ThreadPoolExecutor(max_workers=len(paths)) as executor:
            results = executor.map(subcommand.documentation, paths)
            commands_message = options\
                .make_command_summary_string(sorted(results))

        emitter.publish(
            "Command line utility for the Mesosphere Datacenter Operating\n"
            "System (DCOS). The Mesosphere DCOS is a distributed operating\n"
            "system built around Apache Mesos. This utility provides tools\n"
            "for easy management of a DCOS installation.\n")
        emitter.publish("Available DCOS commands:")
        emitter.publish(commands_message)
        emitter.publish(
            "\nGet detailed command description with 'dcos <command> --help'.")

        return 0
Exemplo n.º 2
0
def _main():
    signal.signal(signal.SIGINT, signal_handler)

    if not _is_valid_configuration():
        return 1

    args = docopt.docopt(
        __doc__,
        version='dcos version {}'.format(dcoscli.version),
        options_first=True)

    if args['<command>'] != 'config' and \
       not auth.check_if_user_authenticated():
        auth.force_auth()

    if not _config_log_level_environ(args['--log-level']):
        return 1

    err = util.configure_logger_from_environ()
    if err is not None:
        emitter.publish(err)
        return 1

    command = args['<command>']
    http.silence_requests_warnings()

    if not command:
        command = "help"

    executable = subcommand.command_executables(command, util.dcos_path())

    subproc = Popen([executable,  command] + args['<args>'],
                    stderr=PIPE)

    return analytics.wait_and_track(subproc)
Exemplo n.º 3
0
def _help(command):
    """
    :param command: the command name for which you want to see a help
    :type command: str
    :returns: process return code
    :rtype: int
    """

    if command is not None:
        _help_command(command)
    else:
        directory = util.dcos_path()
        logger.debug("DCOS Path: {!r}".format(directory))

        paths = subcommand.list_paths()
        with ThreadPoolExecutor(max_workers=len(paths)) as executor:
            results = executor.map(subcommand.documentation, paths)
            commands_message = options\
                .make_command_summary_string(sorted(results))

        emitter.publish(
            "Command line utility for the Mesosphere Datacenter Operating\n"
            "System (DCOS). The Mesosphere DCOS is a distributed operating\n"
            "system built around Apache Mesos. This utility provides tools\n"
            "for easy management of a DCOS installation.\n")
        emitter.publish("Available DCOS commands:")
        emitter.publish(commands_message)
        emitter.publish(
            "\nGet detailed command description with 'dcos <command> --help'.")

        return 0
Exemplo n.º 4
0
def installed_subcommands():
    """Returns all installed subcommands.

    :returns: all installed subcommands
    :rtype: [InstalledSubcommand]
    """

    return [subcommand.InstalledSubcommand(name) for name in
            subcommand.distributions(util.dcos_path())]
Exemplo n.º 5
0
def _install_with_pip(
        package_name,
        env_directory,
        requirements):
    """
    :param package_name: the name of the package
    :type package_name: str
    :param env_directory: the path to the directory in which to install the
                          package's virtual env
    :type env_directory: str
    :param requirements: the list of pip requirements
    :type requirements: list of str
    :rtype: None
    """

    bin_directory = os.path.join(util.dcos_path(), BIN_DIRECTORY)
    new_package_dir = not os.path.exists(env_directory)

    pip_path = os.path.join(env_directory, BIN_DIRECTORY, 'pip')
    if not os.path.exists(pip_path):
        cmd = [os.path.join(bin_directory, 'virtualenv'), env_directory]

        if _execute_install(cmd) != 0:
            raise _generic_error(package_name)

    with util.temptext() as text_file:
        fd, requirement_path = text_file

        # Write the requirements to the file
        with os.fdopen(fd, 'w') as requirements_file:
            for line in requirements:
                print(line, file=requirements_file)

        cmd = [
            os.path.join(env_directory, BIN_DIRECTORY, 'pip'),
            'install',
            '--requirement',
            requirement_path,
        ]

        if _execute_install(cmd) != 0:
            # We should remove the directory that we just created
            if new_package_dir:
                shutil.rmtree(env_directory)

            raise _generic_error(package_name)

    return None
Exemplo n.º 6
0
def _install_with_pip(package_name, env_directory, requirements):
    """
    :param package_name: the name of the package
    :type package_name: str
    :param env_directory: the path to the directory in which to install the
                          package's virtual env
    :type env_directory: str
    :param requirements: the list of pip requirements
    :type requirements: list of str
    :rtype: None
    """

    bin_directory = os.path.join(util.dcos_path(), BIN_DIRECTORY)
    new_package_dir = not os.path.exists(env_directory)

    pip_path = os.path.join(env_directory, BIN_DIRECTORY, 'pip')
    if not os.path.exists(pip_path):
        cmd = [os.path.join(bin_directory, 'virtualenv'), env_directory]

        if _execute_install(cmd) != 0:
            raise _generic_error(package_name)

    with util.temptext() as text_file:
        fd, requirement_path = text_file

        # Write the requirements to the file
        with os.fdopen(fd, 'w') as requirements_file:
            for line in requirements:
                print(line, file=requirements_file)

        cmd = [
            os.path.join(env_directory, BIN_DIRECTORY, 'pip'),
            'install',
            '--requirement',
            requirement_path,
        ]

        if _execute_install(cmd) != 0:
            # We should remove the directory that we just created
            if new_package_dir:
                shutil.rmtree(env_directory)

            raise _generic_error(package_name)

    return None
Exemplo n.º 7
0
def _get_config_schema(command):
    """
    :param command: the subcommand name
    :type command: str
    :returns: the subcommand's configuration schema
    :rtype: dict
    """

    # core.* config variables are special.  They're valid, but don't
    # correspond to any particular subcommand, so we must handle them
    # separately.
    if command == "core":
        return json.loads(
            pkg_resources.resource_string(
                'dcoscli',
                'data/config-schema/core.json').decode('utf-8'))

    executable = subcommand.command_executables(command, util.dcos_path())
    return subcommand.config_schema(executable)
Exemplo n.º 8
0
def list_paths():
    """List the real path to executable dcos subcommand programs.

    :returns: list of all the dcos program paths
    :rtype: [str]
    """

    dcos_path = util.dcos_path()
    # Let's get all the default subcommands
    binpath = os.path.join(dcos_path, BIN_DIRECTORY)
    commands = [
        os.path.join(binpath, filename) for filename in os.listdir(binpath)
        if (filename.startswith(constants.DCOS_COMMAND_PREFIX)
            and _is_executable(os.path.join(binpath, filename)))
    ]

    subcommands = []
    for package in distributions():
        subcommands += get_package_commands(package)

    return commands + subcommands
Exemplo n.º 9
0
def list_paths():
    """List the real path to executable dcos subcommand programs.

    :returns: list of all the dcos program paths
    :rtype: [str]
    """

    dcos_path = util.dcos_path()
    # Let's get all the default subcommands
    binpath = os.path.join(dcos_path, BIN_DIRECTORY)
    commands = [
        os.path.join(binpath, filename)
        for filename in os.listdir(binpath)
        if (filename.startswith(constants.DCOS_COMMAND_PREFIX) and _is_executable(os.path.join(binpath, filename)))
    ]

    subcommands = []
    for package in distributions():
        subcommands += get_package_commands(package)

    return commands + subcommands
Exemplo n.º 10
0
def _help(show_info):
    if show_info:
        emitter.publish(__doc__.split('\n')[0])
        return 0

    directory = util.dcos_path()
    logger.debug("DCOS Path: {!r}".format(directory))

    paths = subcommand.list_paths()
    with ThreadPoolExecutor(max_workers=len(paths)) as executor:
        results = executor.map(subcommand.documentation, paths)
        commands_message = options.make_command_summary_string(sorted(results))

    emitter.publish(
        "Command line utility for the Mesosphere Datacenter Operating\n"
        "System (DCOS). The Mesosphere DCOS is a distributed operating\n"
        "system built around Apache Mesos. This utility provides tools\n"
        "for easy management of a DCOS installation.\n")
    emitter.publish("Available DCOS commands:")
    emitter.publish(commands_message)
    emitter.publish(
        "\nGet detailed command description with 'dcos <command> --help'.")

    return 0