This change reduces code duplication by setting arguments to the templates to be set once, rather than once per template.
Signed-off-by: Dylan Baker <[email protected]> --- framework/summary.py | 56 ++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/framework/summary.py b/framework/summary.py index eaba2b3..0e47e9e 100644 --- a/framework/summary.py +++ b/framework/summary.py @@ -24,7 +24,7 @@ import os.path as path import itertools import shutil import collections -from mako.template import Template +from mako.lookup import TemplateLookup # a local variable status exists, prevent accidental overloading by renaming # the module @@ -345,20 +345,21 @@ class Summary: of dicts, which mako turns into pretty HTML. """ + # Lookup all templates in the template dir + templates = TemplateLookup(directories=["templates"], + output_encoding="utf-8", + module_directory=".makotmp") + + # Load the necissary templates + testindex = templates.get_template("testrun_info.mako") + testfile = templates.get_template("test_result.mako") + makoindex = templates.get_template("index.mako") + empty_status = templates.get_template("empty_status.mako") + # Copy static files shutil.copy("templates/index.css", path.join(destination, "index.css")) shutil.copy("templates/result.css", path.join(destination, "result.css")) - # Create the mako object for creating the test/index.html file - testindex = Template(filename="templates/testrun_info.mako", - output_encoding="utf-8", - module_directory=".makotmp") - - # Create the mako object for the individual result files - testfile = Template(filename="templates/test_result.mako", - output_encoding="utf-8", - module_directory=".makotmp") - result_css = path.join(destination, "result.css") index = path.join(destination, "index.html") @@ -399,43 +400,34 @@ class Summary: index=path.relpath(index, temp_path))) # Finally build the root html files: index, regressions, etc - index = Template(filename="templates/index.mako", - output_encoding="utf-8", - module_directory=".makotmp") - - empty_status = Template(filename="templates/empty_status.mako", - output_encoding="utf-8", - module_directory=".makotmp") - pages = ('changes', 'problems', 'skipped', 'fixes', 'regressions') # Index.html is a bit of a special case since there is index, all, and # alltests, where the other pages all use the same name. ie, # changes.html, self.changes, and page=changes. with open(path.join(destination, "index.html"), 'w') as out: - out.write(index.render(results=HTMLIndex(self, self.tests['all']), - page='all', - pages=pages, - colnum=len(self.results), - exclude=exclude)) + out.write(makoindex.render(results=HTMLIndex(self, self.tests['all']), + page='all', + pages=pages, + colnum=len(self.results), + exclude=exclude)) # Generate the rest of the pages for page in pages: - with open(path.join(destination, page + '.html'), 'w') as out: # If there is information to display display it + with open(path.join(destination, page + '.html'), 'w') as out: if self.tests[page]: - out.write(index.render(results=HTMLIndex(self, - self.tests[page]), - pages=pages, - page=page, - colnum=len(self.results), - exclude=exclude)) + out.write(makoindex.render( + results=HTMLIndex(self, self.tests[page]), + pages=pages, + page=page, + colnum=len(self.results), + exclude=exclude)) # otherwise provide an empty page else: out.write(empty_status.render(page=page, pages=pages)) def generate_text(self, diff, summary): - """ Write summary information to the console """ self.__find_totals() # Print the name of the test and the status from each test run -- 1.8.1.5 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
