Commit 5f8fd553 authored by André Anjos's avatar André Anjos 💬

Merge branch 'amohammadi-master-patch-38592' into 'master'

create_directories_safe: use the new exist_ok flag in os.makedirs.

See merge request !29
parents 8c178351 7015b0dd
Pipeline #38384 passed with stages
in 6 minutes and 32 seconds
......@@ -83,6 +83,7 @@ def _is_string(s):
isinstance(s, (bytes, str))
@numpy.deprecate(new_name="os.makedirs(directory, exist_ok=True)")
def create_directories_safe(directory, dryrun=False):
"""Creates a directory if it does not exists, with concurrent access support.
This function will also create any parent directories that might be required.
......@@ -97,17 +98,10 @@ def create_directories_safe(directory, dryrun=False):
``dryrun`` : bool
Only ``print`` the command to console, but do not execute it.
"""
try:
if dryrun:
print("[dry-run] mkdir -p '%s'" % directory)
else:
if directory and not os.path.exists(directory):
os.makedirs(directory)
except OSError as exc: # Python >2.5
import errno
if exc.errno != errno.EEXIST:
raise
if dryrun:
print("[dry-run] mkdir -p '%s'" % directory)
else:
os.makedirs(directory, exist_ok=True)
def load(inputs):
......
Markdown is supported
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