[Piglit] [PATCH 1/3] framework/summary/html_.py: save templates in cache on linux

Dylan Baker baker.dylan.c at gmail.com
Mon Sep 28 18:05:17 PDT 2015


Use the cache (presumably ~/.cache) to store templates on linux. This
saves us from having to generate them again after reboots.
---
 framework/summary/html_.py | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/framework/summary/html_.py b/framework/summary/html_.py
index 0036b83..93749f0 100644
--- a/framework/summary/html_.py
+++ b/framework/summary/html_.py
@@ -42,16 +42,26 @@ __all__ = [
     'html',
 ]
 
-_TEMP_DIR = os.path.join(
-    tempfile.gettempdir(),
-    "piglit-{}".format(getpass.getuser()),
-    'version-{}'.format(sys.version.split()[0]))
+# If on linux write the module templates into XDG_CACHE_HOME (or HOME/.cache,
+# the default location). If not, put them in a temporary directory.
+if sys.platform.startswith('linux'):
+    _cache = os.path.expandvars('$XDG_CACHE_HOME') 
+    if _cache == '$XDG_CACHE_HOME':
+        _cache = os.path.expandvars('$HOME/.cache')
+    _CACHE_DIR = os.path.join(
+        _cache, 'piglit', 'version-{}'.format(sys.version.split()[0]))
+else:
+    _CACHE_DIR = os.path.join(
+        tempfile.gettempdir(),
+        "piglit-{}".format(getpass.getuser()),
+        'version-{}'.format(sys.version.split()[0]))
+
 _TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), '../..', 'templates')
 _TEMPLATES = TemplateLookup(
     _TEMPLATE_DIR,
     output_encoding="utf-8",
     encoding_errors='replace',
-    module_directory=os.path.join(_TEMP_DIR, "html-summary"))
+    module_directory=os.path.join(_CACHE_DIR, "html-summary"))
 
 
 def _copy_static_files(destination):
-- 
2.5.3



More information about the Piglit mailing list