summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <baker.dylan.c@gmail.com>2015-07-16 17:07:36 -0700
committerDylan Baker <baker.dylan.c@gmail.com>2015-07-16 17:07:36 -0700
commitd66e0c76fc39dcbb0179fbd9b9553996407d46d3 (patch)
tree9cef8a043edd094b96470016f7aefbcf49f67cb1
parent992bbcec39c335892c2c618fe3923a6a0ce6ffa4 (diff)
Revert "framework: remove last use of core.checkDir"
-rw-r--r--framework/core.py23
-rw-r--r--framework/programs/summary.py14
2 files changed, 25 insertions, 12 deletions
diff --git a/framework/core.py b/framework/core.py
index 4add9fb92..f9cdbfe5b 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -23,9 +23,11 @@
# Piglit core
from __future__ import print_function, absolute_import
+import errno
import os
import re
import subprocess
+import sys
import ConfigParser
from framework import exceptions
@@ -112,6 +114,27 @@ def get_config(arg=None):
pass
+# Ensure the given directory exists
+def checkDir(dirname, failifexists):
+ exists = True
+ try:
+ os.stat(dirname)
+ except OSError as e:
+ if e.errno == errno.ENOENT or e.errno == errno.ENOTDIR:
+ exists = False
+
+ if exists and failifexists:
+ print("%(dirname)s exists already.\nUse --overwrite if "
+ "you want to overwrite it.\n" % locals(), file=sys.stderr)
+ exit(1)
+
+ try:
+ os.makedirs(dirname)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+
class Options(object):
""" Contains options for a piglit run
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index c8601c6ee..069aed961 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -90,18 +90,8 @@ def html(input_):
if path.exists(args.summaryDir) and args.overwrite:
shutil.rmtree(args.summaryDir)
- # If the directory exists and overwrite is specified, delete it so it can
- # be recreated shortly after, if it is empty follow this path too. If the
- # directory exists and is not empty, and args.overwite is Falsy, raise an
- # exception and exit. Finally create the new directory
- if os.path.exists(args.summaryDir):
- if args.overwrite or not os.listdir(args.summaryDir):
- shutil.rmtree(args.summaryDir)
- else:
- raise exceptions.PiglitFatalError(
- 'Results directory already exists and is not empty.\n'
- 'use -o/--overwrite to force.')
- os.mkdir(args.summaryDir)
+ # If the requested directory doesn't exist, create it or throw an error
+ core.checkDir(args.summaryDir, not args.overwrite)
# Merge args.list and args.resultsFiles
if args.list: