-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_contents.py
67 lines (55 loc) · 1.71 KB
/
index_contents.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
import glob
import json
import os
import shutil
import yaml
def read_yaml_description(file_path):
"""
Extract the schema description from the yaml file
"""
with open(file_path, 'r') as file:
data = yaml.safe_load(file)
description = data.get('description')
return description
# List of all schemas
files_list = glob.glob("schemas/**/*.yaml", recursive=True)
tpls = {}
schema_metadata = {}
for f in files_list:
print(f)
f_split = f.split("/")
basename, ext = os.path.splitext(f)
f_split = basename.split("/")
f_split
namespace = f_split[1]
tpl_name = f_split[-1]
description = read_yaml_description(f)
url = os.path.relpath(f, "schemas/")
if namespace not in schema_metadata:
schema_metadata[namespace] = {}
schema_metadata[namespace][tpl_name] = {
"namespace": namespace,
"schema": f_split[-1],
"url": url,
"description": description
}
tpls[basename] = {
"project": namespace,
"url": url,
"description": description
}
new_file = f"public/{url}"
os.makedirs(os.path.dirname(new_file), exist_ok=True)
shutil.copyfile(f, new_file)
print(json.dumps(schema_metadata, indent=4))
print("Namespaces: ", list(schema_metadata.keys()))
# Namespaces list
with open("public/namespaces.json", "w") as outfile:
json.dump(list(schema_metadata.keys()), outfile, indent=4)
# Schema list for each namespace
for namespace in schema_metadata:
with open(f"public/{namespace}/schemas.json", "w") as outfile:
json.dump(schema_metadata[namespace], outfile, indent=4)
# List of all schemas
with open("public/list.json", "w") as outfile:
json.dump(tpls, outfile, indent=4)