[Piglit] [PATCH 1/4] framework: allow loading a piglit.conf from more locations

Dylan Baker baker.dylan.c at gmail.com
Mon Jun 30 16:53:19 PDT 2014


This allows piglit.conf to reside in $HOME/.conf/ (as defined by xdg
basedir-spec
http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html), in
the current directory, or in the piglit toplevel directory (in that
order). This allows piglit.conf to survive git clean and other hardships
of living in a development directory

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/programs/run.py | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/framework/programs/run.py b/framework/programs/run.py
index c1a2658..c2bc686 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -123,13 +123,7 @@ def run(input_):
         args.concurrency = "none"
 
     # Read the config file
-    if args.config_file:
-        core.PIGLIT_CONFIG.readfp(args.config_file)
-        args.config_file.close()
-    else:
-        core.PIGLIT_CONFIG.read(os.path.abspath(
-            os.path.join(
-                os.path.dirname(__file__), '..', '..', 'piglit.conf')))
+    _get_config(args.config_file)
 
     # Pass arguments into Options
     opts = core.Options(concurrent=args.concurrency,
@@ -203,6 +197,11 @@ def resume(input_):
                         type=path.realpath,
                         metavar="<Results Path>",
                         help="Path to results folder")
+    parser.add_argument("-f", "--config",
+                        dest="config_file",
+                        type=argparse.FileType("r"),
+                        help="Optionally specify a piglit config file to use. "
+                             "Default is piglit.conf")
     args = parser.parse_args(input_)
 
     results = framework.results.load_results(args.results_path)
@@ -214,6 +213,8 @@ def resume(input_):
                         dmesg=results.options['dmesg'],
                         verbose=results.options['verbose'])
 
+    _get_config(args.config_file)
+
     if results.options.get('platform'):
         opts.env['PIGLIT_PLATFORM'] = results.options['platform']
 
@@ -242,3 +243,23 @@ def resume(input_):
 
     print("Thank you for running Piglit!\n"
           "Results have ben wrriten to {0}".format(results_path))
+
+
+def _get_config(arg):
+    if arg:
+        core.PIGLIT_CONFIG.readfp(arg)
+    else:
+        # Try XDG_CONFIG_DIR, then try the local directory, finally try the
+        # root of the piglit dir relative to this file
+        for d in [os.path.expandvars('$HOME/.config'), '.',
+                  os.path.join(os.path.dirname(__file__), '..', '..')]:
+            try:
+                with open(os.path.join(d, 'piglit.conf'), 'r') as f:
+                    core.PIGLIT_CONFIG.readfp(f)
+                break
+            except IOError:
+                pass
+        else:
+            if __debug__:
+                print('Warning: piglit.conf not found! (searching $HOME/.conf,'
+                      ' piglit source dir, and current dir)', file=sys.stderr)
-- 
2.0.0



More information about the Piglit mailing list