generated from notofonts/noto-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.py
130 lines (112 loc) · 3.89 KB
/
template.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
import chevron
import os
from glob import glob
from sh import git
import re
from urllib.parse import quote
from fontTools.ttLib import TTFont
from gftools.utils import font_sample_text
from pathlib import Path
class FileTreeMaker(object):
def _recurse(self, parent_path, file_list, prefix, output_buf, level):
if len(file_list) == 0:
return
else:
file_list.sort(key=lambda f: os.path.isfile(os.path.join(parent_path, f)))
for idx, sub_path in enumerate(file_list):
full_path = os.path.join(parent_path, sub_path)
if os.path.isdir(full_path):
output_buf.append(f'<li class="li-{level}">{sub_path}<ul>')
self._recurse(
full_path,
os.listdir(full_path),
"",
output_buf,
level + 1,
)
elif os.path.isfile(full_path):
output_buf.append(f'<li><a href="{full_path}"> {sub_path}</a></li>')
output_buf.append("%s </ul>" % (prefix))
def make(self, root):
self.root = root
buf = ["<ul>"]
path_parts = self.root.rsplit(os.path.sep, 1)
self._recurse(self.root, os.listdir(self.root), "", buf, 0)
output_str = "\n".join(buf)
return output_str
commit = git("rev-parse", "--short", "HEAD")
github_repo = os.environ.get("GITHUB_REPOSITORY", "")
repo_url = (
os.environ.get("GITHUB_SERVER_URL", "https://github.com/") + "/" + github_repo
)
raw_url = "https://raw.githubusercontent.com/" + github_repo + "/gh-pages/badges"
shields_url = "https://img.shields.io/endpoint?url=" + quote(raw_url, safe="")
families = []
for family in glob("fonts/*"):
basename = os.path.basename(family)
fname = re.sub(r"([a-z])([A-Z])", r"\1 \2", basename)
fonttree = FileTreeMaker().make(family)
fontbakery = []
for result in glob(f"out/fontbakery/*{basename}*html"):
result = result[4:]
if "unhinted" in result:
fontbakery.append({
"name": "Noto fonts, unhinted",
"path": result
})
elif "hinted" in result:
fontbakery.append({
"name": "Noto fonts, hinted",
"path": result
})
elif "googlefonts" in result:
fontbakery.append({
"name": "Google Fonts",
"path": result
})
fontbakery = list(reversed(sorted(fontbakery, key=lambda l:l["name"])))
diffenator = []
for result in glob(f"out/qa/{basename}/**/diffenator.html", recursive=True):
diffenator.append({
"name": "Diffenator report, " + Path(result).parent.stem,
"path": result[4:],
})
families.append({
"name": fname,
"fonttree": fonttree,
"fontbakery": fontbakery,
"diffenator": diffenator
})
unhinted = glob("fonts/*/unhinted/ttf/*.ttf")
grab_a_font = None
if unhinted:
grab_a_font = unhinted[0]
sample_text = ""
if grab_a_font:
sample_text = font_sample_text(TTFont(grab_a_font))
sample_text = " ".join(sample_text)
sample_text += " " + sample_text
with open("README.md") as readme:
lines = readme.read()
m = re.match("^# (.*)", lines)
if not m:
project = "Unknown Project"
else:
project = m[1]
print(families)
with open("scripts/index.html", "r") as f:
with open("out/index.html", "w") as fw:
fw.write(
chevron.render(
f,
{
"families": families,
"repo_url": repo_url,
"commit": commit,
"project": project,
"shields_url": shields_url,
"a_font": grab_a_font,
"sample_text": sample_text
},
)
)