File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,29 @@ def unfrackpath(path):
2020 '''
2121 return os .path .normpath (os .path .realpath (os .path .expandvars (os .path .expanduser (path ))))
2222
23+ def prepare_writeable_dir (tree , mode = 0777 ):
24+ ''' make sure a directory exists and is writeable '''
25+
26+ # modify the mode to ensure the owner at least
27+ # has read/write access to this directory
28+ mode |= 0700
29+
30+ # make sure the tree path is always expanded
31+ # and normalized and free of symlinks
32+ tree = unfrackpath (tree )
33+
34+ if not os .path .exists (tree ):
35+ try :
36+ os .makedirs (tree , mode )
37+ except (IOError , OSError ), e :
38+ print ("Could not make dir %s: %s" % (tree , e ))
39+ sys .exit (1 )
40+ if not os .access (tree , os .W_OK ):
41+ print ("Cannot write to path %s" % tree )
42+ sys .exit (1 )
43+ return tree
44+
45+
2346def makedirs_safe (path , mode = None ):
2447 '''Safe way to create dirs in muliprocess/thread environments'''
2548 if not os .path .exists (path ):
You can’t perform that action at this time.
0 commit comments