Refactored mkdir_p function to use os.makedirs

This commit is contained in:
Osaetin Daniel
2017-12-11 20:18:27 +01:00
parent a3ea3ea35f
commit 322c835d2d
+10 -14
View File
@@ -15,20 +15,16 @@ def mkdir_p(newdir):
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
"""
if os.path.isdir(newdir):
pass
elif os.path.isfile(newdir):
raise OSError(
"a file with the same name as the desired "
"dir, '%s', already exists." % newdir
)
else:
head, tail = os.path.split(newdir)
if head and not os.path.isdir(head):
mkdir_p(head)
if tail:
os.mkdir(newdir)
try:
os.makedirs(newdir)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(newdir):
pass
else:
raise OSError (
"a file with the same name as the desired "
"dir, '%s', already exists." % newdir
)
class HerokuDiscoverRunner(DiscoverRunner):