From d3c6596d7c893bcdd55fcdaea4b87656a45e91cd Mon Sep 17 00:00:00 2001
From: dave <dave@dtu.dk>
Date: Mon, 1 Feb 2016 14:13:51 +0100
Subject: [PATCH] exist_ok does not exists for os.makedirs in PY27

---
 wetb/gtsdf/gtsdf.py      | 4 +++-
 wetb/hawc2/htc_file.py   | 4 +++-
 wetb/hawc2/log_file.py   | 4 +++-
 wetb/hawc2/shear_file.py | 4 +++-
 wetb/hawc2/simulation.py | 8 ++++++--
 5 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/wetb/gtsdf/gtsdf.py b/wetb/gtsdf/gtsdf.py
index 396695b..b948765 100644
--- a/wetb/gtsdf/gtsdf.py
+++ b/wetb/gtsdf/gtsdf.py
@@ -223,7 +223,9 @@ def save(filename, data, **kwargs):
 
     if not filename.lower().endswith('.hdf5'):
         filename += ".hdf5"
-    os.makedirs(os.path.dirname(os.path.abspath(filename)), exist_ok=True)
+    # exist_ok does not exist in Python27
+    if not os.path.exists(os.path.dirname(os.path.abspath(filename))):
+        os.makedirs(os.path.dirname(os.path.abspath(filename)))#, exist_ok=True)
     f = h5py.File(filename, "w")
     try:
         f.attrs["type"] = "General time series data format"
diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py
index 709637c..21427ca 100644
--- a/wetb/hawc2/htc_file.py
+++ b/wetb/hawc2/htc_file.py
@@ -82,7 +82,9 @@ class HTCFile(HTCContents, HTCDefaults):
             filename = self.filename
         else:
             self.filename = filename
-        os.makedirs(os.path.dirname(filename), exist_ok=True)
+        # exist_ok does not exist in Python27
+        if not os.path.exists():
+            os.makedirs(os.path.dirname(filename))#, exist_ok=True)
         with open(filename, 'w') as fid:
             fid.write(str(self))
 
diff --git a/wetb/hawc2/log_file.py b/wetb/hawc2/log_file.py
index 7d051ea..d8cde89 100644
--- a/wetb/hawc2/log_file.py
+++ b/wetb/hawc2/log_file.py
@@ -67,7 +67,9 @@ class LogFile(object):
     def __str__(self):
         return self.txt
     def clear(self):
-        os.makedirs(os.path.dirname(self.filename), exist_ok=True)
+        # exist_ok does not exist in Python27
+        if not os.path.exists(os.path.dirname(self.filename)):
+            os.makedirs(os.path.dirname(self.filename))#, exist_ok=True)
         with open(self.filename, 'w'):
             pass
         self.reset()
diff --git a/wetb/hawc2/shear_file.py b/wetb/hawc2/shear_file.py
index 03413ab..04a768b 100644
--- a/wetb/hawc2/shear_file.py
+++ b/wetb/hawc2/shear_file.py
@@ -51,7 +51,9 @@ def save(filename, y_coordinates, z_coordinates, u=None, v=None, w=None):
 
             assert vuw[i].shape == shape, (i, vuw[i].shape, shape)
 
-    os.makedirs(os.path.dirname(filename), exist_ok=True)
+    # exist_ok does not exist in Python27
+    if not os.path.exists(os.path.dirname(filename)):
+        os.makedirs(os.path.dirname(filename))#, exist_ok=True)
     with open(filename, 'w') as fid:
         fid.write(" # autogenerated shear file\n")
         fid.write("  %d %d\n" % (len(y_coordinates), len(z_coordinates)))
diff --git a/wetb/hawc2/simulation.py b/wetb/hawc2/simulation.py
index db26a98..f4d38e7 100644
--- a/wetb/hawc2/simulation.py
+++ b/wetb/hawc2/simulation.py
@@ -138,7 +138,9 @@ class Simulation(object):
                 src = os.path.join(self.modelpath, src)
             for src_file in glob.glob(src):
                 dst = os.path.join(self.tmp_modelpath, os.path.relpath(src_file, self.modelpath))
-                os.makedirs(os.path.dirname(dst), exist_ok=True)
+                # exist_ok does not exist in Python27
+                if not os.path.exists(os.path.dirname(dst)):
+                    os.makedirs(os.path.dirname(dst))#, exist_ok=True)
                 shutil.copy(src_file, dst)
                 if not os.path.isfile(dst) or os.stat(dst).st_size != os.stat(src_file).st_size:
                     print ("error copy ", dst)
@@ -169,7 +171,9 @@ class Simulation(object):
 
             for src_file in glob.glob(src):
                 dst_file = os.path.join(self.modelpath, os.path.relpath(src_file, self.tmp_modelpath))
-                os.makedirs(os.path.dirname(dst_file), exist_ok=True)
+                # exist_ok does not exist in Python27
+                if not os.path.exists(os.path.dirname(dst_file)):
+                    os.makedirs(os.path.dirname(dst_file))#, exist_ok=True)
                 if not os.path.isfile(dst_file) or os.path.getmtime(dst_file) != os.path.getmtime(src_file):
                     shutil.copy(src_file, dst_file)
 
-- 
GitLab