Commit 9e9881aa authored by Alexander Alekhin's avatar Alexander Alekhin

ts(misc): support tables exporting in markdown format

basic support only (no symbol escapes/sanitizing)
parent cca99bf8
...@@ -30,7 +30,7 @@ if __name__ == "__main__": ...@@ -30,7 +30,7 @@ if __name__ == "__main__":
exit(0) exit(0)
parser = OptionParser() parser = OptionParser()
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto") parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html', 'markdown' or 'auto' - default)", metavar="FMT", default="auto")
parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean") parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms") parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms")
parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None) parser.add_option("-f", "--filter", dest="filter", help="regex to filter tests", metavar="REGEX", default=None)
...@@ -142,7 +142,7 @@ if __name__ == "__main__": ...@@ -142,7 +142,7 @@ if __name__ == "__main__":
getter_score = metrix_table["score"][1] if options.calc_score else None getter_score = metrix_table["score"][1] if options.calc_score else None
getter_p = metrix_table[options.metric + "%"][1] if options.calc_relatives else None getter_p = metrix_table[options.metric + "%"][1] if options.calc_relatives else None
getter_cr = metrix_table[options.metric + "$"][1] if options.calc_cr else None getter_cr = metrix_table[options.metric + "$"][1] if options.calc_cr else None
tbl = table(metrix_table[options.metric][0]) tbl = table(metrix_table[options.metric][0], options.format)
# header # header
tbl.newColumn("name", "Name of Test", align = "left", cssclass = "col_name") tbl.newColumn("name", "Name of Test", align = "left", cssclass = "col_name")
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import sys, re, os.path, cgi, stat, math import sys, re, os.path, cgi, stat, math
from optparse import OptionParser from optparse import OptionParser
from color import getColorizer from color import getColorizer, dummyColorizer
class tblCell(object): class tblCell(object):
def __init__(self, text, value = None, props = None): def __init__(self, text, value = None, props = None):
...@@ -34,7 +34,9 @@ class table(object): ...@@ -34,7 +34,9 @@ class table(object):
def_italic = False def_italic = False
def_text="-" def_text="-"
def __init__(self, caption = None): def __init__(self, caption = None, format=None):
self.format = format
self.is_markdown = self.format == 'markdown'
self.columns = {} self.columns = {}
self.rows = [] self.rows = []
self.ridx = -1; self.ridx = -1;
...@@ -248,7 +250,7 @@ class table(object): ...@@ -248,7 +250,7 @@ class table(object):
def consolePrintTable(self, out): def consolePrintTable(self, out):
columns = self.layoutTable() columns = self.layoutTable()
colrizer = getColorizer(out) colrizer = getColorizer(out) if not self.is_markdown else dummyColorizer(out)
if self.caption: if self.caption:
out.write("%s%s%s" % ( os.linesep, os.linesep.join(self.reformatTextValue(self.caption)), os.linesep * 2)) out.write("%s%s%s" % ( os.linesep, os.linesep.join(self.reformatTextValue(self.caption)), os.linesep * 2))
...@@ -288,19 +290,40 @@ class table(object): ...@@ -288,19 +290,40 @@ class table(object):
i += colspan i += colspan
#print content #print content
for ln in range(row.minheight): if self.is_markdown:
i = 0 out.write("|")
while i < len(row.cells): for c in row.cells:
if i > 0: text = ' '.join(self.getValue('text', c) or [])
out.write(" ") out.write(text + "|")
cell = row.cells[i] out.write(os.linesep)
column = columns[i] else:
if cell is None: for ln in range(row.minheight):
out.write(" " * column.minwidth) i = 0
i += 1 while i < len(row.cells):
if i > 0:
out.write(" ")
cell = row.cells[i]
column = columns[i]
if cell is None:
out.write(" " * column.minwidth)
i += 1
else:
self.consolePrintLine(cell, row, column, out)
i += self.getValue("colspan", cell)
if self.is_markdown:
out.write("|")
out.write(os.linesep)
if self.is_markdown and row.props.get('header', False):
out.write("|")
for th in row.cells:
align = self.getValue("align", th)
if align == 'center':
out.write(":-:|")
elif align == 'right':
out.write("--:|")
else: else:
self.consolePrintLine(cell, row, column, out) out.write("---|")
i += self.getValue("colspan", cell)
out.write(os.linesep) out.write(os.linesep)
def consolePrintLine(self, cell, row, column, out): def consolePrintLine(self, cell, row, column, out):
...@@ -588,7 +611,7 @@ def getStdoutFilename(): ...@@ -588,7 +611,7 @@ def getStdoutFilename():
return "" return ""
def detectHtmlOutputType(requestedType): def detectHtmlOutputType(requestedType):
if requestedType == "txt": if requestedType in ['txt', 'markdown']:
return False return False
elif requestedType in ["html", "moinwiki"]: elif requestedType in ["html", "moinwiki"]:
return True return True
...@@ -701,7 +724,7 @@ if __name__ == "__main__": ...@@ -701,7 +724,7 @@ if __name__ == "__main__":
exit(0) exit(0)
parser = OptionParser() parser = OptionParser()
parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto") parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html', 'markdown' or 'auto' - default)", metavar="FMT", default="auto")
parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean") parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms") parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
...@@ -750,7 +773,7 @@ if __name__ == "__main__": ...@@ -750,7 +773,7 @@ if __name__ == "__main__":
for arg in args: for arg in args:
tests = testlog_parser.parseLogFile(arg) tests = testlog_parser.parseLogFile(arg)
tbl = table(arg) tbl = table(arg, format=options.format)
tbl.newColumn("name", "Name of Test", align = "left") tbl.newColumn("name", "Name of Test", align = "left")
tbl.newColumn("value", metrix_table[options.metric][0], align = "center", bold = "true") tbl.newColumn("value", metrix_table[options.metric][0], align = "center", bold = "true")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment