-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
executable file
·118 lines (95 loc) · 3.91 KB
/
main.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*
#
# Florent Jacquet <[email protected]>
#
import sys
import os
import unicodedata
import re
import json
from collections import OrderedDict
from datetime import datetime
from jinja2 import FileSystemLoader, Environment
from toolchain import Toolchain, ToolchainEncoder, ToolchainSet, OBSOLETE_ARCHITECTURES
def to_json(value):
return json.dumps(value, cls=ToolchainEncoder)
def slugify(value):
""" Note: This was modified from django.utils.text slugify """
value = str(value)
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
value = re.sub('[^\w\s-]', '', value).strip().lower()
value = re.sub('[-\s]+', '-', value)
return str(value)
jinja_env = Environment(loader=FileSystemLoader(os.getcwd()))
jinja_env.filters['slugify'] = slugify
jinja_env.filters['to_json'] = to_json
TOOLCHAINS_DIR = "/srv/gitlabci/www/downloads"
WWW_DIR = "/srv/gitlabci/www"
def generate():
start_time = datetime.now()
toolchains = ToolchainSet()
main_release = "releases"
toolchains_path = os.path.join(TOOLCHAINS_DIR, main_release)
toolchain_list = []
# Find all toolchains
for a in os.scandir(os.path.join(toolchains_path, "toolchains")):
try:
toolchain_list += os.scandir(os.path.join(toolchains_path, "toolchains",
a.name, 'available_toolchains'))
except FileNotFoundError:
pass
# Iterate over all toolchains
for toolchain in sorted([e for e in toolchain_list if e.is_file() and not e.name.startswith('.') and not e.name.endswith(".sha256")], key=lambda t: t.name):
t = Toolchain(toolchain.name)
arch_path = os.path.join(toolchains_path, "toolchains", t.arch)
t.set_test_result(arch_path, t.name)
tarball_dir = os.path.join(toolchains_path, "toolchains", t.arch,
"tarballs")
if os.path.exists(os.path.join(tarball_dir, t.name + ".tar.xz")):
tarball_name = t.name + ".tar.xz"
else:
tarball_name = t.name + ".tar.bz2"
t.set_tarball_name(tarball_name)
with open(os.path.join(toolchains_path, "toolchains", t.arch,
"summaries", t.name + ".csv")) as f:
t.set_summary(f)
toolchains.add(main_release, t)
for p in ['index', 'status', 'faq', 'news']:
template = jinja_env.get_template("templates/%s.jinja" % p)
html = template.render(
toolchains=toolchains,
obsolete_archs=OBSOLETE_ARCHITECTURES,
datetime=datetime,
start_time=start_time
)
with open(os.path.join(WWW_DIR, p + ".html"), 'w') as f:
f.write(html)
print("Page generated in", os.path.join(WWW_DIR, p + ".html"))
template = jinja_env.get_template("templates/arch_listing.jinja")
for a in toolchains.arch_list(main_release):
page_name = "%s_%s" % (main_release, a)
html = template.render(
release=main_release,
arch=a,
toolchains=toolchains,
obsolete_archs=OBSOLETE_ARCHITECTURES,
datetime=datetime,
start_time=start_time
)
with open(os.path.join(WWW_DIR, page_name + ".html"), 'w') as f:
f.write(html)
print("Page generated in", os.path.join(WWW_DIR, page_name + ".html"))
template = jinja_env.get_template("templates/toolchains.jinja")
page_name = "toolchains"
html = template.render(
release=main_release,
toolchains=toolchains,
datetime=datetime,
start_time=start_time
)
with open(os.path.join(WWW_DIR, page_name + ".html"), 'w') as f:
f.write(html)
print("Page generated in", os.path.join(WWW_DIR, page_name + ".html"))
if __name__ == "__main__":
generate()