aboutsummaryrefslogtreecommitdiff
path: root/utils/update-db.py
blob: 71da6f8d53dbed1a231378e3dfe74a9f45e882fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import argparse
import asyncio
import logging
import os
import pathlib
import shutil


logger = logging.getLogger()
logger.setLevel(logging.DEBUG)


async def add_package(dest: pathlib.Path, pkg_name: str, key: str) -> None:
    # logger.debug("%s %s %s", dest, pkg_name, key)
    await (
        await asyncio.create_subprocess_exec(
            "/usr/bin/repo-add",
            str(dest),
            pkg_name,
            "-s",
            "-v",
            "-R",
            "-k",
            key,
            stdout=None,
        )
    ).wait()


async def main(remote_dest: str, repo_base_name: str, sign_key: str) -> None:
    cwd = pathlib.Path(os.getcwd()).resolve()
    remote_dest = pathlib.Path(remote_dest).resolve()
    database_dest = cwd.joinpath(repo_base_name).resolve()

    for file in os.listdir(str(remote_dest)):
        logger.debug("Copy file: %s", file)
        shutil.copy(str(remote_dest.joinpath(file).joinpath()), str(cwd))

    for file in os.listdir(str(remote_dest)):
        if ".pkg.tar.zst" in file and not file.endswith(".sig"):
            await add_package(database_dest, file, sign_key)


if __name__ == "__main__":
    parser = argparse.ArgumentParser("update-db.py")
    parser.add_argument("cwd")
    parser.add_argument("basename")
    parser.add_argument("sign_key")

    args_ = parser.parse_args()

    try:
        import coloredlogs

        coloredlogs.install(
            logging.DEBUG,
            fmt="%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s",
        )
    except ModuleNotFoundError:
        logging.basicConfig(
            level=logging.DEBUG,
            format="%(asctime)s - %(levelname)s - %(funcName)s - %(lineno)d - %(message)s",
        )
    asyncio.run(main(args_.cwd, args_.basename, args_.sign_key))