[Piglit] [PATCH 2/2] framework/programs/run.py: Add option for overwriting files
Dylan Baker
baker.dylan.c at gmail.com
Mon Feb 1 15:12:39 PST 2016
Rather than removing the results_path unconditionally (if it exists),
this requires the that -o/--overwrite switch is provided to overwrite.
This is the same syntax that `summary html` uses, and provides users a
little bit of protection so they don't overwrite something they meant to
keep.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/programs/run.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/framework/programs/run.py b/framework/programs/run.py
index 1cc1b4a..452e412 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -164,6 +164,10 @@ def _run_parser(input_):
help="Set the logger verbosity level")
parser.add_argument("--test-list",
help="A file containing a list of tests to run")
+ parser.add_argument('-o', '--overwrite',
+ dest='overwrite',
+ action='store_true',
+ help='If the results_path already exists, delete it')
parser.add_argument("test_profile",
metavar="<Profile path(s)>",
nargs='+',
@@ -249,13 +253,19 @@ def run(input_):
piglit_dir = path.dirname(path.realpath(sys.argv[0]))
os.chdir(piglit_dir)
- # Clear results directory, completely remove it and recreate it whether
- # it's a directory or a file.
- if os.path.isdir(args.results_path):
- shutil.rmtree(args.results_path)
- else:
- os.unlink(args.results_path)
- os.makedirs(args.results_path)
+ # If the results directory already exists and if overwrite was set, then
+ # clear the directory. If it wasn't set, then raise fatal error.
+ if os.path.exists(args.results_path):
+ if args.overwrite:
+ if os.path.isdir(args.results_path):
+ shutil.rmtree(args.results_path)
+ else:
+ os.unlink(args.results_path)
+ else:
+ raise exceptions.PiglitFatalError(
+ 'Cannot overwrite existing folder without the -o/--overwrite '
+ 'option being set.')
+ os.mkdir(args.results_path)
results = framework.results.TestrunResult()
backends.set_meta(args.backend, results)
--
2.7.0
More information about the Piglit
mailing list