[Piglit] [PATCH 2/2] summary/html: Fix processing of Windows results.

jfonseca at vmware.com jfonseca at vmware.com
Thu Jun 5 12:20:01 PDT 2014


From: José Fonseca <jfonseca at vmware.com>

- Prevent the use of reserved characters in filenames (e.g., '>' and '<'
  which are used in several cases.)

- Handle mixture of backward and forward slashes gracefuly.
---
 framework/summary.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/framework/summary.py b/framework/summary.py
index d71fb53..9cb5646 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -40,6 +40,15 @@ __all__ = [
 ]
 
 
+def escapeFilename(key):
+    """
+    Avoid reserved characters in filenames.
+    """
+    for c in '<>:"|?*':
+        key = key.replace(c, '_')
+    return key
+
+
 class HTMLIndex(list):
     """
     Builds HTML output to be passed to the index mako template, which will be
@@ -122,7 +131,7 @@ class HTMLIndex(list):
 
             # Split the group names and test names, then determine
             # which groups to close and which to open
-            openList = key.split('/')
+            openList = key.replace('\\', '/').split('/')
             test = openList.pop()
             openList, closeList = returnList(openList, list(currentDir))
 
@@ -172,6 +181,8 @@ class HTMLIndex(list):
                 except KeyError:
                     href = key
 
+                href = escapeFilename(href)
+
                 try:
                     self._testResult(each.name, href,
                                      summary.status[each.name][key])
@@ -454,7 +465,8 @@ class Summary:
 
             # Then build the individual test results
             for key, value in each.tests.iteritems():
-                temp_path = path.join(destination, each.name, path.dirname(key))
+                html_path = path.join(destination, each.name, escapeFilename(key + ".html"))
+                temp_path = path.dirname(html_path)
 
                 if value['result'] not in exclude:
                     # os.makedirs is very annoying, it throws an OSError if
@@ -469,8 +481,7 @@ class Summary:
                     if value.get('time') is not None:
                         value['time'] = datetime.timedelta(0, value['time'])
 
-                    with open(path.join(destination, each.name, key + ".html"),
-                              'w') as out:
+                    with open(path.join(html_path), 'w') as out:
                         out.write(testfile.render(
                             testname=key,
                             value=value,
-- 
1.9.1



More information about the Piglit mailing list