[Piglit] [PATCH 1/4] piglit-run.py: Zip the main json file
Dylan Baker
baker.dylan.c at gmail.com
Fri Aug 16 09:09:35 PDT 2013
With this patch piglit run will save the json output as normal, however,
upon finishing the run it will use python's internal zip implementation
to zip the json file, and if successfull will remove the original
uncompressed text. If it fails to zip, it prints a slightly different
message and leaves the original unocompressed file.
Using zip on the json file compresses a run of quick.tests from 30MB to
1.4MB, which is useful when storing a large number of results files.
Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
piglit-run.py | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/piglit-run.py b/piglit-run.py
index 6a762db..77b70dc 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -29,6 +29,8 @@ import os.path as path
import time
import traceback
import json
+import zipfile
+import textwrap
sys.path.append(path.dirname(path.realpath(sys.argv[0])))
import framework.core as core
@@ -212,9 +214,30 @@ def main():
json_writer.close_dict()
json_writer.file.close()
- print
- print 'Thank you for running Piglit!'
- print 'Results have been written to ' + result_filepath
+ # Zip the json file, this saves a lot of space, however,
+ try:
+ zip = zipfile.ZipFile(path.join(resultsDir, 'main.zip'), 'w',
+ compression=zipfile.ZIP_DEFLATED)
+ zip.write(path.join(resultsDir, "main"), 'main')
+ # Verify the zip file is okay
+ zip.testzip()
+ zip.close()
+ os.remove(path.join(resultsDir, 'main'))
+ print textwrap.dedent("""
+
+ Thank you for running Piglit!
+ Results have been written to {0}.zip
+ """.format(result_filepath))
+ except zipfile.BadZipFile:
+ zip.close()
+ os.remove(path.join(resultsDir, 'main.zip'))
+
+ print textwrap.dedent("""
+
+ Thank you for running Piglit!
+ Becasue the zip file was bad your results have ben saved as raw json
+ Results have been written to {0}
+ """.format(result_filepath))
if __name__ == "__main__":
--
1.8.1.5
More information about the Piglit
mailing list