-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_repo.py
79 lines (59 loc) · 1.66 KB
/
update_repo.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import subprocess
import tempfile
import shutil
import os
import re
import glob
INCLUDE_DIR = "include"
SOURCE_DIR = "src"
STB_REPO_URL = "https://github.com/nothings/stb.git"
STB_SOURCE = {
"stb_ds.h": INCLUDE_DIR,
"stb_sprintf.h": INCLUDE_DIR,
}
SDS_REPO_URL = "https://github.com/jcorporation/sds.git"
SDS_SOURCE = {
"sds.h": INCLUDE_DIR,
"sdsalloc.h": INCLUDE_DIR,
"sds.c": SOURCE_DIR,
}
def copy_source(source_dir: str, target_dir_dict: dict[str, str]):
for name, target_dir in target_dir_dict.items():
src = os.path.join(source_dir, name)
dst = os.path.join(target_dir, name)
shutil.copyfile(src, dst)
def clone_temp(repo_url: str) -> str:
path = tempfile.mkdtemp()
subprocess.check_call(
["git", "clone", "--depth", "1", repo_url, path],
)
return path
def get_project_name(clone_url: str) -> str:
idx = clone_url.rfind("/")
name = clone_url[idx + 1 :]
if "." in name:
idx = name.find(".")
return name[:idx]
return name
def update_repo(clone_url: str, target_dir_dict: dict[str, str]):
name = get_project_name(clone_url)
clone_dir = clone_temp(clone_url)
copy_source(clone_dir, target_dir_dict)
src = os.path.join(clone_dir, "LICENSE")
dst = os.path.join(SOURCE_DIR, f"{name}.LICENSE")
shutil.copyfile(src, dst)
def apply_patchs():
patchs = glob.glob("patchs/*.patch")
subprocess.check_call(
[
"git",
"apply",
*patchs,
],
)
def main():
update_repo(STB_REPO_URL, STB_SOURCE)
update_repo(SDS_REPO_URL, SDS_SOURCE)
apply_patchs()
if __name__ == "__main__":
main()