[Piglit] [PATCH 2/6] index.mako: Split index.mako into three files

Dylan Baker baker.dylan.c at gmail.com
Mon Nov 4 08:53:43 PST 2013


This is groundwork for simplifying the generation of the HTML pages.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/summary.py       | 25 ++++++++------
 templates/index.mako       | 81 ----------------------------------------------
 templates/index_body.mako  | 41 +++++++++++++++++++++++
 templates/index_close.mako |  3 ++
 templates/index_open.mako  | 38 ++++++++++++++++++++++
 5 files changed, 97 insertions(+), 91 deletions(-)
 delete mode 100644 templates/index.mako
 create mode 100644 templates/index_body.mako
 create mode 100644 templates/index_close.mako
 create mode 100644 templates/index_open.mako

diff --git a/framework/summary.py b/framework/summary.py
index 0e47e9e..9333139 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -353,7 +353,9 @@ class Summary:
         # Load the necissary templates
         testindex = templates.get_template("testrun_info.mako")
         testfile = templates.get_template("test_result.mako")
-        makoindex = templates.get_template("index.mako")
+        index_open = templates.get_template("index_open.mako")
+        index_body = templates.get_template("index_body.mako")
+        index_close = templates.get_template("index_close.mako")
         empty_status = templates.get_template("empty_status.mako")
 
         # Copy static files
@@ -406,23 +408,26 @@ class Summary:
         # 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(makoindex.render(results=HTMLIndex(self, self.tests['all']),
-                                       page='all',
-                                       pages=pages,
-                                       colnum=len(self.results),
-                                       exclude=exclude))
+            out.write(index_open.render(page='all',
+                                        pages=pages,
+                                        colnum=len(self.results)))
+            out.write(index_body.render(results=HTMLIndex(self, self.tests['all']),
+                                        exclude=exclude))
+            out.write(index_close.render())
 
         # Generate the rest of the pages
         for page in pages:
             # If there is information to display display it
             with open(path.join(destination, page + '.html'), 'w') as out:
                 if self.tests[page]:
-                    out.write(makoindex.render(
-                        results=HTMLIndex(self, self.tests[page]),
-                        pages=pages,
+                    out.write(index_open.render(
                         page=page,
-                        colnum=len(self.results),
+                        pages=pages,
+                        colnum=len(self.results)))
+                    out.write(index_body.render(
+                        results=HTMLIndex(self, self.tests[page]),
                         exclude=exclude))
+                    out.write(index_close.render())
                 # otherwise provide an empty page
                 else:
                     out.write(empty_status.render(page=page, pages=pages))
diff --git a/templates/index.mako b/templates/index.mako
deleted file mode 100644
index e959a27..0000000
--- a/templates/index.mako
+++ /dev/null
@@ -1,81 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-  <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-    <title>Result summary</title>
-    <link rel="stylesheet" href="index.css" type="text/css" />
-  </head>
-  <body>
-    <h1>Result summary</h1>
-    <p>Currently showing: ${page}</p>
-    <p>Show:
-      % if page == 'all':
-        all
-      % else:
-        <a href="index.html">all</a>
-      % endif
-      % for i in pages:
-        % if i == page:
-          | ${i}
-        % else:
-          | <a href="${i}.html">${i}</a>
-        % endif
-      % endfor
-    </p>
-    <table>
-      <colgroup>
-        ## Name Column
-        <col />
-
-        ## Status columns
-        ## Create an additional column for each summary
-        % for _ in xrange(colnum):
-        <col />
-        % endfor
-      </colgroup>
-      % for line in results:
-        % if line['type'] == "newRow":
-        <tr>
-        % elif line['type'] == "endRow":
-        </tr>
-        % elif line['type'] == "groupRow":
-          <td>
-            <div class="${line['class']}" style="margin-left: ${line['indent']}em">
-              <b>${line['text']}</b>
-            </div>
-          </td>
-        % elif line['type'] == "testRow":
-          <td>
-            <div class="${line['class']}" style="margin-left: ${line['indent']}em">
-              ${line['text']}
-            </div>
-          </td>
-        % elif line['type'] == "groupResult":
-          <td class="${line['class']}">
-            <b>${line['text']}</b>
-          </td>
-        % elif line['type'] == "testResult":
-          <td class="${line['class']}">
-          ## If the result is in the excluded results page list from
-          ## argparse, just print the text, otherwise add the link
-          % if line['class'] not in exclude:
-            <a href="${line['href']}">
-              ${line['text']}
-            </a>
-          % else:
-            ${line['text']}
-          % endif
-          </td>
-        % elif line['type'] == "subtestResult":
-          <td class="${line['class']}">
-            ${line['text']}
-          </td>
-        % elif line['type'] == "other":
-          ${line['text']}
-        % endif
-      % endfor
-    </table>
-  </body>
-</html>
diff --git a/templates/index_body.mako b/templates/index_body.mako
new file mode 100644
index 0000000..0056912
--- /dev/null
+++ b/templates/index_body.mako
@@ -0,0 +1,41 @@
+    % for line in results:
+      % if line['type'] == "newRow":
+      <tr>
+      % elif line['type'] == "endRow":
+      </tr>
+      % elif line['type'] == "groupRow":
+        <td>
+          <div class="${line['class']}" style="margin-left: ${line['indent']}em">
+            <b>${line['text']}</b>
+          </div>
+        </td>
+      % elif line['type'] == "testRow":
+        <td>
+          <div class="${line['class']}" style="margin-left: ${line['indent']}em">
+            ${line['text']}
+          </div>
+        </td>
+      % elif line['type'] == "groupResult":
+        <td class="${line['class']}">
+          <b>${line['text']}</b>
+        </td>
+      % elif line['type'] == "testResult":
+        <td class="${line['class']}">
+        ## If the result is in the excluded results page list from
+        ## argparse, just print the text, otherwise add the link
+        % if line['class'] not in exclude:
+          <a href="${line['href']}">
+            ${line['text']}
+          </a>
+        % else:
+          ${line['text']}
+        % endif
+        </td>
+      % elif line['type'] == "subtestResult":
+        <td class="${line['class']}">
+          ${line['text']}
+        </td>
+      % elif line['type'] == "other":
+        ${line['text']}
+      % endif
+    % endfor
diff --git a/templates/index_close.mako b/templates/index_close.mako
new file mode 100644
index 0000000..a649f82
--- /dev/null
+++ b/templates/index_close.mako
@@ -0,0 +1,3 @@
+    </table>
+  </body>
+</html>
\ No newline at end of file
diff --git a/templates/index_open.mako b/templates/index_open.mako
new file mode 100644
index 0000000..6f468a6
--- /dev/null
+++ b/templates/index_open.mako
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+    <title>Result summary</title>
+    <link rel="stylesheet" href="index.css" type="text/css" />
+  </head>
+  <body>
+    <h1>Result summary</h1>
+    <p>Currently showing: ${page}</p>
+    <p>Show:
+      % if page == 'all':
+        all
+      % else:
+        <a href="index.html">all</a>
+      % endif
+      % for i in pages:
+        % if i == page:
+          | ${i}
+        % else:
+          | <a href="${i}.html">${i}</a>
+        % endif
+      % endfor
+    </p>
+    <table>
+      <colgroup>
+        ## Name Column
+        <col />
+
+        ## Status columns
+        ## Create an additional column for each summary
+        % for _ in xrange(colnum):
+        <col />
+        % endfor
+      </colgroup>
+
-- 
1.8.1.5



More information about the Piglit mailing list