| 65 | |
| 66 | |
| 67 | def rmtree(path): |
| 68 | # On Windows, running shutil.rmtree on a folder that contains read-only |
| 69 | # files throws errors. To workaround this, if removing a path fails, we make |
| 70 | # the path writable and then try again |
| 71 | def onerror(func, path, unused_exc_info): # error handler for rmtree |
| 72 | if not os.access(path, os.W_OK): |
| 73 | os.chmod(path, stat.S_IWUSR) |
| 74 | func(path) |
| 75 | else: |
| 76 | # Swallow errors for now (on Windows there seems to be something weird |
| 77 | # going on and we can't remove the temp directory even after all files |
| 78 | # in it have been successfully removed) |
| 79 | pass |
| 80 | |
| 81 | shutil.rmtree(path, onerror=onerror) |
| 82 | logging.debug('Removed dir {0}'.format(path)) |
| 83 | |
| 84 | |
| 85 | def write_file(fp, contents=''): |