Ejemplo n.º 1
0
def test_registry(isolated_pio_core):
    lm = LibraryPackageManager()

    # reveal ID
    assert lm.reveal_registry_package_id(PackageSpec(id=13)) == 13
    assert lm.reveal_registry_package_id(PackageSpec(name="OneWire"),
                                         silent=True) == 1
    with pytest.raises(UnknownPackageError):
        lm.reveal_registry_package_id(
            PackageSpec(name="/non-existing-package/"))

    # fetch package data
    assert lm.fetch_registry_package(PackageSpec(id=1))["name"] == "OneWire"
    assert lm.fetch_registry_package(
        PackageSpec(name="ArduinoJson"))["id"] == 64
    assert (lm.fetch_registry_package(
        PackageSpec(id=13, owner="adafruit",
                    name="Renamed library"))["name"] == "Adafruit GFX Library")
    with pytest.raises(UnknownPackageError):
        lm.fetch_registry_package(
            PackageSpec(owner="unknown<>owner", name="/non-existing-package/"))
    with pytest.raises(UnknownPackageError):
        lm.fetch_registry_package(PackageSpec(name="/non-existing-package/"))
Ejemplo n.º 2
0
def lib_show(library, json_output):
    lm = LibraryPackageManager()
    lib_id = lm.reveal_registry_package_id(library, silent=json_output)
    regclient = lm.get_registry_client_instance()
    lib = regclient.fetch_json_data("get", "/v2/lib/info/%d" % lib_id, cache_valid="1h")
    if json_output:
        return click.echo(dump_json_to_unicode(lib))

    title = "{ownername}/{name}".format(**lib)
    click.secho(title, fg="cyan")
    click.echo("=" * len(title))
    click.echo(lib["description"])
    click.echo()

    click.secho("ID: %d" % lib["id"])
    click.echo(
        "Version: %s, released %s"
        % (
            lib["version"]["name"],
            time.strftime("%c", util.parse_date(lib["version"]["released"])),
        )
    )
    click.echo("Manifest: %s" % lib["confurl"])
    for key in ("homepage", "repository", "license"):
        if key not in lib or not lib[key]:
            continue
        if isinstance(lib[key], list):
            click.echo("%s: %s" % (key.title(), ", ".join(lib[key])))
        else:
            click.echo("%s: %s" % (key.title(), lib[key]))

    blocks = []

    _authors = []
    for author in lib.get("authors", []):
        _data = []
        for key in ("name", "email", "url", "maintainer"):
            if not author.get(key):
                continue
            if key == "email":
                _data.append("<%s>" % author[key])
            elif key == "maintainer":
                _data.append("(maintainer)")
            else:
                _data.append(author[key])
        _authors.append(" ".join(_data))
    if _authors:
        blocks.append(("Authors", _authors))

    blocks.append(("Keywords", lib["keywords"]))
    for key in ("frameworks", "platforms"):
        if key not in lib or not lib[key]:
            continue
        blocks.append(("Compatible %s" % key, [i["title"] for i in lib[key]]))
    blocks.append(("Headers", lib["headers"]))
    blocks.append(("Examples", lib["examples"]))
    blocks.append(
        (
            "Versions",
            [
                "%s, released %s"
                % (v["name"], time.strftime("%c", util.parse_date(v["released"])))
                for v in lib["versions"]
            ],
        )
    )
    blocks.append(
        (
            "Unique Downloads",
            [
                "Today: %s" % lib["dlstats"]["day"],
                "Week: %s" % lib["dlstats"]["week"],
                "Month: %s" % lib["dlstats"]["month"],
            ],
        )
    )

    for (title, rows) in blocks:
        click.echo()
        click.secho(title, bold=True)
        click.echo("-" * len(title))
        for row in rows:
            click.echo(row)

    return True