Commit d3c6596d authored by David Verelst's avatar David Verelst
Browse files

exist_ok does not exists for os.makedirs in PY27

parent 85ca8f61
......@@ -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"
......
......@@ -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))
......
......@@ -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()
......
......@@ -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)))
......
......@@ -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)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment