[Piglit] [PATCH 03/14] core.py: remove flag from checkDir, use exception block

Dylan Baker dylan at pnwbakers.com
Fri May 6 20:07:13 UTC 2016


From: Dylan Baker <baker.dylan.c at gmail.com>

This simplifies the function.
---
 framework/core.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/framework/core.py b/framework/core.py
index 870a708..c339572 100644
--- a/framework/core.py
+++ b/framework/core.py
@@ -117,17 +117,13 @@ def get_config(arg=None):
 
 # Ensure the given directory exists
 def checkDir(dirname, failifexists):
-    exists = True
     try:
         os.stat(dirname)
     except OSError as e:
-        if e.errno in [errno.ENOENT, 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)
+        if e.errno not in [errno.ENOENT, errno.ENOTDIR] 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)
-- 
2.8.2



More information about the Piglit mailing list