[Piglit] [PATCH] piglit_run: New overwrite options {next, no}

Ben Widawsky ben at bwidawsk.net
Wed May 8 15:15:21 PDT 2013


Some of us (ie. not just me) like to script piglit runs. As such we've
all baked in versions of our own auto result directory naming, or as an
alternative accidentally overwritten the results we've wanted.. To make
things easier for people, add two new options under the -o (overwrite)
flag.

[-o {yes,no,next}]

yes: default, and previous behavior. Just do it.
no: warn, and exit if you try to overwrite the results dir.
next: create a new results dir with an appended number.

For example, if one invokes:
> piglit-run.py -o next tests/igt.tests results/ppgtt-ctx
and results/ppgtt-ctx exists...
results would be written to results/ppgtt-ctx.1.

To keep the code relatively simple, it won't be smart if the user
specifies a number in their invocation. ie. if after doing the above,
> piglit-run.py -o next tests/igt.tests results/ppgtt-ctx.1

results/ppgtt-ctx.1.1 would be created.

CC: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 piglit-run.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/piglit-run.py b/piglit-run.py
index 6d6ec77..175ee56 100755
--- a/piglit-run.py
+++ b/piglit-run.py
@@ -28,6 +28,7 @@ import sys, os
 import time
 import traceback
 import json
+import re
 
 sys.path.append(path.dirname(path.realpath(sys.argv[0])))
 import framework.core as core
@@ -72,6 +73,12 @@ def main():
 			action  = "append",
 			metavar = "<regex>",
 			help    = "Exclude matching tests (can be used more than once)")
+	parser.add_argument("-o", "--overwrite",
+			default	= "yes",
+			choices	= ["yes", "no", "next"],
+			help	= "Results directory overwrite options. " \
+				  "\"next\" will create a new directory name " \
+				  "based on the old similarly names ones")
 
 	# The new option going forward should be --no-concurrency, but to
 	# maintain backwards compatability the --c, --concurrent option should
@@ -149,6 +156,22 @@ def main():
 	else:
 		profileFilename = args.testProfile
 		resultsDir = args.resultsPath
+		if os.path.isdir(resultsDir):
+			if args.overwrite == "no":
+				sys.exit(resultsDir + " Already exists, and overwrite was no")
+			elif args.overwrite == "next":
+				suffixes = [0] # If we found the dir, we have at least 1
+
+				# Find the highest numbered results dir
+				pattern = re.compile(os.path.basename(resultsDir) + "\.*(\d+)")
+				parent = os.path.abspath(os.path.join(resultsDir, os.pardir))
+				for file in os.listdir(parent):
+					m = pattern.match(file)
+					if m:
+						suffixes.append(m.group(1))
+
+				# Add 1 to the highest, and move along
+				resultsDir += "." + str((int(max(suffixes))+1))
 
 	# Pass arguments into Environment
 	env = core.Environment(concurrent=args.concurrency,
-- 
1.8.2.2



More information about the Piglit mailing list