<div dir="ltr">Have you tested this? When I try to run with just -o (nothing added after) it attempts to scoop up the next positional argument as the argument for -o, and fails.<div><br></div><div style>Also, instead of using \ escapes, line up the quotation marks on the left and python will magically concatenate the strings.</div>
<div style><br></div><div style>Have you considered instead adding an exclusive argument as an alternative to --overwrite, something like --rename? these would just need to be simple 'store_true'/'store_false' sort of switches.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 8, 2013 at 3:15 PM, Ben Widawsky <span dir="ltr"><<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Some of us (ie. not just me) like to script piglit runs. As such we've<br>
all baked in versions of our own auto result directory naming, or as an<br>
alternative accidentally overwritten the results we've wanted.. To make<br>
things easier for people, add two new options under the -o (overwrite)<br>
flag.<br>
<br>
[-o {yes,no,next}]<br>
<br>
yes: default, and previous behavior. Just do it.<br>
no: warn, and exit if you try to overwrite the results dir.<br>
next: create a new results dir with an appended number.<br>
<br>
For example, if one invokes:<br>
> piglit-run.py -o next tests/igt.tests results/ppgtt-ctx<br>
and results/ppgtt-ctx exists...<br>
results would be written to results/ppgtt-ctx.1.<br>
<br>
To keep the code relatively simple, it won't be smart if the user<br>
specifies a number in their invocation. ie. if after doing the above,<br>
> piglit-run.py -o next tests/igt.tests results/ppgtt-ctx.1<br>
<br>
results/ppgtt-ctx.1.1 would be created.<br>
<br>
CC: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
Signed-off-by: Ben Widawsky <<a href="mailto:ben@bwidawsk.net">ben@bwidawsk.net</a>><br>
---<br>
piglit-run.py | 23 +++++++++++++++++++++++<br>
1 file changed, 23 insertions(+)<br>
<br>
diff --git a/piglit-run.py b/piglit-run.py<br>
index 6d6ec77..175ee56 100755<br>
--- a/piglit-run.py<br>
+++ b/piglit-run.py<br>
@@ -28,6 +28,7 @@ import sys, os<br>
import time<br>
import traceback<br>
import json<br>
+import re<br>
<br>
sys.path.append(path.dirname(path.realpath(sys.argv[0])))<br>
import framework.core as core<br>
@@ -72,6 +73,12 @@ def main():<br>
action = "append",<br>
metavar = "<regex>",<br>
help = "Exclude matching tests (can be used more than once)")<br>
+ parser.add_argument("-o", "--overwrite",<br>
+ default = "yes",<br>
+ choices = ["yes", "no", "next"],<br>
+ help = "Results directory overwrite options. " \<br>
+ "\"next\" will create a new directory name " \<br>
+ "based on the old similarly names ones")<br>
<br>
# The new option going forward should be --no-concurrency, but to<br>
# maintain backwards compatability the --c, --concurrent option should<br>
@@ -149,6 +156,22 @@ def main():<br>
else:<br>
profileFilename = args.testProfile<br>
resultsDir = args.resultsPath<br>
+ if os.path.isdir(resultsDir):<br>
+ if args.overwrite == "no":<br>
+ sys.exit(resultsDir + " Already exists, and overwrite was no")<br>
+ elif args.overwrite == "next":<br>
+ suffixes = [0] # If we found the dir, we have at least 1<br>
+<br>
+ # Find the highest numbered results dir<br>
+ pattern = re.compile(os.path.basename(resultsDir) + "\.*(\d+)")<br>
+ parent = os.path.abspath(os.path.join(resultsDir, os.pardir))<br>
+ for file in os.listdir(parent):<br>
+ m = pattern.match(file)<br>
+ if m:<br>
+ suffixes.append(m.group(1))<br>
+<br>
+ # Add 1 to the highest, and move along<br>
+ resultsDir += "." + str((int(max(suffixes))+1))<br>
<br>
# Pass arguments into Environment<br>
env = core.Environment(concurrent=args.concurrency,<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.2.2<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div>