From 322c835d2dcd8d848426a7f9df6da3bd8dbc8ba2 Mon Sep 17 00:00:00 2001 From: Osaetin Daniel Date: Mon, 11 Dec 2017 20:18:27 +0100 Subject: [PATCH] Refactored mkdir_p function to use os.makedirs --- django_heroku/core.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/django_heroku/core.py b/django_heroku/core.py index 5be2052..abaffff 100644 --- a/django_heroku/core.py +++ b/django_heroku/core.py @@ -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):