Create directory and all sub-directories recursively at `location`. Raise Exceptions if it fails to create the directory. NOTE: this is essentailly a copy of commoncode.fileutils.create_dir()
(location)
| 33 | |
| 34 | |
| 35 | def _create_dir(location): |
| 36 | """ |
| 37 | Create directory and all sub-directories recursively at `location`. |
| 38 | Raise Exceptions if it fails to create the directory. |
| 39 | NOTE: this is essentailly a copy of commoncode.fileutils.create_dir() |
| 40 | """ |
| 41 | |
| 42 | if exists(location): |
| 43 | if not os.path.isdir(location): |
| 44 | err = ('Cannot create directory: existing file ' |
| 45 | 'in the way ''%(location)s.') |
| 46 | raise OSError(err % locals()) |
| 47 | return |
| 48 | |
| 49 | # may fail on win if the path is too long |
| 50 | # FIXME: consider using UNC ?\\ paths |
| 51 | try: |
| 52 | os.makedirs(location) |
| 53 | |
| 54 | # avoid multi-process TOCTOU conditions when creating dirs |
| 55 | # the directory may have been created since the exist check |
| 56 | except WindowsError as e: |
| 57 | # [Error 183] Cannot create a file when that file already exists |
| 58 | if e and e.winerror == 183: |
| 59 | if not os.path.isdir(location): |
| 60 | raise |
| 61 | else: |
| 62 | raise |
| 63 | except (IOError, OSError) as o: |
| 64 | if o.errno == errno.EEXIST: |
| 65 | if not os.path.isdir(location): |
| 66 | raise |
| 67 | else: |
| 68 | raise |
| 69 | |
| 70 | ################################################################################ |
| 71 | # INVARIABLE INSTALLATION-SPECIFIC, BUILT-IN LOCATIONS AND FLAGS |