예제 #1
0
def pip_pkgs(img_name):
    """get python packages installed in an image."""
    with Container(img_name) as sha_id:
        Container.run_docker_cmd(sha_id, "pip install pip-licenses")
        pkgs = Container.run_docker_cmd(sha_id,
                                        "pip-licenses -f=csv --from=mixed")
    return pkgs, sha_id
예제 #2
0
def apt_pkgs(img_name):
    """get apt packages installed in an image."""
    with Container(img_name) as sha_id:
        cmd = "dpkg-query -Wf '${Package},${Version},${Source}\n'"
        pkgs = "Package,Version,Source\n"
        pkgs += Container.run_docker_cmd(sha_id, cmd)
    return pkgs, sha_id
예제 #3
0
def rpm_pkgs(img_name):
    """get rpm packages installed in an image."""
    with Container(img_name) as sha_id:
        pkgs = "Package,Version,License\n"
        pkgs += Container.run_docker_cmd(
            sha_id, "rpm -qa --qf '%{NAME},%{VERSION},%{LICENSE}\n'")
    return pkgs, sha_id
예제 #4
0
def apt_licenses(img_name):
    """get licenses of apt pkgs from an image."""
    pkg_lcs = {}
    with Container(img_name) as sha_id:
        cmd = "bash -c \"for pkg in `dpkg-query -Wf '${Package}\n'`; do lc=`cat /usr/share/doc/$pkg/copyright 2>/dev/null`; echo PKG_START $pkg PKG_END,LFILE_START $lc LFILE_END; done\""  # noqa: E501
        pkgs = Container.run_docker_cmd(sha_id, cmd)
    pkg = re.findall("PKG_START(.*?)PKG_END", pkgs)
    license = re.findall("LFILE_START(.*?)LFILE_END", pkgs)
    pkg_lcs = {
        p.strip(): _search_spdx(v.strip())
        for p, v in zip(pkg, license)
    }
    pkgs = "Package,License\n"
    for pkg, lc in pkg_lcs.items():
        pkgs += "{0},{1}\n".format(pkg, lc)
    return pkgs, sha_id
예제 #5
0
def test_run_docker_cmd(monkeypatch):
    monkeypatch.setattr("subprocess.run", fake_subprocess_run())
    out = Container.run_docker_cmd(Img.sha, Img.cmd)
    assert out == Img.output
예제 #6
0
def test_stop_rm_container(monkeypatch):
    monkeypatch.setattr("subprocess.run", fake_subprocess_run())
    assert Container.stop_rm_container(Img.sha) is None
예제 #7
0
def test_deamonize_image(monkeypatch):
    """test deamonize image."""
    monkeypatch.setattr("subprocess.run", fake_subprocess_run())
    out = Container.deamonize_image(Img.name)
    assert out == Img.sha
예제 #8
0
def test_get_image(monkeypatch):
    """test get image."""
    monkeypatch.setattr("subprocess.run", fake_subprocess_run())
    img_sha = Container.get_image(Img.name)
    assert img_sha == Img.sha