-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate.py
executable file
·137 lines (103 loc) · 3.94 KB
/
generate.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
from datetime import datetime, timezone
from jinja2 import Environment, FileSystemLoader
import tables
import sys
def handle_socs():
socs = {}
for soc in tables.socs:
soc["core_names"] = []
if "announce" not in soc or soc["announce"]["time"] is None:
soc["announce"] = {"time": " "}
aarch32 = False
for core in soc["cores"]:
try:
core["implementer_name"] = tables.cpu_cores[
core["implementer"]]["name"]
except KeyError:
print(
f"Missing name for {hex(core['implementer'])} core"
" implementer!",
file=sys.stderr
)
sys.exit(-1)
# try to check core part-revision-variant
# (like X-Gene 1/2/3)
core_prv = f'{hex(core["part"])}-{core["revision"]}-' \
f'{core["variant"]}'
try:
soc["core_names"].append(
tables.cpu_cores[core["implementer"]]["cores"][
core_prv]["name"]
)
aarch32 = tables.cpu_cores[
core["implementer"]]["cores"][core_prv]["aarch32"]
except KeyError:
try:
soc["core_names"].append(
tables.cpu_cores[core["implementer"]]["cores"][
hex(core["part"])]["name"]
)
aarch32 = tables.cpu_cores[
core["implementer"]]["cores"][
hex(core["part"])]["aarch32"]
except KeyError:
print(
f"Missing name for {hex(core['part'])} for "
f"{hex(core['implementer'])}!",
file=sys.stderr
)
sys.exit(-1)
if aarch32 == "to be set":
aarch32 = ""
elif aarch32 is False:
aarch32 = "NO"
core["aarch32"] = aarch32
socs[f"{soc['vendor']}-{soc['name']}"] = soc
sorted_socs = []
for key in sorted(socs.keys()):
sorted_socs.append(socs[key])
return sorted_socs
def handle_cpu_features():
sorted_cpu_features = {}
for feature in tables.cpu_features:
feature_data = tables.cpu_features[feature]
if not feature_data['archv'] in sorted_cpu_features:
sorted_cpu_features[feature_data['archv']] = []
sorted_cpu_features[feature_data['archv']].append(feature)
cpu_features = {}
for archv in sorted(sorted_cpu_features):
for feature in sorted_cpu_features[archv]:
cpu_features[feature] = tables.cpu_features[feature]
return cpu_features
def handle_cpu_cores():
cpu_cores = {}
for implementer in tables.cpu_cores:
cpu_cores[implementer] = {}
for core in tables.cpu_cores[implementer]['cores']:
try:
cpu_cores[implementer][int(core, base=16)] = tables.cpu_cores[
implementer]['cores'][core]
except ValueError:
pass
return cpu_cores
def generate_html_file(socs, cpu_features, cpu_cores):
file_loader = FileSystemLoader("templates")
env = Environment(loader=file_loader,
trim_blocks=True,
lstrip_blocks=True)
template = env.get_template("arm-socs.html.j2")
output = template.render(
generate_time=datetime.strftime(datetime.now(timezone.utc),
"%d %B %Y %H:%M"),
socs=socs,
cpu_features=cpu_features,
cpu_cores=cpu_cores,
git_repo="arm-socs-table",
)
print(output)
if __name__ == "__main__":
socs = handle_socs()
cpu_cores = handle_cpu_cores()
cpu_features = handle_cpu_features()
generate_html_file(socs, cpu_features, cpu_cores)