-
-
Notifications
You must be signed in to change notification settings - Fork 989
/
overview.py
executable file
·182 lines (142 loc) · 5.88 KB
/
overview.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python2
import glob, os, sys, time, re
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from . import html_output
def write_addon_overview(folder, addon):
out = open(os.path.join(folder, "index.html"), "w")
def w(x): out.write(x + "\n")
name = addon["name"]
path = "../"
title = name + " Overview"
generation_note = "generated on " + time.ctime()
w(html_output.html_header % locals())
w(html_output.top_bar % locals())
w('<div class="overview">')
eras = addon.get("eras", [])
w("<h2>" + name + "</h2>")
if eras:
w("<h3>Eras</h3><ul>")
for era in eras:
epath = os.path.join("en_US", era["id"] + ".html")
w('<li><a href="' + epath + '">' + era["name"] + '</a></li>')
w("</ul>")
campaigns = addon.get("campaigns", [])
if campaigns:
w("<h3>Campaigns</h3><ul>")
for campaign in campaigns:
cpath = os.path.join("en_US", campaign["id"] + ".html")
w('<li><a href="' + cpath + '">' + campaign["name"] + '</a></li>')
w("</ul>")
w("<div>")
if os.path.exists(os.path.join(folder, "error.log")):
w('<p><b>Warnings or errors were found: <a href="error.html"/>log</a></b></p>')
w('<p><a href="../overview.html">back to overview</a></p>')
w("</div>")
w('</div> <!-- overview -->')
w(html_output.html_footer % locals())
def main(folder):
out = open(os.path.join(folder, "overview.html"), "w")
def w(x): out.write(x + "\n")
path = ""
title = "Wesnoth Unit Database Overview"
generation_note = "generated on " + time.ctime()
w(html_output.html_header % locals())
w(html_output.top_bar % locals())
w('<div class="overview">')
w('<table class="overview">')
w("<tr><th>")
w("Addon")
w("</th><th>")
w("Output Files")
w("</th><th>")
w("Error Log")
w("</th></tr>")
count = 0
total_n = 0
total_error_logs = 0
total_lines = 0
for f in sorted(glob.glob(os.path.join(folder, "*"))):
if not os.path.isdir(f): continue
if f.endswith("/pics"): continue
error_log = os.path.abspath(os.path.join(f, "error.log"))
error_html = os.path.abspath(os.path.join(f, "error.html"))
try:
n = len(os.listdir(os.path.join(f, "en_US")))
except OSError:
n = 0
total_n += n
name = f[len(folder):].lstrip("/")
error_name = os.path.join(name, "error.html")
w('<tr><td>')
w('<a href="' + os.path.join(name, "index.html") + '">' + name + '</a>')
w('</td><td>')
w(str(n))
w('</td><td>')
if os.path.exists(error_log):
text = open(error_log).read()
error_kind = "warnings"
if "<INTERNAL ERROR>" in text:
error_kind = "internal error"
elif "<WML ERROR>" in text:
error_kind = "wml error"
elif "<PARSE ERROR>" in text:
error_kind = "parse error"
elif "<TIMEOUT ERROR>" in text:
error_kind = "timeout"
source = []
def postprocess(line):
if line == "WMLError:": return ""
if line == "?": return ""
if line == "Preprocessor error:": return ""
if line.startswith("Automatically found a possible data directory"): return ""
if line.startswith("Overriding data directory with"): return ""
if line == "'SKIP_CORE' defined.": return ""
if re.match("added .* defines.", line): return ""
if line.startswith("skipped 'data/core'"): return ""
if line.startswith("preprocessing specified resource:"): return ""
mo = re.match(r"\d+ /tmp(?:/wmlparser_.*?/|/)(.*\.cfg).*", line)
if mo:
source.append("/tmp/" + mo.group(1))
return ""
mo = re.match(".*--preprocess-defines(.*)", line)
if mo: return "Defines: " + mo.group(1) + "<br />"
for s in source:
line = line.replace(s, "WML")
line = line.replace("included from WML:1", "")
rows = line.replace("included from", "\n included from").splitlines()
out = ""
for row in rows:
row = row.strip()
out += row + "<br />"
return out
htmlerr = open(error_html, "w")
htmlerr.write("<html><body>")
lines_count = 0
for line in text.splitlines():
line = line.strip()
if line in ["<INTERNAL ERROR>", "<WML ERROR>", "<PARSE ERROR>", "<TIMEOUT ERROR>"]:
htmlerr.write("<p>")
elif line in ["</INTERNAL ERROR>", "</WML ERROR>", "</PARSE ERROR>", "</TIMEOUT ERROR>"]:
htmlerr.write("</p>")
else:
err_html = postprocess(line)
lines_count += err_html.count("<br")
htmlerr.write(err_html)
htmlerr.write("</body></html>")
total_lines += lines_count
total_error_logs += 1
w('<a class="error" href="%s">%s (%d lines)</a>' % (error_name, error_kind, lines_count))
w("</td></tr>")
count += 1
w("<tr><td>")
w("Total (for %d addons):" % count)
w("</td><td>")
w(str(total_n))
w("</td><td>")
w(str(total_error_logs) + " (" + str(total_lines) + " lines)")
w("</td></tr>")
w("</table>")
w('</div> <!-- overview -->')
w(html_output.html_footer % locals())
if __name__ == "__main__":
main(sys.argv[1])