validate:launcher: Add an option to output HTML if commonmark is installed

This commit is contained in:
Thibault Saunier 2019-04-05 23:05:20 -03:00 committed by Thibault Saunier
parent f7517e503c
commit 8639dc528c
2 changed files with 26 additions and 2 deletions

View file

@ -125,6 +125,7 @@ class Test(Loggable):
self.number = ""
self.workdir = workdir
self.allow_flakiness = False
self.html_log = None
self.clean()
@ -234,6 +235,18 @@ class Test(Loggable):
self.out.flush()
self.out.close()
if self.options.html:
self.html_log = os.path.splitext(self.logfile)[0] + '.html'
import commonmark
parser = commonmark.Parser()
with open(self.logfile) as f:
ast = parser.parse(f.read())
renderer = commonmark.HtmlRenderer()
html = renderer.render(ast)
with open(self.html_log, 'w') as f:
f.write(html)
self.out = None
def _get_file_content(self, file_name):
@ -542,7 +555,7 @@ class Test(Loggable):
def get_logfile_repr(self):
if not self.options.redirect_logs:
return "\n Log: %s" % self.logfile
return "\n Log: %s" % (self.html_log if self.html_log else self.logfile)
return ""
@ -628,6 +641,7 @@ class Test(Loggable):
if self.options.gdb:
signal.signal(signal.SIGINT, self.previous_sigint_handler)
self.finalize_logfiles()
message = None
end = "\n"
if self.result != Result.PASSED:
@ -643,7 +657,6 @@ class Test(Loggable):
if message is not None:
printc(message, color=utils.get_color_for_result(
self.result), end=end)
self.finalize_logfiles()
if self.options.dump_on_failure:
if self.result is not Result.PASSED:

View file

@ -224,6 +224,7 @@ class LauncherConfig(Loggable):
self.sync_all = False
self.check_bugs_status = False
self.retry_on_failures = False
self.html = False
def cleanup(self):
"""
@ -326,6 +327,14 @@ class LauncherConfig(Loggable):
Colors.FAIL)
return False
if self.html:
try:
import commonmark
except ImportError:
printc("You want to output html logs but commonmark not found. Install it"
" with `pip install commonmark` and try again.", Colors.FAIL)
return False
return True
def set_http_server_dir(self, path):
@ -483,6 +492,8 @@ class LauncherConfig(Loggable):
" at the same time")
parser.add_argument('--retry-on-failures', dest="retry_on_failures", action="store_true",
help="Re-try tests that produce unexpected results")
parser.add_argument('--html', dest="html", action="store_true",
help="Write logs as html")
dir_group = parser.add_argument_group(
"Directories and files to be used by the launcher")
dir_group.add_argument("-M", "--main-dir", dest="main_dir",