Skip to content

Commit 02210cd

Browse files
committed
Merge pull request #1130 from nipy/enh/add_mkdir_p
Enh/add mkdir p closes #1127
2 parents 3fa6f3e + 7f8a555 commit 02210cd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

nipype/utils/config.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from json import load, dump
1414
import os
1515
import shutil
16+
import errno
1617
from StringIO import StringIO
1718
from warnings import warn
1819

@@ -55,15 +56,25 @@
5556
interval = 1209600
5657
""" % (homedir, os.getcwd())
5758

59+
60+
def mkdir_p(path):
61+
try:
62+
os.makedirs(path)
63+
except OSError as exc:
64+
if exc.errno == errno.EEXIST and os.path.isdir(path):
65+
pass
66+
else:
67+
raise
68+
69+
5870
class NipypeConfig(object):
5971
"""Base nipype config class
6072
"""
6173

6274
def __init__(self, *args, **kwargs):
6375
self._config = ConfigParser.ConfigParser()
6476
config_dir = os.path.expanduser('~/.nipype')
65-
if not os.path.exists(config_dir):
66-
os.makedirs(config_dir)
77+
mkdir_p(config_dir)
6778
old_config_file = os.path.expanduser('~/.nipype.cfg')
6879
new_config_file = os.path.join(config_dir, 'nipype.cfg')
6980
# To be deprecated in two releases

nipype/utils/filemanip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from ..interfaces.traits_extension import isdefined
2020
from .misc import is_container
21+
from .config import mkdir_p
2122

2223
from .. import logging, config
2324
fmlogger = logging.getLogger("filemanip")

0 commit comments

Comments
 (0)