Merge pull request #15 from elias-pschernig/master

[wmlunits] Fix error logging.
This commit is contained in:
Alexander van Gessel 2013-05-25 02:54:38 -07:00
commit cdb68d0c8a
3 changed files with 25 additions and 15 deletions

View File

@ -106,6 +106,8 @@ def main(folder):
error_kind = "wml error" error_kind = "wml error"
elif "<PARSE ERROR>" in text: elif "<PARSE ERROR>" in text:
error_kind = "parse error" error_kind = "parse error"
elif "<TIMEOUT ERROR>" in text:
error_kind = "timeout"
source = [] source = []
@ -144,9 +146,9 @@ def main(folder):
lines_count = 0 lines_count = 0
for line in text.splitlines(): for line in text.splitlines():
line = line.strip() line = line.strip()
if line in ["<INTERNAL ERROR>", "<WML ERROR>", "<PARSE ERROR>"]: if line in ["<INTERNAL ERROR>", "<WML ERROR>", "<PARSE ERROR>", "<TIMEOUT ERROR>"]:
htmlerr.write("<p>") htmlerr.write("<p>")
elif line in ["</INTERNAL ERROR>", "</WML ERROR>", "</PARSE ERROR>"]: elif line in ["</INTERNAL ERROR>", "</WML ERROR>", "</PARSE ERROR>", "</TIMEOUT ERROR>"]:
htmlerr.write("</p>") htmlerr.write("</p>")
else: else:
err_html = postprocess(line) err_html = postprocess(line)

View File

@ -21,11 +21,12 @@ class WMLError(Exception):
Catch this exception to retrieve the first error message from Catch this exception to retrieve the first error message from
the parser. the parser.
""" """
def __init__(self, parser, message): def __init__(self, parser = None, message = None):
self.line = parser.parser_line if parser:
self.wml_line = parser.last_wml_line self.line = parser.parser_line
self.message = message self.wml_line = parser.last_wml_line
self.preprocessed = parser.preprocessed self.message = message
self.preprocessed = parser.preprocessed
def __str__(self): def __str__(self):
r = "WMLError:\n" r = "WMLError:\n"

View File

@ -21,6 +21,8 @@ import unit_tree.html_output as html_output
import unit_tree.overview import unit_tree.overview
import unit_tree.wiki_output as wiki_output import unit_tree.wiki_output as wiki_output
TIMEOUT = 5
def copy_images(): def copy_images():
print("Recolorizing pictures.") print("Recolorizing pictures.")
image_collector.copy_and_color_images(options.output) image_collector.copy_and_color_images(options.output)
@ -130,19 +132,24 @@ def list_contents():
options.data_dir, options.data_dir,
options.transdir) options.transdir)
#print("remote", local.wesnoth) #print("remote", local.wesnoth)
local.wesnoth.parser.parse_text(wml, defines) try:
q.put(local.wesnoth) local.wesnoth.parser.parse_text(wml, defines)
q.put(("ok", local.wesnoth))
except Exception as e:
q.put(("e", e))
q = multiprocessing.Queue() q = multiprocessing.Queue()
p = multiprocessing.Process(target = f, args = (options, wml, defines, q)) p = multiprocessing.Process(target = f, args = (options, wml, defines, q))
p.start() p.start()
try: try:
local.wesnoth = q.get(timeout = 5) s, local.wesnoth = q.get(timeout = TIMEOUT)
except Queue.Empty: except Queue.Empty:
p.terminate() p.terminate()
raise raise
#print("local", local.wesnoth) #print("local", s, local.wesnoth)
p.join() p.join()
if s == "e":
raise local.wesnoth
def get_version(addon): def get_version(addon):
try: try:
@ -222,9 +229,9 @@ def list_contents():
sys.stdout.write("failed\n") sys.stdout.write("failed\n")
except Queue.Empty as e: except Queue.Empty as e:
ef = open(logname, "w") ef = open(logname, "w")
ef.write("<PARSE ERROR>\n") ef.write("<TIMEOUT ERROR>\n")
ef.write(str(e)) ef.write("Failed to parse the WML within " + str(TIMEOUT) + " seconds.")
ef.write("</PARSE ERROR>\n") ef.write("</TIMEOUT ERROR>\n")
ef.close() ef.close()
sys.stdout.write("failed\n") sys.stdout.write("failed\n")
finally: finally: