[Piglit] [PATCH 2/4] summary.py: Allows summary to use zipped json files

Dylan Baker baker.dylan.c at gmail.com
Fri Aug 16 09:09:36 PDT 2013


This allows the Result class to unzip and pass a file object to result.
It still can use unziped main json files, but looks for main.zip files
as well.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/summary.py | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/framework/summary.py b/framework/summary.py
index 35500bf..49b53b9 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -22,6 +22,7 @@
 import os
 import os.path as path
 import string
+import zipfile
 from itertools import izip_longest
 from shutil import copy
 from json import loads
@@ -42,14 +43,23 @@ class Result(core.TestrunResult):
         # Run the init from TestrunResult
         core.TestrunResult.__init__(self)
 
-        # Load the json file, or if that fails assume that the locations given
-        # is a folder containing a json file
+        # Attempt to load the json file, first looke for a zipped version, and
+        # if that doesn't exist look for an unziped version. Assume first that
+        # a directory was prvided, and then that a file was provided
         try:
-            with open(resultfile, 'r') as file:
-                result = self.parseFile(file)
+            try:
+                zip = zipfile.ZipFile(resultfile)
+                result = self.parseFile(zip.open('main', 'r'))
+            except zipfile.BadZipfile:
+                with open(resultfile, 'r') as file:
+                    result = self.parseFile(file)
         except IOError:
-            with open(path.join(resultfile, 'main'), 'r') as file:
-                result = self.parseFile(file)
+            try:
+                zip = zipfile.ZipFile(path.join(resultfile, 'main.zip'))
+                result = self.parseFile(zip.open('main', 'r'))
+            except IOError:
+                with open(path.join(resultfile, 'main'), 'r') as file:
+                    result = self.parseFile(file)
 
 
 class HTMLIndex(list):
-- 
1.8.1.5



More information about the Piglit mailing list