[Piglit] [PATCH 2/2] framework: remove last use of core.checkDir

Dylan Baker baker.dylan.c at gmail.com
Wed Jul 8 18:02:27 PDT 2015


With the previous change there is only one user of checkDir, which was
in need of refactor if it was going to be generally useful.

So instead, just remove it, the replacement is less code and it's
obvious what it does.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/core.py             | 23 -----------------------
 framework/programs/summary.py | 14 ++++++++++++--
 2 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index f9cdbfe..4add9fb 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -23,11 +23,9 @@
 # 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
@@ -114,27 +112,6 @@ 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 069aed9..b519ede 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -90,8 +90,18 @@ def html(input_):
     if path.exists(args.summaryDir) and args.overwrite:
         shutil.rmtree(args.summaryDir)
 
-    # If the requested directory doesn't exist, create it or throw an error
-    core.checkDir(args.summaryDir, not args.overwrite)
+    # 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 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)
 
     # Merge args.list and args.resultsFiles
     if args.list:
-- 
2.4.5



More information about the Piglit mailing list