forked from Cog-Creators/Red-Index
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
47 lines (37 loc) · 1.09 KB
/
parser.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
import yaml
import sys
from hashlib import sha1
from pathlib import Path
CACHE = Path("cache")
def sha1_digest(url):
return sha1(url.encode('utf-8')).hexdigest()
def get_clean_url(url):
branch = ""
if "@" in url:
url, branch = url.split("@")
if url.endswith("/"):
url = url[:-1]
return url, branch
if __name__ == "__main__":
infile = sys.argv[1]
outfile = sys.argv[2]
with open(infile) as f:
data = yaml.safe_load(f.read())
sh = ""
repos = []
if data["approved"]:
repos.extend(data["approved"])
if data["unapproved"]:
repos.extend(data["unapproved"])
for r in repos:
url, branch = get_clean_url(r)
if branch:
sha = sha1_digest(f"{url}@{branch}")
dest = CACHE / Path(sha)
sh += f"./git-retry.sh clone --depth=1 {url} --branch {branch} --single-branch {dest}\n"
else:
sha = sha1_digest(url)
dest = CACHE / Path(sha)
sh += f"./git-retry.sh clone --depth=1 {url} {dest}\n"
with open(outfile, "w") as f:
f.write(sh)