This repository has been archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathbuild_filelist.py
60 lines (48 loc) · 1.52 KB
/
build_filelist.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
#!/usr/bin/python
# Author: Stephen Leitnick
# Date: February 12, 2019
from json import dump
from subprocess import check_output
FILELIST_NAME = "filelist.json"
FILELIST_MIN_NAME = "filelist.min.json"
FILELIST_INDENT = 2
FETCH_PREFIX = "https://raw.githubusercontent.com/Sleitnick/AeroGameFramework/master/"
def write_json_to_file(filename, json_obj, indent):
with open(filename, "w") as f:
dump(json_obj, f, indent=FILELIST_INDENT if indent else None)
# Find dictionary with the same name within the given array:
def find(ar, name):
a = [x for x in ar if x["name"] == name]
if len(a) > 0:
return a[0]
else:
return None
if __name__ == "__main__":
print("Building file list...")
paths_data = []
cur_branch = check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("utf-8").strip()
all_files = check_output(["git", "ls-tree", "--name-only", "-r", cur_branch, "src"]).decode("utf-8")
paths = all_files.split("\n")
for path in paths:
path_array = path.split("/")
current = paths_data
for p in path_array:
item = find(current, p)
if not item:
is_file = p.endswith(".lua")
item = {
"type": "file" if is_file else "directory",
"name": p
}
if not is_file:
item["children"] = []
current.append(item)
if item["type"] == "directory":
current = item["children"]
filelist_data = {
"url": FETCH_PREFIX,
"paths": paths_data[0]
}
write_json_to_file(FILELIST_NAME, filelist_data, True)
write_json_to_file(FILELIST_MIN_NAME, filelist_data, False)
print("File list built")