@@ -91,20 +91,31 @@ def copytree(src, dst, symlinks=False, ignore=None):
91
91
return shutil .copy2 (s , d )
92
92
93
93
94
- def maybe_make (directory ):
94
+ def maybe_make (directory , mode = 0o777 , parents = False , exist_ok = False ):
95
95
"""
96
- Makes a directory only if it doesn't already exist
97
-
96
+ Create a directory at this given path, but only if the directory does
97
+ not already exist.
98
+
98
99
:param directory: Directory to create
99
100
:type directory: str or pathlib.Path
100
-
101
+ :param mode: Combined with the process’ umask value to determine the file mode and access flags
102
+ :type mode:
103
+ :param parents: If ``False`` (the default), a missing parent raises a :class:`~python:FileNotFoundError`.
104
+ If ``True``, any missing parents of this path are created as needed; they are created with the
105
+ default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
106
+ :type parents: bool
107
+ :param exist_ok: If ``False`` (the default), a :class:`~python:FileExistsError` is raised if the
108
+ target directory already exists. If ``True``, :class:`~python:FileExistsError` exceptions
109
+ will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
110
+ component is not an existing non-directory file.
111
+ :type exist_ok: bool
101
112
"""
102
113
103
114
if not isinstance (directory , pathlib .Path ):
104
115
directory = pathlib .Path (directory )
105
116
106
117
if not directory .exists ():
107
- directory .mkdir ()
118
+ directory .mkdir (mode , parents , exist_ok )
108
119
109
120
110
121
def parent_path (path ):
0 commit comments