mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Move mkdir_p function to utils module
This commit is contained in:
+1
-20
@@ -5,29 +5,10 @@ import toml
|
||||
|
||||
from requests.compat import OrderedDict
|
||||
|
||||
from .utils import format_toml, multi_split
|
||||
from .utils import format_toml, multi_split, mkdir_p
|
||||
from .utils import convert_deps_from_pip, convert_deps_to_pip
|
||||
|
||||
|
||||
def mkdir_p(newdir):
|
||||
"""works the way a good mkdir should :)
|
||||
- already exists, silently complete
|
||||
- regular file in the way, raise an exception
|
||||
- parent directory(ies) does not exist, make them as well
|
||||
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
class Project(object):
|
||||
"""docstring for Project"""
|
||||
def __init__(self):
|
||||
|
||||
+24
-1
@@ -1,7 +1,9 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import delegator
|
||||
import click
|
||||
import requirements
|
||||
import tempfile
|
||||
|
||||
|
||||
def format_toml(data):
|
||||
@@ -111,3 +113,24 @@ def convert_deps_to_pip(deps, r=True):
|
||||
f = tempfile.NamedTemporaryFile(suffix='-requirements.txt', delete=False)
|
||||
f.write('\n'.join(dependencies).encode('utf-8'))
|
||||
return f.name
|
||||
|
||||
|
||||
def mkdir_p(newdir):
|
||||
"""works the way a good mkdir should :)
|
||||
- already exists, silently complete
|
||||
- regular file in the way, raise an exception
|
||||
- parent directory(ies) does not exist, make them as well
|
||||
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
|
||||
"""
|
||||
if os.path.isdir(newdir):
|
||||
pass
|
||||
elif os.path.isfile(newdir):
|
||||
raise OSError("a file with the same name as the desired dir, '{0}', already exists.".format(newdir))
|
||||
else:
|
||||
head, tail = os.path.split(newdir)
|
||||
if head and not os.path.isdir(head):
|
||||
mkdir_p(head)
|
||||
if tail:
|
||||
os.mkdir(newdir)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user