-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_versions_file.py
51 lines (35 loc) · 1.09 KB
/
gen_versions_file.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
import sys
from os import listdir, getcwd
from os.path import isdir, join
from json import dumps
SCRIPT_NAME = sys.argv[0]
GIT_RAW_URL = "https://raw.githubusercontent.com/clausmarian/cc_obamos/main/"
def skip(filename):
return not (filename.startswith(".") or filename == SCRIPT_NAME)
def get_files(root):
res = list()
for file in list(filter(skip, listdir(root))):
path = join(root, file)
if isdir(path):
res += get_files(path)
else:
res.append(path)
return res
def get_raw_url(path):
return join(GIT_RAW_URL, path)
def make_file_object(path):
return {"path": path, "url": get_raw_url(path)}
def main(version):
cwd = getcwd()
files = list(
map(lambda path: make_file_object(path[len(cwd) + 1 :]), get_files(cwd))
)
json = dumps({"version": version, "files": files}, indent=4)
print(json)
with open('versions.json', 'w') as file:
file.write(json)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Version not provided!", file=sys.stderr)
else:
main(sys.argv[1])