[Piglit] [PATCH V3 04/10] piglit-summary-py: Use the new summary class to generate HTML
Dylan Baker
baker.dylan.c at gmail.com
Tue May 28 13:17:49 PDT 2013
Drops almost all of the code used in this file, all of that
functionality is now handled in the summary class. Instead, the majority
of this file is just the argparse instance, and a few short lines
calling the new summary class.
V2: Fixes the -l/--list syntax
V3: Changes the listfile syntax to match the newline seperated format
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
framework/summary.py | 7 +-
piglit-summary-html.py | 261 ++++---------------------------------------------
2 files changed, 21 insertions(+), 247 deletions(-)
diff --git a/framework/summary.py b/framework/summary.py
index b25f952..1ce3fa7 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -268,7 +268,7 @@ def sanitizePath(path):
"""
Helper function to remove illegal characters from the names
"""
- return filter(lambda s: s.isalnum() or s == '_', path.repalce('/', '__')) \
+ return filter(lambda s: s.isalnum() or s == '_', path.replace('/', '__')) \
+ '.html'
@@ -290,7 +290,7 @@ class Result:
self.options = result['options']
self.glxinfo = result['glxinfo']
self.lspci = result['lspci']
- self.time = result.get('time_elapsed', 'N/A')
+ self.time = result.get('time_elapsed', 'skip')
self.name = result['name']
self.tests = result['tests']
@@ -770,6 +770,5 @@ class NewSummary:
file.write(index.render(results=HTMLIndex(self, page),
page=page,
colnum=len(self.results),
- links=pages,
- exclude=exclude))
+ links=pages))
file.close()
diff --git a/piglit-summary-html.py b/piglit-summary-html.py
index 2752b9f..dc10b7d 100755
--- a/piglit-summary-html.py
+++ b/piglit-summary-html.py
@@ -22,228 +22,16 @@
# DEALINGS IN THE SOFTWARE.
import argparse
-import cgi
-import os, os.path
import sys
+import shutil
+import os.path as path
-sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
-import framework.core as core
-import framework.summary
+import framework.summary as summary
+from framework.core import checkDir
+sys.path.append(path.dirname(path.realpath(sys.argv[0])))
-#############################################################################
-##### Auxiliary functions
-#############################################################################
-def testPathToHtmlFilename(path):
- return 'test_' + filter(lambda s: s.isalnum() or s == '_', path.replace('/', '__')) + '.html'
-
-
-#############################################################################
-##### HTML output
-#############################################################################
-
-def readfile(filename):
- f = open(filename, "r")
- s = f.read()
- f.close()
- return s
-
-def writefile(filename, text):
- f = open(filename, "w")
- f.write(text.encode('utf-8'))
- f.close()
-
-templatedir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates')
-Result = readfile(os.path.join(templatedir, 'result.html'))
-ResultDetail = readfile(os.path.join(templatedir, 'result_detail.html'))
-ResultList = readfile(os.path.join(templatedir, 'result_list.html'))
-ResultListItem = readfile(os.path.join(templatedir, 'result_listitem.html'))
-ResultMString = readfile(os.path.join(templatedir, 'result_mstring.html'))
-
-Index = readfile(os.path.join(templatedir, 'index.html'))
-IndexTestrunB = readfile(os.path.join(templatedir, 'index_testrunb.html'))
-IndexTestrunBHref = readfile(os.path.join(templatedir, 'index_testrunb_href.html'))
-IndexGroup = readfile(os.path.join(templatedir, 'index_group.html'))
-IndexGroupTestrun = readfile(os.path.join(templatedir, 'index_group_testrun.html'))
-IndexTest = readfile(os.path.join(templatedir, 'index_test.html'))
-IndexTestTestrun = readfile(os.path.join(templatedir, 'index_test_testrun.html'))
-
-Testrun = readfile(os.path.join(templatedir, 'testrun.html'))
-
-SummaryPages = {
- 'all': 'index.html',
- 'changes': 'changes.html',
- 'problems': 'problems.html',
- 'regressions': 'regressions.html',
- 'fixes': 'fixes.html',
- 'skipped': 'skipped.html'
-}
-
-def buildResultListItem(detail):
- return ResultListItem % { 'detail': buildDetailValue(detail) }
-
-def buildDetailValue(detail):
- if type(detail) == list:
- items = map(buildResultListItem, detail)
- return ResultList % { 'items': "".join(items) }
-
- elif isinstance(detail, basestring):
- return ResultMString % { 'detail': cgi.escape(detail) }
-
- return cgi.escape(str(detail))
-
-
-def buildDetails(testResult):
- details = []
- for name in testResult:
- assert(isinstance(name, basestring))
-
- if name == 'result':
- continue
-
- value = buildDetailValue(testResult[name])
- details += [(name, value)]
-
- details.sort(lambda a, b: len(a[1])-len(b[1]))
-
- text = ''
- for name, value in details:
- text += ResultDetail % locals()
-
- return text
-
-
-def writeResultHtml(test, testResult, filename):
- path = test.path
- name = test.name
- status = testResult.status
-
- if 'result' in testResult:
- result = testResult['result']
- else:
- result = '?'
-
- details = buildDetails(testResult)
-
- writefile(filename, Result % locals())
-
-def writeTestrunHtml(testrun, filename):
- detail_keys = [
- key
- for key in testrun.__dict__.keys()
- if key in testrun.serialized_keys
- if key != 'tests'
- ]
- detaildict = dict([(k, testrun.__dict__[k]) for k in detail_keys])
- details = buildDetails(detaildict)
- name = testrun.name
- codename = testrun.codename
-
- writefile(filename, Testrun % locals())
-
-def hrefFromParts(codename, path):
- outStr = codename + '/' + testPathToHtmlFilename(path)
- if outStr[0] == '/':
- outStr = outStr[1:]
- return outStr
-
-def buildTestSummary(indent, testsummary):
- path = testsummary.path
- name = cgi.escape(testsummary.name)
- testruns = "".join([IndexTestTestrun % {
- 'status': result.status,
- 'link': hrefFromParts(result.testrun.codename, path)
- } for result in testsummary.results])
-
- return IndexTest % locals()
-
-
-def buildGroupSummaryTestrun(groupresult):
- passnr = groupresult.passvector.passnr
- warnnr = groupresult.passvector.warnnr
- failnr = groupresult.passvector.failnr
- skipnr = groupresult.passvector.skipnr
- crashnr = groupresult.passvector.crashnr
- totalnr = passnr + warnnr + failnr + crashnr # do not count skips
-
- if crashnr > 0:
- status = 'crash'
- elif failnr > 0:
- status = 'fail'
- elif warnnr > 0:
- status = 'warn'
- elif passnr > 0:
- status = 'pass'
- else:
- status = 'skip'
-
- return IndexGroupTestrun % locals()
-
-
-def buildGroupSummary(indent, groupsummary, showcurrent):
- indent_inc = 1.75 # em
- items = ''
- path = groupsummary.path
- name = groupsummary.name
- names = groupsummary.children.keys()
-
- if showcurrent == 'changes':
- names = filter(lambda n: groupsummary.children[n].changes, names)
- elif showcurrent == 'problems':
- names = filter(lambda n: groupsummary.children[n].problems, names)
- elif showcurrent == 'regressions':
- names = filter(lambda n: groupsummary.children[n].regressions, names)
- elif showcurrent == 'fixes':
- names = filter(lambda n: groupsummary.children[n].fixes, names)
- elif showcurrent == 'skipped':
- names = filter(lambda n: groupsummary.children[n].skipped, names)
-
- names.sort()
- for n in names:
- child = groupsummary.children[n]
- if isinstance(child, framework.summary.GroupSummary):
- items = items + buildGroupSummary(indent + indent_inc, child, showcurrent)
- else:
- items = items + buildTestSummary(indent + indent_inc, child)
-
- testruns = "".join([buildGroupSummaryTestrun(result)
- for result in groupsummary.results])
-
- return IndexGroup % locals()
-
-
-def writeSummaryHtml(summary, summaryDir, showcurrent):
- """\
-results is an array containing the top-level results dictionarys.
-"""
- def link(to):
- if to == showcurrent:
- return to
- else:
- page = SummaryPages[to]
- return '<a href="%(page)s">%(to)s</a>' % locals()
-
- def testrunb(tr):
- if 'href' in tr.__dict__:
- return IndexTestrunBHref % tr.__dict__
- else:
- return IndexTestrunB % tr.__dict__
-
- group = buildGroupSummary(0, summary.root, showcurrent)
- testruns = '<col/>' * len(summary.testruns)
- testrunsb = "".join([testrunb(tr) for tr in summary.testruns])
-
- tolist = SummaryPages.keys()
- tolist.sort()
- showlinks = " | ".join([link(to) for to in tolist])
-
- writefile(summaryDir + '/' + SummaryPages[showcurrent], Index % locals())
-
-
-#############################################################################
-##### Main program
-#############################################################################
def parse_listfile(filename):
"""
Read a list of newline seperated flies and return them as a python list.
@@ -252,6 +40,7 @@ def parse_listfile(filename):
"""
return open(filename, 'r').read().rstrip().split('\n')
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--overwrite",
@@ -267,7 +56,7 @@ def main():
help = "Directory to put HTML files in")
parser.add_argument("resultsFiles",
metavar = "<Results Files>",
- nargs = "+",
+ nargs = "*",
help = "Results files to include in HTML")
args = parser.parse_args()
@@ -275,34 +64,20 @@ def main():
if not args.list and not args.resultsFiles:
raise parser.error("Missing required option -l or <resultsFiles>")
- core.checkDir(args.summaryDir, not args.overwrite)
+ # if overwrite is requested delete the output directory
+ if path.exists(args.summaryDir) and args.overwrite:
+ shutil.rmtree(args.summaryDir)
- results = []
- if args.list:
- for result in parse_listfile(args.list):
- results.append(core.loadTestResults(os.path.expanduser(result)))
-
- results.extend([core.loadTestResults(i) for i in args.resultsFiles])
+ # If the requested directory doesn't exist, create it or throw an error
+ checkDir(args.summaryDir, not args.overwrite)
- summary = framework.summary.Summary(results)
- for j in range(len(summary.testruns)):
- tr = summary.testruns[j]
- tr.codename = filter(lambda s: s.isalnum(), tr.name)
- dirname = args.summaryDir + '/' + tr.codename
- core.checkDir(dirname, False)
- writeTestrunHtml(tr, dirname + '/index.html')
- for test in summary.allTests():
- filename = dirname + '/' + testPathToHtmlFilename(test.path)
- writeResultHtml(test, test.results[j], filename)
+ # Merge args.list and args.resultsFiles
+ if args.list:
+ args.resultsFiles.extend(parse_listfile(args.list))
- writefile(os.path.join(args.summaryDir, 'result.css'), readfile(os.path.join(templatedir, 'result.css')))
- writefile(os.path.join(args.summaryDir, 'index.css'), readfile(os.path.join(templatedir, 'index.css')))
- writeSummaryHtml(summary, args.summaryDir, 'all')
- writeSummaryHtml(summary, args.summaryDir, 'problems')
- writeSummaryHtml(summary, args.summaryDir, 'changes')
- writeSummaryHtml(summary, args.summaryDir, 'regressions')
- writeSummaryHtml(summary, args.summaryDir, 'fixes')
- writeSummaryHtml(summary, args.summaryDir, 'skipped')
+ # Create the HTML output
+ output = summary.NewSummary(args.resultsFiles)
+ output.generateHTML(args.summaryDir)
if __name__ == "__main__":
--
1.8.1.4
More information about the Piglit
mailing list