Skip to content

Commit 6482637

Browse files
committed
make versions.json builder
1 parent 6750660 commit 6482637

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

.root/generate_site_assets.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import json, os
22

33
output_dir = "site/jsons"
4+
45
background_assets_dir = "site/assets/screens/backgrounds"
56
styles_assets_dir = "site/assets/themes"
67

8+
repo_file = "repo.json"
9+
10+
# Collectors
11+
712
def get_files(path: str, extensions: list):
813
returned_files = []
914
if not os.path.isdir(path):
@@ -15,23 +20,60 @@ def get_files(path: str, extensions: list):
1520
returned_files.append(f)
1621
return returned_files
1722

18-
1923
def save_to_json(data, filename: str):
2024
os.makedirs(output_dir, exist_ok=True)
2125
filepath = os.path.join(output_dir, filename)
2226
with open(filepath, "w", encoding="utf-8") as f:
2327
json.dump(data, f, indent=2, ensure_ascii=False)
2428

29+
# Generators
30+
2531
def generate_backgrounds():
2632
files = get_files(background_assets_dir, ["gif", "png", "jpeg", "jpg"])
2733
save_to_json(files, "backgrounds.json")
2834

29-
3035
def generate_themes():
3136
files = get_files(styles_assets_dir, ["css"])
3237
save_to_json(files, "themes.json")
3338

39+
def generate_versions():
40+
save_to_json(get_pathes(), "versions.json")
41+
42+
# Just contain artifacts
43+
44+
def get_pathes():
45+
pathes = []
46+
versions = {}
47+
with open(repo_file, "r", encoding="utf-8") as f:
48+
data = json.load(f)
49+
collect_paths(data, [], pathes)
50+
for path in pathes:
51+
print(f"Checking versions for ../{path}")
52+
if os.path.exists(path):
53+
versions[path] = get_versions(path)
54+
else: print("Not found")
55+
print(versions)
56+
return versions
57+
58+
def collect_paths(data, current_path, result):
59+
if isinstance(data, dict):
60+
if "url" in data:
61+
result.append("/".join(current_path))
62+
else:
63+
for key, value in data.items():
64+
collect_paths(value, current_path + [key], result)
65+
66+
# Check versions in repo
67+
68+
def get_versions(path):
69+
if os.path.isdir(path):
70+
return os.listdir(path)
71+
72+
# Main
3473

3574
if __name__ == "__main__":
75+
# For versions on page
76+
generate_versions()
77+
# For themes
3678
generate_backgrounds()
3779
generate_themes()

0 commit comments

Comments
 (0)