Beispiel #1
0
def install_batch():
    payload = request.get_json()
    plugin_type = PluginType(payload["plugin_type"])
    plugin_name = payload["name"]

    project = Project.find()

    plugins_service = ProjectPluginsService(project)
    plugin = plugins_service.find_plugin(plugin_name, plugin_type=plugin_type)

    add_service = ProjectAddService(project, plugins_service=plugins_service)
    related_plugins = add_service.add_related(plugin)

    # We will install the plugins in reverse order, since dependencies
    # are listed after their dependents in `related_plugins`, but should
    # be installed first.
    related_plugins.reverse()

    install_service = PluginInstallService(project,
                                           plugins_service=plugins_service)
    install_status = install_service.install_plugins(
        related_plugins, reason=PluginInstallReason.ADD)

    for error in install_status["errors"]:
        raise PluginInstallError(error["message"])

    return jsonify([plugin.canonical() for plugin in related_plugins])
Beispiel #2
0
def add_related_plugins(project,
                        plugins,
                        add_service: ProjectAddService,
                        plugin_types=list(PluginType)):
    discovery_service = PluginDiscoveryService(project)

    added_plugins = []
    for plugin_install in plugins:
        try:
            plugin_def = discovery_service.find_plugin(plugin_install.type,
                                                       plugin_install.name)
        except PluginNotFoundError:
            continue

        related_plugins = add_service.add_related(plugin_def,
                                                  plugin_types=plugin_types)
        for related_plugin in related_plugins:
            if related_plugin.should_add_to_file(project):
                click.secho(
                    f"Added related {related_plugin.type.descriptor} '{related_plugin.name}' to your Meltano project",
                    fg="green",
                )
            else:
                click.secho(
                    f"Adding related {related_plugin.type.descriptor} '{related_plugin.name}' to your Meltano project...",
                    fg="green",
                )

        added_plugins.extend(related_plugins)

    return added_plugins
Beispiel #3
0
def install_batch():
    payload = request.get_json()
    plugin_type = PluginType(payload["plugin_type"])
    plugin_name = payload["name"]

    project = Project.find()

    # We use the DiscoveryService rather than the ConfigService because the
    # plugin may not actually be installed yet at this point.
    discovery = PluginDiscoveryService(project)
    plugin = discovery.find_plugin(plugin_type, plugin_name)

    add_service = ProjectAddService(project)
    related_plugins = add_service.add_related(plugin)

    install_service = PluginInstallService(project)
    install_service.install_plugins(related_plugins)

    return jsonify([plugin.canonical() for plugin in related_plugins])