Commit 91c0b137 authored by Alexander Alekhin's avatar Alexander Alekhin Committed by GitHub

Merge pull request #9922 from alalek:ts_markdown_table

ts(misc): support tables exporting in markdown format
parents 1f214d23 9e9881aa
...@@ -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,6 +290,13 @@ class table(object): ...@@ -288,6 +290,13 @@ class table(object):
i += colspan i += colspan
#print content #print content
if self.is_markdown:
out.write("|")
for c in row.cells:
text = ' '.join(self.getValue('text', c) or [])
out.write(text + "|")
out.write(os.linesep)
else:
for ln in range(row.minheight): for ln in range(row.minheight):
i = 0 i = 0
while i < len(row.cells): while i < len(row.cells):
...@@ -301,6 +310,20 @@ class table(object): ...@@ -301,6 +310,20 @@ class table(object):
else: else:
self.consolePrintLine(cell, row, column, out) self.consolePrintLine(cell, row, column, out)
i += self.getValue("colspan", cell) 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:
out.write("---|")
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