예제 #1
0
파일: main.py 프로젝트: sis-tools/dcos-cli
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:
        logger.debug("DCOS bin path: {!r}".format(util.dcos_bin_path()))

        results = [(c, default_command_info(c))
                   for c in subcommand.default_subcommands()]
        paths = subcommand.list_paths()
        with ThreadPoolExecutor(max_workers=max(len(paths), 1)) as executor:
            results += list(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 (DC/OS). The Mesosphere DC/OS is a distributed operating\n"
            "system built around Apache Mesos. This utility provides tools\n"
            "for easy management of a DC/OS installation.\n")
        emitter.publish("Available DC/OS commands:")
        emitter.publish(commands_message)
        emitter.publish(
            "\nGet detailed command description with 'dcos <command> --help'.")

        return 0
예제 #2
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:
        logger.debug("DCOS bin path: {!r}".format(util.dcos_bin_path()))

        results = [(c, default_command_info(c))
                   for c in subcommand.default_subcommands()]
        paths = subcommand.list_paths()
        with ThreadPoolExecutor(max_workers=max(len(paths), 1)) as executor:
            results += list(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 (DC/OS). The Mesosphere DC/OS is a distributed operating\n"
            "system built around Apache Mesos. This utility provides tools\n"
            "for easy management of a DC/OS installation.\n")
        emitter.publish("Available DC/OS commands:")
        emitter.publish(commands_message)
        emitter.publish(
            "\nGet detailed command description with 'dcos <command> --help'.")

        return 0
예제 #3
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 = util.dcos_bin_path()
    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):
        virtualenv_path = _find_virtualenv(bin_directory)

        virtualenv_version = _execute_command([virtualenv_path, '--version'
                                               ])[0].strip().decode('utf-8')
        if LooseVersion("12") > LooseVersion(virtualenv_version):
            msg = ("Unable to install CLI subcommand. "
                   "Required program 'virtualenv' must be version 12+, "
                   "currently version {}\n"
                   "Please see installation instructions: "
                   "https://virtualenv.pypa.io/en/latest/installation.html"
                   "".format(virtualenv_version))
            raise DCOSException(msg)

        cmd = [_find_virtualenv(bin_directory), env_directory]

        if _execute_command(cmd)[2] != 0:
            raise _generic_error(package_name)

    # Do not replace util.temptext NamedTemporaryFile
    # otherwise bad things will happen on Windows
    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_command(cmd)[2] != 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
예제 #4
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 = util.dcos_bin_path()
    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):
        virtualenv_path = _find_virtualenv(bin_directory)

        virtualenv_version = _execute_command([virtualenv_path, "--version"])[0].strip().decode("utf-8")
        if LooseVersion("12") > LooseVersion(virtualenv_version):
            msg = (
                "Unable to install CLI subcommand. "
                "Required program 'virtualenv' must be version 12+, "
                "currently version {}\n"
                "Please see installation instructions: "
                "https://virtualenv.pypa.io/en/latest/installation.html"
                "".format(virtualenv_version)
            )
            raise DCOSException(msg)

        cmd = [_find_virtualenv(bin_directory), env_directory]

        if _execute_command(cmd)[2] != 0:
            raise _generic_error(package_name)

    # Do not replace util.temptext NamedTemporaryFile
    # otherwise bad things will happen on Windows
    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_command(cmd)[2] != 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
예제 #5
0
def default_list_paths():
    """List the real path to dcos executable

    :returns: list dcos program path
    :rtype: str
    """

    # Let's get all the default subcommands
    binpath = util.dcos_bin_path()
    return os.path.join(binpath, "dcos")
예제 #6
0
def default_list_paths():
    """List the real path to dcos executable

    :returns: list dcos program path
    :rtype: str
    """

    # Let's get all the default subcommands
    binpath = util.dcos_bin_path()
    return os.path.join(binpath, "dcos")
예제 #7
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 = util.dcos_bin_path()
    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 = [_find_virtualenv(bin_directory), env_directory]

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

    # Do not replace util.temptext NamedTemporaryFile
    # otherwise bad things will happen on Windows
    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
예제 #8
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 = util.dcos_bin_path()
    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 = [_find_virtualenv(bin_directory), env_directory]

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

    # Do not replace util.temptext NamedTemporaryFile
    # otherwise bad things will happen on Windows
    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
예제 #9
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 = util.dcos_bin_path()
    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 = [_find_virtualenv(bin_directory), env_directory]

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

    with tempfile.NamedTemporaryFile() as temp_file:
        # Write the requirements to the file
        for line in requirements:
            temp_file.write((line + os.linesep).encode('utf-8'))
        # Make sure that we flush the file before passing it to pip
        temp_file.flush()

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

        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
예제 #10
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 = util.dcos_bin_path()
    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 = [_find_virtualenv(bin_directory), env_directory]

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

    with tempfile.NamedTemporaryFile() as temp_file:
        # Write the requirements to the file
        for line in requirements:
            temp_file.write((line + os.linesep).encode('utf-8'))
        # Make sure that we flush the file before passing it to pip
        temp_file.flush()

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

        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
예제 #11
0
def list_paths():
    """List the real path to executable dcos subcommand programs.

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

    # Let's get all the default subcommands
    binpath = util.dcos_bin_path()
    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
예제 #12
0
def list_paths():
    """List the real path to executable dcos subcommand programs.

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

    # Let's get all the default subcommands
    binpath = util.dcos_bin_path()
    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