summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-11-13 15:51:53 -0800
committerDylan Baker <dylan@pnwbakers.com>2016-06-01 07:08:43 -0700
commitaaf55584a42d83fc3a14449cbe5681e0a2e42a82 (patch)
tree17a75c1c6fd69eeed6471faa6c3c54645e9a5eb1
parentcb821fa13b3376ea515bf16f4227f20b1cdfc6eb (diff)
framework: core.checkDir raises PiglitException
This requires each caller that sets failifexists=True to handle the error, but it allows them to set a custom message or handle the failure themselves, rather than just bailing. This makes the function more generically useful, and removes a layering violation. Signed-off-by: Dylan Baker <dylanx.c.baker@intel.com>
-rw-r--r--framework/core.py4
-rw-r--r--framework/programs/summary.py8
-rw-r--r--unittests/core_tests.py2
3 files changed, 9 insertions, 5 deletions
diff --git a/framework/core.py b/framework/core.py
index a75e59868..d052bd524 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -120,9 +120,7 @@ def checkDir(dirname, failifexists):
os.stat(dirname)
except OSError as e:
if e.errno not in [errno.ENOENT, errno.ENOTDIR] and failifexists:
- raise exceptions.PiglitFatalError(
- "%(dirname)s exists already.\nUse --overwrite if "
- "you want to overwrite it.\n" % locals())
+ raise exceptions.PiglitException
try:
if not os.path.exists(dirname):
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index b42675f22..13368e4fe 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -101,7 +101,13 @@ def html(input_):
shutil.rmtree(args.summaryDir)
# If the requested directory doesn't exist, create it or throw an error
- core.checkDir(args.summaryDir, not args.overwrite)
+ try:
+ core.checkDir(args.summaryDir, not args.overwrite)
+ except exceptions.PiglitException:
+ raise exceptions.PiglitFatalError(
+ '{} already exists.\n'
+ 'use -o/--overwrite if you want to overwrite it.'.format(
+ args.summaryDir))
# Merge args.list and args.resultsFiles
if args.list:
diff --git a/unittests/core_tests.py b/unittests/core_tests.py
index 043440b47..e1523363f 100644
--- a/unittests/core_tests.py
+++ b/unittests/core_tests.py
@@ -278,7 +278,7 @@ class TestPiglitConfig(object):
@utils.capture_stderr
-@nt.raises(exceptions.PiglitFatalError)
+@nt.raises(exceptions.PiglitException)
def test_check_dir_exists_fail():
"""core.check_dir: if the directory exists and failifexsits is True fail"""
with mock.patch('framework.core.os.stat', mock.Mock(side_effect=OSError)):