🗝
summary refs log tree commit diff
path: root/packages/init.py
blob: d556548115905bf4bcb38be340a3c8e055090dec (plain) (blame)
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
import shlex
import subprocess

from commia.prelude import *
from commia.util import read_ini

packages = read_ini("packages/aur.ini")["default"]

ini = Path("packages/aur.ini").read_text()
git_ignore = Path("packages/.gitignore").read_text()

for name, fix in packages.items():
    if not Path(f"packages/{name}").exists():
        print(f"cloning {name}")
        run_check(
            [
                "git",
                "clone",
                f"https://aur.archlinux.org/{name}.git",
                f"packages/{name}",
            ]
        )
        if name.endswith("-git"):
            for line in Path(f"packages/{name}/PKGBUILD").read_text().splitlines():
                if not line.startswith("pkgver="):
                    continue
                ver = shlex.split(line[len("pkgver=") :])[0]
                ini = ini.replace(f"{name} = ?", f"{name} = {ver}")
                break
        else:
            if fix == "?":
                commit = subprocess.check_output(
                    ["git", "rev-parse", "HEAD"], cwd=f"packages/{name}", text=True
                ).strip()
                ini = ini.replace(f"{name} = ?", f"{name} = {commit}")
            else:
                run_check(["git", "checkout", fix], cwd=f"packages/{name}")
        if not name in git_ignore:
            git_ignore += f"{name}\n"
            Path("packages/.gitignore").write_text(git_ignore)

Path("packages/aur.ini").write_text(ini)