def extract_plugin_name(plugin_url):
    previous_cwd = os.getcwd()
    fetch_plugin_from_pip_by_url = not os.path.isdir(plugin_url)
    plugin_dir = plugin_url
    try:
        if fetch_plugin_from_pip_by_url:
            plugin_dir = tempfile.mkdtemp()
            req_set = pip.req.RequirementSet(build_dir=None,
                                             src_dir=None,
                                             download_dir=None)
            req_set.unpack_url(link=pip.index.Link(plugin_url),
                               location=plugin_dir,
                               download_dir=None,
                               only_download=False)
        os.chdir(plugin_dir)
        return LocalCommandRunner(
            host=utils.get_local_ip()
        ).run('cmd.exe /c "{0} {1} {2}"'.format(
            sys.executable,
            os.path.join(os.path.dirname(__file__), 'extract_package_name.py'),
            plugin_dir)).std_out
    finally:
        os.chdir(previous_cwd)
        if fetch_plugin_from_pip_by_url:
            shutil.rmtree(plugin_dir)
Example #2
0
def extract_plugin_name(plugin_url):
    previous_cwd = os.getcwd()
    fetch_plugin_from_pip_by_url = not os.path.isdir(plugin_url)
    plugin_dir = plugin_url
    try:
        if fetch_plugin_from_pip_by_url:
            plugin_dir = tempfile.mkdtemp()
            req_set = pip.req.RequirementSet(build_dir=None,
                                             src_dir=None,
                                             download_dir=None)
            req_set.unpack_url(link=pip.index.Link(plugin_url),
                               location=plugin_dir,
                               download_dir=None,
                               only_download=False)
        runner = LocalCommandRunner(host=utils.get_local_ip())
        os.chdir(plugin_dir)
        plugin_name = runner.run(
            '{0} {1} {2}'.format(_python(),
                                 path.join(
                                     path.dirname(__file__),
                                     'extract_package_name.py'),
                                 plugin_dir)).std_out
        runner.run('{0} install --no-deps {1}'.format(_pip(), plugin_dir))
        return plugin_name
    finally:
        os.chdir(previous_cwd)
        if fetch_plugin_from_pip_by_url:
            shutil.rmtree(plugin_dir)
Example #3
0
def install_package(url):

    """
    Installs a package onto the worker's virtualenv.

    :param url: A URL to the package archive.
    """

    command = '{0} install {1}'.format(_pip(), url)
    LocalCommandRunner(
        host=utils.get_local_ip()
    ).run(command)
Example #4
0
def extract_plugin_name(plugin_dir):
    previous_cwd = os.getcwd()

    try:
        os.chdir(plugin_dir)
        runner = LocalCommandRunner(host=utils.get_local_ip())
        plugin_name = runner.run('{0} {1} {2}'.format(
            _python(),
            path.join(path.dirname(__file__), 'extract_package_name.py'),
            plugin_dir)).std_out
        return plugin_name
    finally:
        os.chdir(previous_cwd)
Example #5
0
def extract_plugin_name(plugin_dir):
    previous_cwd = os.getcwd()

    try:
        os.chdir(plugin_dir)
        runner = LocalCommandRunner(host=utils.get_local_ip())
        plugin_name = runner.run(
            '{0} {1} {2}'.format(_python(),
                                 path.join(
                                     path.dirname(__file__),
                                     'extract_package_name.py'),
                                 plugin_dir)).std_out
        return plugin_name
    finally:
        os.chdir(previous_cwd)
Example #6
0
def extract_module_paths(plugin_dir):

    plugin_name = extract_plugin_name(plugin_dir)

    module_paths = []
    files = LocalCommandRunner(host=utils.get_local_ip()).run(
        '{0} show -f {1}'.format(
            _pip(),
            plugin_name)).std_out.splitlines()
    for module in files:
        if module.endswith('.py') and '__init__' not in module:
            # the files paths are relative to the package __init__.py file.
            module_paths.append(module.replace('../', '')
                                .replace('/', '.').replace('.py', '').strip())
    return module_paths
