|
2 | 2 |
|
3 | 3 | import sys, re, os.path, cgi, stat, math
|
4 | 4 | from optparse import OptionParser
|
5 |
| -from color import getColorizer |
| 5 | +from color import getColorizer, dummyColorizer |
6 | 6 |
|
7 | 7 | class tblCell(object):
|
8 | 8 | def __init__(self, text, value = None, props = None):
|
@@ -34,7 +34,9 @@ class table(object):
|
34 | 34 | def_italic = False
|
35 | 35 | def_text="-"
|
36 | 36 |
|
37 |
| - def __init__(self, caption = None): |
| 37 | + def __init__(self, caption = None, format=None): |
| 38 | + self.format = format |
| 39 | + self.is_markdown = self.format == 'markdown' |
38 | 40 | self.columns = {}
|
39 | 41 | self.rows = []
|
40 | 42 | self.ridx = -1;
|
@@ -248,7 +250,7 @@ def getValue(self, name, *elements):
|
248 | 250 |
|
249 | 251 | def consolePrintTable(self, out):
|
250 | 252 | columns = self.layoutTable()
|
251 |
| - colrizer = getColorizer(out) |
| 253 | + colrizer = getColorizer(out) if not self.is_markdown else dummyColorizer(out) |
252 | 254 |
|
253 | 255 | if self.caption:
|
254 | 256 | out.write("%s%s%s" % ( os.linesep, os.linesep.join(self.reformatTextValue(self.caption)), os.linesep * 2))
|
@@ -288,19 +290,40 @@ def consolePrintRow2(self, out, r, columns):
|
288 | 290 | i += colspan
|
289 | 291 |
|
290 | 292 | #print content
|
291 |
| - for ln in range(row.minheight): |
292 |
| - i = 0 |
293 |
| - while i < len(row.cells): |
294 |
| - if i > 0: |
295 |
| - out.write(" ") |
296 |
| - cell = row.cells[i] |
297 |
| - column = columns[i] |
298 |
| - if cell is None: |
299 |
| - out.write(" " * column.minwidth) |
300 |
| - i += 1 |
| 293 | + if self.is_markdown: |
| 294 | + out.write("|") |
| 295 | + for c in row.cells: |
| 296 | + text = ' '.join(self.getValue('text', c) or []) |
| 297 | + out.write(text + "|") |
| 298 | + out.write(os.linesep) |
| 299 | + else: |
| 300 | + for ln in range(row.minheight): |
| 301 | + i = 0 |
| 302 | + while i < len(row.cells): |
| 303 | + if i > 0: |
| 304 | + out.write(" ") |
| 305 | + cell = row.cells[i] |
| 306 | + column = columns[i] |
| 307 | + if cell is None: |
| 308 | + out.write(" " * column.minwidth) |
| 309 | + i += 1 |
| 310 | + else: |
| 311 | + self.consolePrintLine(cell, row, column, out) |
| 312 | + i += self.getValue("colspan", cell) |
| 313 | + if self.is_markdown: |
| 314 | + out.write("|") |
| 315 | + out.write(os.linesep) |
| 316 | + |
| 317 | + if self.is_markdown and row.props.get('header', False): |
| 318 | + out.write("|") |
| 319 | + for th in row.cells: |
| 320 | + align = self.getValue("align", th) |
| 321 | + if align == 'center': |
| 322 | + out.write(":-:|") |
| 323 | + elif align == 'right': |
| 324 | + out.write("--:|") |
301 | 325 | else:
|
302 |
| - self.consolePrintLine(cell, row, column, out) |
303 |
| - i += self.getValue("colspan", cell) |
| 326 | + out.write("---|") |
304 | 327 | out.write(os.linesep)
|
305 | 328 |
|
306 | 329 | def consolePrintLine(self, cell, row, column, out):
|
@@ -588,7 +611,7 @@ def getStdoutFilename():
|
588 | 611 | return ""
|
589 | 612 |
|
590 | 613 | def detectHtmlOutputType(requestedType):
|
591 |
| - if requestedType == "txt": |
| 614 | + if requestedType in ['txt', 'markdown']: |
592 | 615 | return False
|
593 | 616 | elif requestedType in ["html", "moinwiki"]:
|
594 | 617 | return True
|
@@ -701,7 +724,7 @@ def formatValue(val, metric, units = None):
|
701 | 724 | exit(0)
|
702 | 725 |
|
703 | 726 | parser = OptionParser()
|
704 |
| - parser.add_option("-o", "--output", dest="format", help="output results in text format (can be 'txt', 'html' or 'auto' - default)", metavar="FMT", default="auto") |
| 727 | + 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") |
705 | 728 | parser.add_option("-m", "--metric", dest="metric", help="output metric", metavar="NAME", default="gmean")
|
706 | 729 | parser.add_option("-u", "--units", dest="units", help="units for output values (s, ms (default), mks, ns or ticks)", metavar="UNITS", default="ms")
|
707 | 730 | (options, args) = parser.parse_args()
|
@@ -750,7 +773,7 @@ def formatValue(val, metric, units = None):
|
750 | 773 |
|
751 | 774 | for arg in args:
|
752 | 775 | tests = testlog_parser.parseLogFile(arg)
|
753 |
| - tbl = table(arg) |
| 776 | + tbl = table(arg, format=options.format) |
754 | 777 | tbl.newColumn("name", "Name of Test", align = "left")
|
755 | 778 | tbl.newColumn("value", metrix_table[options.metric][0], align = "center", bold = "true")
|
756 | 779 |
|
|
0 commit comments