#!/usr/bin/env python import glob, os, sys, time, re sys.path.append(os.path.join(os.path.dirname(__file__), "..")) import html_output def write_addon_overview(folder, addon): out = open(os.path.join(folder, "index.html"), "wb") def w(x): out.write(x.encode("utf8") + "\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('
') eras = addon.get("eras", []) w("

" + name + "

") if eras: w("

Eras

") campaigns = addon.get("campaigns", []) if campaigns: w("

Campaigns

") w("
") if os.path.exists(os.path.join(folder, "error.log")): w('

Warnings or errors were found: log

') w('

back to overview

') w("
") w('
') w(html_output.html_footer % locals()) def main(folder): out = open(os.path.join(folder, "overview.html"), "wb") def w(x): out.write(x.encode("utf8") + "\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('
') w('') w("") 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('") count += 1 w("") w("
") w("Addon") w("") w("Output Files") w("") w("Error Log") w("
') w('' + name + '') w('') w(str(n)) w('') if os.path.exists(error_log): text = open(error_log).read() error_kind = "warnings" if "" in text: error_kind = "internal error" elif "" in text: error_kind = "wml error" elif "" in text: error_kind = "parse error" elif "" 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) + "
" 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 + "
" return out htmlerr = open(error_html, "w") htmlerr.write("") lines_count = 0 for line in text.splitlines(): line = line.strip() if line in ["", "", "", ""]: htmlerr.write("

") elif line in ["", "", "", ""]: htmlerr.write("

") else: err_html = postprocess(line) lines_count += err_html.count("") total_lines += lines_count total_error_logs += 1 w('%s (%d lines)' % (error_name, error_kind, lines_count)) w("
") w("Total (for %d addons):" % count) w("") w(str(total_n)) w("") w(str(total_error_logs) + " (" + str(total_lines) + " lines)") w("
") w('
') w(html_output.html_footer % locals()) if __name__ == "__main__": main(sys.argv[1])