wmlunits: More cleanup
This commit is contained in:
parent
b7b4efcf76
commit
743d8c2278
2 changed files with 77 additions and 91 deletions
|
@ -12,13 +12,13 @@ import unit_tree.helpers as helpers
|
|||
import wesnoth.wmlparser3 as wmlparser3
|
||||
|
||||
|
||||
pics_location = "../../pics"
|
||||
PICS_LOCATION = "../../pics"
|
||||
|
||||
html_entity_horizontal_bar = '―'
|
||||
html_entity_multiplication_sign = '×'
|
||||
html_entity_figure_dash = '‒'
|
||||
HTML_ENTITY_HORIZONTAL_BAR = '―'
|
||||
HTML_ENTITY_MULTIPLICATION_SIGN = '×'
|
||||
HTML_ENTITY_FIGURE_DASH = '‒'
|
||||
|
||||
html_header = '''
|
||||
HTML_HEADER = '''
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html class="no-js wmlunits %(classes)s" lang="en">
|
||||
|
@ -40,7 +40,7 @@ html_header = '''
|
|||
|
||||
<div id="main">'''.strip()
|
||||
|
||||
top_bar = '''
|
||||
TOP_BAR = '''
|
||||
<div id="nav" role="banner">
|
||||
<div class="centerbox">
|
||||
|
||||
|
@ -76,7 +76,7 @@ top_bar = '''
|
|||
|
||||
<div id="content" role="main">'''.strip()
|
||||
|
||||
html_footer = '''
|
||||
HTML_FOOTER = '''
|
||||
</div> <!-- end content -->
|
||||
|
||||
<div class="centerbox"><div id="lastmod">%(generation_note)s</div></div>
|
||||
|
@ -94,7 +94,7 @@ html_footer = '''
|
|||
</body></html>
|
||||
'''.strip()
|
||||
|
||||
html_clear_floats = '<div class="reset"></div>'
|
||||
HTML_CLEAR_FLOATS = '<div class="reset"></div>'
|
||||
|
||||
all_written_html_files = []
|
||||
|
||||
|
@ -373,7 +373,7 @@ class HTMLOutput:
|
|||
langlist = list(languages.keys())
|
||||
langlist.sort()
|
||||
|
||||
write(top_bar % {"path" : "../../"})
|
||||
write(TOP_BAR % {"path" : "../../"})
|
||||
|
||||
write('<div class="navbar">')
|
||||
write('<ul class="navbar" role="menu">')
|
||||
|
@ -414,7 +414,7 @@ class HTMLOutput:
|
|||
write('</li>')
|
||||
|
||||
def add_menuitem_placeholder():
|
||||
write('<li>' + html_entity_horizontal_bar + '</li>')
|
||||
write('<li>' + HTML_ENTITY_HORIZONTAL_BAR + '</li>')
|
||||
|
||||
def end_menu(is_table_container=False):
|
||||
if not is_table_container:
|
||||
|
@ -601,10 +601,10 @@ class HTMLOutput:
|
|||
error_message("Warning: No picture %s for unit %s.\n" %
|
||||
(image, u.get_text_val("id")))
|
||||
picname = icpic.id_name
|
||||
image = os.path.join(pics_location, picname)
|
||||
image = os.path.join(PICS_LOCATION, picname)
|
||||
if portrait:
|
||||
picname = image_collector.add_image(self.addon, portrait, no_tc=True)
|
||||
portrait = os.path.join(pics_location, picname)
|
||||
portrait = os.path.join(PICS_LOCATION, picname)
|
||||
return image, portrait
|
||||
|
||||
def get_abilities(self, u):
|
||||
|
@ -670,7 +670,7 @@ class HTMLOutput:
|
|||
pic = image_collector.add_image("general",
|
||||
"../../../images/misc/leader-crown.png",
|
||||
no_tc=True)
|
||||
crownimage = cleanurl(os.path.join(pics_location, pic))
|
||||
crownimage = cleanurl(os.path.join(PICS_LOCATION, pic))
|
||||
ms = None
|
||||
for row in range(len(rows)):
|
||||
write("<tr>\n")
|
||||
|
@ -779,7 +779,7 @@ class HTMLOutput:
|
|||
for attack in attacks:
|
||||
n = T(attack, "number")
|
||||
x = T(attack, "damage")
|
||||
x = "%s %s %s " % (cleantext(x, quote=False), html_entity_multiplication_sign, cleantext(n, quote=False))
|
||||
x = "%s %s %s " % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
|
||||
write(x)
|
||||
|
||||
r = T(attack, "range")
|
||||
|
@ -809,7 +809,7 @@ class HTMLOutput:
|
|||
def write_units_tree(self, grouper, title, add_parents):
|
||||
html_title = cleantext(title)
|
||||
|
||||
self.output.write(html_header % {
|
||||
self.output.write(HTML_HEADER % {
|
||||
"path": "../../",
|
||||
"title": html_title,
|
||||
"classes": "wmlunits-tree",
|
||||
|
@ -824,10 +824,10 @@ class HTMLOutput:
|
|||
|
||||
self.write_units()
|
||||
|
||||
self.output.write(html_clear_floats)
|
||||
self.output.write(HTML_CLEAR_FLOATS)
|
||||
self.output.write('</div>')
|
||||
|
||||
self.output.write(html_footer % {
|
||||
self.output.write(HTML_FOOTER % {
|
||||
"generation_note": "Last updated on " + time.ctime() + "."})
|
||||
|
||||
return n
|
||||
|
@ -866,7 +866,7 @@ class HTMLOutput:
|
|||
display_name = cleantext(uname)
|
||||
|
||||
self.output = output
|
||||
write(html_header % {
|
||||
write(HTML_HEADER % {
|
||||
"path": "../../",
|
||||
"title": display_name,
|
||||
"classes": "wmlunits-unit"})
|
||||
|
@ -908,7 +908,7 @@ class HTMLOutput:
|
|||
if not description:
|
||||
description = clean_uval("unit_description")
|
||||
if not description:
|
||||
description = html_entity_horizontal_bar
|
||||
description = HTML_ENTITY_HORIZONTAL_BAR
|
||||
write('<p>%s</p>\n' % re.sub('\n', '\n<br />', description))
|
||||
|
||||
write('<h2>Information</h2>\n')
|
||||
|
@ -930,7 +930,7 @@ class HTMLOutput:
|
|||
write('<a href="%s">%s</a>' % (link, cleantext(name, quote=False)))
|
||||
have_advances = True
|
||||
if not have_advances:
|
||||
write(html_entity_figure_dash)
|
||||
write(HTML_ENTITY_FIGURE_DASH)
|
||||
write('</td></tr>\n')
|
||||
|
||||
# Advances-to list
|
||||
|
@ -956,7 +956,7 @@ class HTMLOutput:
|
|||
write('<a href="%s">%s</a>' % (link, cleantext(name, quote=False)))
|
||||
have_advances = True
|
||||
if not have_advances:
|
||||
write(html_entity_figure_dash)
|
||||
write(HTML_ENTITY_FIGURE_DASH)
|
||||
write('</td></tr>\n')
|
||||
|
||||
attributes = [
|
||||
|
@ -987,7 +987,7 @@ class HTMLOutput:
|
|||
if len(anames):
|
||||
write('<td class="val">' + cleantext(', '.join(anames), quote=False) + '</td>')
|
||||
else:
|
||||
write('<td class="val">' + html_entity_figure_dash + '</td>')
|
||||
write('<td class="val">' + HTML_ENTITY_FIGURE_DASH + '</td>')
|
||||
write('</tr>\n')
|
||||
|
||||
write('</table>\n')
|
||||
|
@ -995,7 +995,7 @@ class HTMLOutput:
|
|||
# Write info about attacks.
|
||||
write('<h2>%s <small>(damage %s count)</small></h2>\n' %
|
||||
(cleantext(_("unit help^Attacks", "wesnoth-help"), quote=False),
|
||||
html_entity_multiplication_sign))
|
||||
HTML_ENTITY_MULTIPLICATION_SIGN))
|
||||
write('<table class="unitinfo attacks">\n')
|
||||
write('<colgroup><col class="col0" /><col class="col1" /><col class="col2" /><col class="col3" /></colgroup>')
|
||||
attacks = self.get_recursive_attacks(unit)
|
||||
|
@ -1013,9 +1013,9 @@ class HTMLOutput:
|
|||
if not image_add.ipath:
|
||||
error_message("Error: No attack icon '%s' found for '%s'.\n" % (
|
||||
icon, uid))
|
||||
icon = os.path.join(pics_location, "unit$elves-wood$shaman.png")
|
||||
icon = os.path.join(PICS_LOCATION, "unit$elves-wood$shaman.png")
|
||||
else:
|
||||
icon = os.path.join(pics_location, image_add.id_name)
|
||||
icon = os.path.join(PICS_LOCATION, image_add.id_name)
|
||||
write("<td><img src=\"%s\" alt=\"(image)\"/></td>" % cleanurl(icon))
|
||||
|
||||
write("<td><b>%s</b>" % cleantext(aname, quote=False))
|
||||
|
@ -1025,7 +1025,7 @@ class HTMLOutput:
|
|||
|
||||
n = attack.get_text_val("number")
|
||||
x = attack.get_text_val("damage")
|
||||
x = '%s %s %s' % (cleantext(x, quote=False), html_entity_multiplication_sign, cleantext(n, quote=False))
|
||||
x = '%s %s %s' % (cleantext(x, quote=False), HTML_ENTITY_MULTIPLICATION_SIGN, cleantext(n, quote=False))
|
||||
write("<td><i>%s</i>" % x)
|
||||
|
||||
t = T(attack, "type")
|
||||
|
@ -1089,7 +1089,7 @@ class HTMLOutput:
|
|||
else:
|
||||
write("<td></td>")
|
||||
picname = image_collector.add_image(self.addon, ricon, no_tc=True)
|
||||
icon = os.path.join(pics_location, picname)
|
||||
icon = os.path.join(PICS_LOCATION, picname)
|
||||
write('<td><img src="%s" alt="(icon)" /></td>\n' % (icon, ))
|
||||
write('<th>%s</th><td class="%s">%s</td>\n' % (cleantext(_(rid), quote=False), ' '.join(resist_classes), resist_str))
|
||||
if row % 2 == 1:
|
||||
|
@ -1229,7 +1229,7 @@ class HTMLOutput:
|
|||
if defense_rating:
|
||||
classes_defense.append('rating-' + defense_rating)
|
||||
if move_cost == '-':
|
||||
move_cost = html_entity_figure_dash
|
||||
move_cost = HTML_ENTITY_FIGURE_DASH
|
||||
else:
|
||||
move_cost = cleantext(move_cost, quote=False)
|
||||
|
||||
|
@ -1237,7 +1237,7 @@ class HTMLOutput:
|
|||
picname = image_collector.add_image(self.addon,
|
||||
"terrain/" + ticon + ".png",
|
||||
no_tc=True)
|
||||
icon = os.path.join(pics_location, picname)
|
||||
icon = os.path.join(PICS_LOCATION, picname)
|
||||
write('<td><img src="%s" alt="(icon)" /></td>\n' % cleanurl(icon))
|
||||
write('<td>%s</td><td class="%s"><i>%s</i></td><td class="%s"><i>%s</i></td>\n' %
|
||||
(cleantext(tname, quote=False),
|
||||
|
@ -1250,10 +1250,10 @@ class HTMLOutput:
|
|||
|
||||
write('</div>') # columns parent
|
||||
|
||||
self.output.write(html_clear_floats)
|
||||
self.output.write(HTML_CLEAR_FLOATS)
|
||||
write('</div>') # main
|
||||
|
||||
self.output.write(html_footer % {
|
||||
self.output.write(HTML_FOOTER % {
|
||||
"generation_note": "Last updated on " + time.ctime() + "."})
|
||||
|
||||
|
||||
|
@ -1374,7 +1374,7 @@ def html_postprocess_file(filename, isocode, batchlist):
|
|||
chtml += '<li><a title="%s" href="%s" role="menuitem">%s</a></li>\n' % (
|
||||
cleantext(campname), url, cleantext(campname, quote=False))
|
||||
if i == 0 and cids[1]:
|
||||
chtml += '<li>%s</li>\n' % html_entity_horizontal_bar
|
||||
chtml += '<li>%s</li>\n' % HTML_ENTITY_HORIZONTAL_BAR
|
||||
|
||||
eids = [[], []]
|
||||
for addon in batchlist:
|
||||
|
@ -1398,7 +1398,7 @@ def html_postprocess_file(filename, isocode, batchlist):
|
|||
ehtml += '<li><a title="%s" href="%s" role="menuitem">%s</a></li>\n' % (
|
||||
cleantext(eraname), url, cleantext(eraname, quote=False))
|
||||
if i == 0 and eids[1]:
|
||||
ehtml += '<li>%s</li>\n' % html_entity_horizontal_bar
|
||||
ehtml += '<li>%s</li>\n' % HTML_ENTITY_HORIZONTAL_BAR
|
||||
|
||||
f = open(filename, "r+b")
|
||||
html = f.read().decode("utf8")
|
||||
|
|
|
@ -7,22 +7,22 @@ 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 = html_output.cleantext("Build Report for " + name)
|
||||
generation_note = "Last updated on " + time.ctime() + "."
|
||||
|
||||
w(html_output.html_header % locals())
|
||||
|
||||
w(html_output.top_bar % locals())
|
||||
|
||||
|
||||
w(html_output.HTML_HEADER % locals())
|
||||
|
||||
w(html_output.TOP_BAR % locals())
|
||||
|
||||
w('<div class="overview">')
|
||||
|
||||
|
||||
eras = addon.get("eras", [])
|
||||
|
||||
w("<h2>" + html_output.cleantext(name) + "</h2>")
|
||||
w('<h2>' + html_output.cleantext(name) + '</h2>')
|
||||
|
||||
if eras:
|
||||
w("<h3>Eras</h3><ul>")
|
||||
|
@ -30,55 +30,46 @@ def write_addon_overview(folder, addon):
|
|||
epath = html_output.cleanurl(os.path.join("en_US", era["id"] + ".html"))
|
||||
w('<li><a href="' + epath + '">' + html_output.cleantext(era["name"], quote=False) + '</a></li>')
|
||||
w("</ul>")
|
||||
|
||||
|
||||
campaigns = addon.get("campaigns", [])
|
||||
if campaigns:
|
||||
w("<h3>Campaigns</h3><ul>")
|
||||
w('<h3>Campaigns</h3><ul>')
|
||||
for campaign in campaigns:
|
||||
cpath = os.path.join("en_US", campaign["id"] + ".html")
|
||||
w('<li><a href="' + cpath + '">' + html_output.cleantext(campaign["name"], quote=False) + '</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><b>Warnings or errors were found: <a href="error.html">log</a></b></p>')
|
||||
w('<p><a href="../overview.html">Back to the full report</a></p>')
|
||||
w("</div>")
|
||||
|
||||
|
||||
w('</div> <!-- overview -->')
|
||||
|
||||
w(html_output.html_footer % locals())
|
||||
|
||||
|
||||
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")
|
||||
def w(x):
|
||||
out.write(x + "\n")
|
||||
|
||||
path = ""
|
||||
title = "Database Build Report"
|
||||
generation_note = "generated on " + time.ctime()
|
||||
classes = "wmlunits-report"
|
||||
|
||||
w(html_output.html_header % locals())
|
||||
|
||||
w(html_output.top_bar % locals())
|
||||
w(html_output.HTML_HEADER % locals())
|
||||
|
||||
w(html_output.TOP_BAR % locals())
|
||||
|
||||
w('<h1>Database Build Report</h1>')
|
||||
|
||||
|
||||
w('<div class="overview">')
|
||||
|
||||
w('<table class="overview">')
|
||||
w("<thead>")
|
||||
w("<tr><th>")
|
||||
w("Addon")
|
||||
w("</th><th>")
|
||||
w("Output Files")
|
||||
w("</th><th>")
|
||||
w("Error Log")
|
||||
w("</th></tr>")
|
||||
w("</thead>")
|
||||
|
||||
w("<tbody>")
|
||||
w('<thead><tr><th>Addon</th><th>Output Files</th><th>Error Log</th></tr></thead>')
|
||||
w('<tbody>')
|
||||
count = 0
|
||||
total_n = 0
|
||||
total_error_logs = 0
|
||||
|
@ -86,15 +77,15 @@ def main(folder):
|
|||
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("/")
|
||||
|
@ -105,7 +96,6 @@ def main(folder):
|
|||
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:
|
||||
|
@ -116,9 +106,9 @@ def main(folder):
|
|||
error_kind = "parse error"
|
||||
elif "<TIMEOUT ERROR>" in text:
|
||||
error_kind = "timeout"
|
||||
|
||||
|
||||
source = []
|
||||
|
||||
|
||||
def postprocess(line):
|
||||
if line == "WMLError:": return ""
|
||||
if line == "?": return ""
|
||||
|
@ -137,10 +127,10 @@ def main(folder):
|
|||
|
||||
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 = ""
|
||||
|
@ -148,7 +138,7 @@ def main(folder):
|
|||
row = row.strip()
|
||||
out += row + "<br />"
|
||||
return out
|
||||
|
||||
|
||||
htmlerr = open(error_html, "w")
|
||||
htmlerr.write("<html><body>")
|
||||
lines_count = 0
|
||||
|
@ -163,31 +153,27 @@ def main(folder):
|
|||
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>' % (html_output.cleanurl(error_name), error_kind, lines_count))
|
||||
w("</td></tr>")
|
||||
|
||||
|
||||
count += 1
|
||||
w("</tbody>")
|
||||
|
||||
w("<tfoot>")
|
||||
w("<tr><th scope=\"row\">")
|
||||
w("Total (for %d addons):" % count)
|
||||
w("</th><td>")
|
||||
w(str(total_n))
|
||||
w("</td><td>")
|
||||
w(str(total_error_logs) + " (" + str(total_lines) + " lines)")
|
||||
w("</td></tr>")
|
||||
w("</tfoot>")
|
||||
w("<tfoot><tr>")
|
||||
w('<th scope="row">Total (for %d addons):</th>' % count)
|
||||
w('<td>' + str(total_n) + '</td>')
|
||||
w('<td>' + str(total_error_logs) + ' (' + str(total_lines) + ' lines)</td>')
|
||||
w('</tr></tfoot>')
|
||||
|
||||
w('</table>')
|
||||
|
||||
w("</table>")
|
||||
|
||||
w('</div> <!-- overview -->')
|
||||
|
||||
w(html_output.html_footer % locals())
|
||||
|
||||
w(html_output.HTML_FOOTER % locals())
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1])
|
||||
|
|
Loading…
Add table
Reference in a new issue