This patch removes the need for the HTMLIndex class by reimplementing it directly in the mako template. This results in a slight amount of overhead on a clean run (since mako generates python from it's templates), but removes the need for an entire class that only added a layer of abstraction to the process.
Signed-off-by: Dylan Baker <[email protected]> --- framework/summary.py | 124 ++--------------------------------------------- templates/functions.mako | 8 +-- templates/index.mako | 81 ++++++++++++++++++++++--------- 3 files changed, 66 insertions(+), 147 deletions(-) diff --git a/framework/summary.py b/framework/summary.py index 8215bbc..c1f24a6 100644 --- a/framework/summary.py +++ b/framework/summary.py @@ -22,7 +22,6 @@ import os import os.path as path import string -from itertools import izip_longest from shutil import copy from json import loads from mako.lookup import TemplateLookup @@ -55,123 +54,6 @@ class Result(core.TestrunResult): result = self.parseFile(file) -class HTMLIndex(list): - """ - Builds HTML output to be passed to the index mako template, which will be - rendered into HTML pages. It does this by parsing the lists provided by the - Summary object, and returns itself, an object with one accessor, a list of - html strings that will be printed by the mako template. - """ - - def __init__(self, summary, page): - """ - Steps through the list of groups and tests from all of the results and - generates a list of dicts that are passed to mako and turned into HTML - """ - - # set a starting depth of 1, 0 is used for 'all' so 1 is the - # next available group - depth = 1 - group = "" - - # The following loop relies on alphabetical sorting of test names - for test in sorted(page): - - # If the current group not the same as the last group call - # os.path.relpath on it. This gives ".." for each group to close - # (reducing the depth) and a name for each group to open - # (increasing the depth) - if path.dirname(test) != group: - for cur in path.relpath(path.dirname(test), group).split('/'): - if cur == "..": - depth -= 1 - group = path.dirname(group) - else: - group = path.join(group, cur) - self._newRow() - self._groupRow("head", depth, group) - for each in summary.results: - try: - self._groupResult( - summary.fractions[each.name][group], - summary.status[each.name][group]) - except KeyError: - self._groupResult((0, 0), 'skip') - depth += 1 - self._endRow() - - # Finally add a new row for the test itself, and add the left-most - # name column - self._newRow() - self._testRow("group", depth, test) - - # Add the result from each test result to the HTML summary If there - # is a KeyError (a result doesn't contain a particular test), - # return Not Run, with clas skip for highlighting - for each in summary.results: - try: - self._testResult(each.name, test, each.tests[test]['result']) - except KeyError: - self.append({'type': 'other', - 'text': '<td class="skip">Not Run</td>'}) - self._endRow() - - def _newRow(self): - self.append({'type': 'newRow'}) - - def _endRow(self): - self.append({'type': 'endRow'}) - - def _groupRow(self, cssclass, depth, groupname): - """ - Helper function for appending new groups to be written out - in HTML. - - This particular function is used to write the left most - column of the summary. (the one with the indents) - """ - self.append({'type': "groupRow", - 'class': cssclass, - 'indent': (1.75 * depth), - 'text': groupname}) - - def _groupResult(self, value, css): - """ - Helper function for appending the results of groups to the - HTML summary file. - """ - - self.append({'type': "groupResult", - 'class': css, - 'text': "%s/%s" % (value[0], value[1])}) - - def _testRow(self, cssclass, depth, groupname): - """ - Helper function for appending new tests to be written out - in HTML. - - This particular function is used to write the left most - column of the summary. (the one with the indents) - """ - self.append({'type': "testRow", - 'class': cssclass, - 'indent': (1.75 * depth), - 'text': groupname}) - - def _testResult(self, group, href, text): - """ - Helper function for writing the results of tests - - This function writes the cells other than the left-most cell, - displaying pass/fail/crash/etc and formatting the cell to the - correct color. - """ - self.append({'type': 'testResult', - 'class': text, - 'href': path.join(group, href + ".html"), - 'text': text}) - - class Summary: """ This Summary class creates an initial object containing lists of tests @@ -422,10 +304,10 @@ class Summary: # alltests, where the other pages all use the same name. ie, # changes.html, self.changes, and page=changes. file = open(path.join(destination, "index.html"), 'w') - file.write(makoindex.render(old_results=HTMLIndex(self, self.tests['all']), - fractions=self.fractions, + file.write(makoindex.render(fractions=self.fractions, status=self.status, results=self.results, + tests=self.tests['all'], page='all', pages=pages, exclude=exclude)) @@ -437,10 +319,10 @@ class Summary: # If there is information to display display it if self.tests[page]: file.write(makoindex.render( - old_results=HTMLIndex(self, self.tests[page]), fractions=self.fractions, status=self.status, results=self.results, + tests=self.tests[page], pages=pages, page=page, exclude=exclude)) diff --git a/templates/functions.mako b/templates/functions.mako index 7e14274..be43f40 100644 --- a/templates/functions.mako +++ b/templates/functions.mako @@ -45,15 +45,15 @@ <%def name="group_result(hclass, text)"> <td class="${hclass}"> - <b>${text}</b> + <b>${text[0]}/${text[1]}</b> </td> </%def> -<%def name="test_result(hclass, href, text)"> - <td class="${hclass}"> +<%def name="test_result(text, href)"> + <td class="${text}"> ## If the result is in the excluded results page list from ## argparse, just print the text, otherwise add the link - % if hclass not in exclude: + % if text not in exclude: <a href="${href}">${text}</a> % else: ${text} diff --git a/templates/index.mako b/templates/index.mako index 429d184..d9986f7 100644 --- a/templates/index.mako +++ b/templates/index.mako @@ -1,4 +1,5 @@ <% + import itertools from os import path %> @@ -52,33 +53,69 @@ ${functions.end_row()} ## Add the toplevel 'all' group + ${functions.new_row()} + ${functions.group_row("head", 0, "all")} % for each in results: - ${functions.new_row()} - ${functions.group_row("head", 0, "all")} - ## FIXME: This can be changed to a group_result after the next loop is converted - <td class="${status[each.name]['all']}"> - <b>${fractions[each.name]['all'][0]}/${fractions[each.name]['all'][1]}</b> - </td> - ${functions.end_row()} + ${functions.group_result(status[each.name]['all'], fractions[each.name]['all'])} % endfor + ${functions.end_row()} ## Generate the body of the index - % for line in old_results: - % if line['type'] == "newRow": - ${functions.new_row()} - % elif line['type'] == "endRow": - ${functions.end_row()} - % elif line['type'] == "groupRow": - ${functions.group_row(line['class'], line['indent'], line['text'])} - % elif line['type'] == "testRow": - ${functions.test_row(line['class'], line['indent'], line['text'])} - % elif line['type'] == "groupResult": - ${functions.group_result(line['class'], line['text'])} - % elif line['type'] == "testResult": - ${functions.test_result(line['class'], line['href'], line['text'])} - % elif line['type'] == "other": - ${line['text']} + <% + group = "" + depth = 1 + %> + + ## This loop relies on the tests being sorted alphabetically + % for test in sorted(tests): + + ## If the current group is equal to path.dirname(test), they are sibliing tests, + ## otherwise figure out group chagnes + % if path.dirname(test) != group: + + ## Calculate the relative path of the previous test's group and the current + ## test' groups + % for cur in path.relpath(path.dirname(test), group).split('/'): + + ## Everytime we hit ".." decrease the indent in the HTML and set the group + % if cur == "..": + <% + depth -= 1 + group = path.dirname(group) + %> + + ## otherwise open a new group, and write it's data + % else: + <% group = path.join(group, cur) %> + ${functions.new_row()} + ${functions.group_row("head", depth, group)} + % for each in results: + % try: + ${functions.group_result(status[each.name][group], + fractions[each.name][group])} + % except KeyError: + ## If we hit this the group wasn't in one of multiple test runs + ${functions.group_result('skip', (0, 0))} + % endtry + % endfor + <% depth += 1 %> + ${functions.end_row()} + % endif + % endfor % endif + + ## Write the actual test now + ${functions.new_row()} + ${functions.test_row("group", depth, test)} + % for each in results: + % try: + ${functions.test_result(each.tests[test]['result'], + path.join(each.name, test + ".html"))} + % except KeyError: + <td class="skip">Not Run</td> + % endtry + % endfor + ${functions.end_row()} % endfor </table> </body> -- 1.8.1.5 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
