Example #1
0
def add(obj, versions, latest_existing, plugins):
    """Add plugin(s) to local store from file, URL, or S3."""
    plugins_local_dir = obj["plugins_local_dir"]
    plugins_s3_buckets = obj["plugins_s3_buckets"]
    plugins_force = obj["plugins_force"]
    host = obj["host"]

    specs_to_search_in_s3 = []
    to_download_from_s3 = []
    s3_versions = None  # For performance, only fetch if/when first needed.
    added_from_file_or_uri = False
    for plugin in plugins:
        if Path(plugin).is_file():
            _add_to_local_store_from_uri(
                plugins_local_dir,
                Path(plugin).resolve().as_uri(),
                plugins_force,
            )
            added_from_file_or_uri = True
        elif urllib.parse.urlparse(plugin).scheme != "":
            _add_to_local_store_from_uri(plugins_local_dir, plugin,
                                         plugins_force)
            added_from_file_or_uri = True
        else:
            specs_to_search_in_s3.append(PluginSpec.make_from_string(plugin))
    if versions:
        specs_to_search_in_s3.extend(
            PluginSpecs.make_from_version_dict(
                lib.read_toml(Path(versions).expanduser())))
    if latest_existing:
        specs_to_search_in_s3.extend(
            PluginSpecs.make_from_plugininfos(
                PluginInfos.make_from_encapsia(host)))
    if specs_to_search_in_s3:
        s3_versions = PluginInfos.make_from_s3_buckets(plugins_s3_buckets)
        to_download_from_s3.extend(pi for spec in specs_to_search_in_s3 if (
            pi := s3_versions.latest_version_matching_spec(spec)) is not None)
    if to_download_from_s3:
        for pi in to_download_from_s3:
            _add_to_local_store_from_s3(pi,
                                        plugins_local_dir,
                                        force=plugins_force)
    else:
        if not added_from_file_or_uri:
            lib.log("Nothing to do!")
Example #2
0
def upstream(obj, plugins, all_versions):
    """Print information about plugins on S3.

    By default, only includes latest versions.
    """
    plugins_s3_buckets = obj["plugins_s3_buckets"]
    lib.log(
        f"Searching for plugins in S3 bucket(s): {', '.join(plugins_s3_buckets)}"
    )
    plugin_infos = PluginInfos.make_from_s3_buckets(plugins_s3_buckets)
    if plugins:
        plugin_infos = PluginSpecs.make_from_spec_strings(plugins).filter(
            plugin_infos)
    if not all_versions:
        plugin_infos = plugin_infos.filter_to_latest()
    info = ([
        r.name_and_variant(),
        r.formatted_version(),
        r.get_s3_bucket(),
        r.get_s3_path(),
    ] for r in sorted(plugin_infos))
    lib.log(tabulate(info, headers=["name*", "version**", "bucket", "path"]))
    _log_message_explaining_headers()