Пример #1
0
def dev_update(obj, directory):
    """Update plugin parts which have changed since previous update.

    Optionally pass in the DIRECTORY of the plugin (defaults to cwd).

    """
    directory = Path(directory)
    plugin_toml_path = directory / "plugin.toml"
    if not plugin_toml_path.exists():
        lib.log_error("Not in a plugin directory.", abort=True)

    with _get_modified_plugin_directories(
            directory,
            reset=obj["plugins_force"]) as modified_plugin_directories:
        if modified_plugin_directories:
            with lib.temp_directory() as temp_directory:
                shutil.copy(plugin_toml_path, temp_directory)
                for modified_directory in modified_plugin_directories:
                    lib.log(f"Including: {modified_directory}")
                    shutil.copytree(
                        directory / modified_directory,
                        temp_directory / modified_directory,
                    )
                api = lib.get_api(**obj)
                result = lib.run_plugins_task(
                    api,
                    "dev_update_plugin",
                    dict(),
                    "Uploading to server",
                    data=lib.create_targz_as_bytes(temp_directory),
                )
                if not result:
                    raise _PluginsTaskError
        else:
            lib.log("Nothing to do.")
Пример #2
0
def build_from_src(obj, sources):
    """Build plugins from given source directories."""
    plugins_cache_dir = obj["plugins_cache_dir"]
    force = obj["force"]
    for source_directory in sources:
        source_directory = Path(source_directory)
        manifest = lib.read_toml(source_directory / "plugin.toml")
        name = manifest["name"]
        version = manifest["version"]
        output_filename = plugins_cache_dir / f"plugin-{name}-{version}.tar.gz"
        if not force and output_filename.exists():
            lib.log(f"Found: {output_filename} (Skipping)")
        else:
            with lib.temp_directory() as temp_directory:
                base_dir = temp_directory / f"plugin-{name}-{version}"
                base_dir.mkdir()
                for t in (
                        "webfiles",
                        "views",
                        "tasks",
                        "wheels",
                        "schedules",
                        "plugin.toml",
                ):
                    source_t = source_directory / t
                    if source_t.exists():
                        if source_t.is_file():
                            shutil.copy(source_t, base_dir / t)
                        else:
                            shutil.copytree(source_t, base_dir / t)
                lib.create_targz(base_dir, output_filename)
                lib.log(f"Created: {output_filename}")
Пример #3
0
 def _read_description(pi):
     filename = plugins_local_dir / pi.get_filename()
     try:
         with lib.temp_directory() as tmp_dir:
             lib.extract_targz(filename, tmp_dir)
             manifests = list(tmp_dir.glob("**/plugin.toml"))
             return lib.read_toml(manifests[0])["description"]
     except Exception:
         lib.log_error(f"Malformed? Unable to read: {filename}")
Пример #4
0
def dev_build(obj, sources):
    """Build plugins from given source directories."""
    plugins_local_dir = obj["plugins_local_dir"]
    plugins_force = obj["plugins_force"]
    for source_directory in sources:
        source_directory = Path(source_directory)
        manifest = lib.read_toml(source_directory / "plugin.toml")
        name = manifest["name"]
        version = manifest["version"]
        tags = manifest.get("tags", [])
        try:
            variant = get_variant_from_tags(tags)
        except TooManyVariantTagsError as e:
            lib.log_error(str(e), abort=True)
        if variant:
            output_filename = (
                plugins_local_dir /
                f"plugin-{name}-variant-{variant}-{version}.tar.gz")
        else:
            output_filename = plugins_local_dir / f"plugin-{name}-{version}.tar.gz"
        if not plugins_force and output_filename.exists():
            lib.log(f"Found: {output_filename} (Skipping)")
        else:
            with lib.temp_directory() as temp_directory:
                base_dir = temp_directory / f"plugin-{name}-{version}"
                base_dir.mkdir()
                for t in (
                        "webfiles",
                        "views",
                        "tasks",
                        "wheels",
                        "schedules",
                        "plugin.toml",
                ):
                    source_t = source_directory / t
                    if source_t.exists():
                        if source_t.is_file():
                            shutil.copy(source_t, base_dir / t)
                        else:
                            shutil.copytree(source_t, base_dir / t)
                lib.create_targz(base_dir, output_filename)
                lib.log(f"Added to local store: {output_filename}")
Пример #5
0
def _download_and_build_plugin_from_s3(s3_directory, name, version, email,
                                       output_filename):
    with lib.temp_directory() as temp_directory:
        base_dir = temp_directory / f"plugin-{name}-{version}"
        base_dir.mkdir()

        # Download everything from S3 into the webfiles folder.
        # (we will move out the views and tasks if present).
        files_directory = base_dir / "webfiles"
        files_directory.mkdir()
        lib.run(
            "aws",
            "s3",
            "cp",
            f"s3://{s3_directory}/{name}/{version}",
            files_directory.as_posix(),
            "--recursive",
        )

        # Move out the views if they exist.
        views_directory = files_directory / "views"
        if views_directory.exists():
            views_directory.rename(base_dir / "views")

        # Move out the wheels if they exist.
        wheels_directory = files_directory / "tasks/wheels"
        if wheels_directory.exists():
            wheels_directory.rename(base_dir / "wheels")

        # Move out the tasks if they exist.
        tasks_directory = files_directory / "tasks"
        if tasks_directory.exists():
            tasks_directory.rename(base_dir / "tasks")

        # Create a plugin.toml manifest.
        make_plugin_toml_file(base_dir / "plugin.toml", name, f"Webapp {name}",
                              version, email)

        # Convert all into tar.gz
        lib.create_targz(base_dir, output_filename)