Esempio n. 1
0
async def create_db_from_json_files(
    input_path: Path, output_path: Path, db_type: defaults.RepoDbType = defaults.RepoDbType.DEFAULT
) -> None:
    """Create a repository database from a list of JSON files found in a directory

    Parameters
    ----------
    input_path: Path
        A directory from which to read JSON files
    output_path: Path
        A file to which to write a repository database
    db_type: defaults.RepoDbType
        A member of the defaults.RepoDbType IntEnum to define what type of repository database to create:
        Either defaults.RepoDbType.DEFAULT for the default .db database or defaults.RepoDbType.FILES for the .files
        database (defaults to defaults.RepoDbType.DEFAULT)
    """

    repodbfile = convert.RepoDbFile()
    with files._write_db_file(path=output_path) as database:
        async for path in files._json_files_in_directory(path=input_path):  # pragma: no cover
            model = await files._read_pkgbase_json_file(path)
            await files._stream_package_base_to_db(
                db=database,
                model=model,
                repodbfile=repodbfile,
                db_type=db_type,
            )
Esempio n. 2
0
async def test_repodbfile_render_desc_template() -> None:
    repodbfile = convert.RepoDbFile()
    assert repodbfile
    output = io.StringIO()
    assert not output.getvalue()
    await repodbfile.render_desc_template(
        model=models.PackageDesc(
            arch="foo",
            base="foo",
            builddate=1,
            csize=1,
            desc="foo",
            filename="foo",
            isize=1,
            license=["foo"],
            md5sum="foo",
            name="foo",
            packager="foo",
            pgpsig="foo",
            sha256sum="foo",
            url="foo",
            version="foo",
        ),
        output=output,
    )
    assert output.getvalue()
Esempio n. 3
0
async def test_repodbfile_render_files_template() -> None:
    repodbfile = convert.RepoDbFile()
    assert repodbfile
    output = io.StringIO()
    assert not output.getvalue()
    await repodbfile.render_files_template(
        model=models.Files(files=["foo", "bar"]),
        output=output,
    )
    assert output.getvalue()
Esempio n. 4
0
async def test__stream_package_base_to_db(
    model: models.OutputPackageBase,
    db_type: defaults.RepoDbType,
    empty_file: Path,
) -> None:
    with files._write_db_file(path=empty_file) as database:
        await files._stream_package_base_to_db(
            db=database,
            model=model,
            repodbfile=convert.RepoDbFile(),
            db_type=db_type,
        )
Esempio n. 5
0
def test_repodbfile__init() -> None:
    assert convert.RepoDbFile()