-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move shutil.rmtree() dance to new function delete_directory(), in new…
… file misc_utils.py
- Loading branch information
1 parent
84b26a4
commit d4ed760
Showing
2 changed files
with
20 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
import stat | ||
import shutil | ||
import logging | ||
from pathlib import Path | ||
from typing import Callable | ||
|
||
log = logging.getLogger('') | ||
|
||
|
||
def delete_directory(dir_to_delete: Path): | ||
def remove_readonly(func: Callable, path, excinfo): | ||
# Windows has a problem with deleting some git files | ||
log.debug(f'Problem removing {path}, attempting to make writable') | ||
os.chmod(path, stat.S_IWRITE) | ||
func(path) | ||
|
||
shutil.rmtree(dir_to_delete, onerror=remove_readonly) |