aboutsummaryrefslogtreecommitdiff
path: root/mirror.py
blob: 14051e2d3ab8b23a8a4240139e1d24063c6317e5 (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
import toml
import pathlib
import os
import subprocess

__here__ = pathlib.Path(__file__).parent

with open("mirrors.toml", "r") as f:
    repositories = toml.load(f)

for path in repositories.keys():
    local_path = pathlib.Path(path)
    local_path.mkdir(exist_ok=True, parents=True)
    primary_url = repositories[path]["primary"]
    secondary_urls = repositories[path]["secondary"]
    os.chdir(str(local_path))
    if not pathlib.Path("git-daemon-export-ok").is_file():
        subprocess.run(["git", "init", "--bare"])
        subprocess.run(["git", "remote", "add", "origin", primary_url])
        pathlib.Path("git-daemon-export-ok").touch()
    subprocess.run(["git", "remote", "update"])
    subprocess.run(["git", "fetch", "origin", "'*:*'"])
    for url in secondary_urls:
        print(url)
        subprocess.run(["git", "push", url, "--all"])