Example #7
0
def extract_module_paths(plugin_dir):

    plugin_name = extract_plugin_name(plugin_dir)

    module_paths = []
    files = LocalCommandRunner(host=utils.get_local_ip()).run(
        '{0} show -f {1}'.format(_pip(), plugin_name)).std_out.splitlines()
    for module in files:
        if module.endswith('.py') and '__init__' not in module:
            # the files paths are relative to the package __init__.py file.
            module_paths.append(
                module.replace('../', '').replace('/',
                                                  '.').replace('.py',
                                                               '').strip())
    return module_paths
Example #8
0
def _update_includes(module_paths):

    # Read current AppParameters
    app_parameters = read_app_parameters()

    new_app_parameters = add_module_paths_to_includes(
        module_paths,
        app_parameters)
    utils.LocalCommandRunner(
        host=utils.get_local_ip()
    ).run(
        'cmd /c "{0} set CloudifyAgent AppParameters {1}"'
        .format(NSSM_PATH, new_app_parameters))

    # Write new AppParameters
    write_app_parameters(new_app_parameters)
Example #9
0
def install_celery_plugin(plugin_url):

    """
    Installs celery tasks into the cloudify agent.

        1. Installs the plugin into the current python installation directory.
        2  Adds the python files into the agent includes directive.

    :param plugin_url: URL to an archive of the plugin.
    """

    command = 'cmd /c "{0}\Scripts\pip.exe install {1}"' \
        .format(sys.prefix, plugin_url)
    utils.LocalCommandRunner(
        logger=logger,
        host=utils.get_local_ip()
    ).run(command)
    plugin_name = plugin_utils.extract_plugin_name(plugin_url)
    module_paths = plugin_utils.extract_module_paths(plugin_name)
    _update_includes(module_paths)
Example #10
0
def install_package(extracted_plugin_dir, install_args):
    """
    Installs a package onto the worker's virtualenv.

    :param extracted_plugin_dir:The directory containing the extracted plugin.
                                If the plugin's source property is a URL, this
                                is the directory the plugin was unpacked to.
    :param install_args:       Arguments passed to pip install.
                                e.g.: -r requirements.txt
    """

    previous_cwd = os.getcwd()

    try:
        os.chdir(extracted_plugin_dir)

        command = '{0} install . {1}'.format(_pip(), install_args)
        LocalCommandRunner(host=utils.get_local_ip()).run(command)
    finally:
        os.chdir(previous_cwd)
Example #11
0
def install_package(extracted_plugin_dir, install_args):

    """
    Installs a package onto the worker's virtualenv.

    :param extracted_plugin_dir:The directory containing the extracted plugin.
                                If the plugin's source property is a URL, this
                                is the directory the plugin was unpacked to.
    :param install_args:       Arguments passed to pip install.
                                e.g.: -r requirements.txt
    """

    previous_cwd = os.getcwd()

    try:
        os.chdir(extracted_plugin_dir)

        command = '{0} install . {1}'.format(_pip(), install_args)
        LocalCommandRunner(host=utils.get_local_ip()).run(command)
    finally:
        os.chdir(previous_cwd)
def extract_module_paths(module_name):

    module_paths = []
    files = LocalCommandRunner(host=utils.get_local_ip())\
        .run('cmd /c "{0}\Scripts\pip.exe show -f {1}"'
             .format(sys.prefix, module_name)).std_out.splitlines()
    for module in files:
        if module.endswith(".py") and "__init__" not in module:
            if module.endswith("-script.py"):
                script_stripped = module[:-len("-script.py")]
                potential_exe_file = "{0}.exe".format(script_stripped)
                if potential_exe_file in files:
                    # file is a console script "entry_point"
                    continue

            # the files paths are relative to the package __init__.py file.
            module_paths.append(
                module.replace("..\\", "").replace("\\", ".")
                .replace(".py", "")
                .strip())
    return ','.join(module_paths)