File tree Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Expand file tree Collapse file tree 1 file changed +20
-12
lines changed Original file line number Diff line number Diff line change @@ -1012,18 +1012,26 @@ def mkdirs(newdir, mode=0o777):
1012
1012
> mkdir -p NEWDIR
1013
1013
> chmod MODE NEWDIR
1014
1014
"""
1015
- try :
1016
- if not os .path .exists (newdir ):
1017
- parts = os .path .split (newdir )
1018
- for i in range (1 , len (parts ) + 1 ):
1019
- thispart = os .path .join (* parts [:i ])
1020
- if not os .path .exists (thispart ):
1021
- os .makedirs (thispart , mode )
1022
-
1023
- except OSError as err :
1024
- # Reraise the error unless it's about an already existing directory
1025
- if err .errno != errno .EEXIST or not os .path .isdir (newdir ):
1026
- raise
1015
+ # this functionality is now in core python as of 3.2
1016
+ if six .PY3 :
1017
+ os .makedirs (newdir , mode = mode , exist_ok = True )
1018
+ return
1019
+
1020
+
1021
+ def _make_leaf (newdir , mode ):
1022
+ if os .path .exists (newdir ):
1023
+ return
1024
+ try :
1025
+ os .makedirs (thispart , mode )
1026
+ except OSError as err :
1027
+ # Reraise the error unless it's about an already existing directory
1028
+ if err .errno != errno .EEXIST or not os .path .isdir (newdir ):
1029
+ raise
1030
+
1031
+ parts = os .path .split (newdir )
1032
+ for i in range (1 , len (parts ) + 1 ):
1033
+ thispart = os .path .join (* parts [:i ])
1034
+ _make_leaf (thispart , mode )
1027
1035
1028
1036
1029
1037
class GetRealpathAndStat (object ):
You can’t perform that action at this time.
0 commit comments