mirror of
https://github.com/derrod/legendary.git
synced 2025-01-03 04:45:28 +00:00
[utils] Allow silent deletion of files
This commit is contained in:
parent
51c8b67f91
commit
40f8c553ba
|
@ -27,7 +27,8 @@ def delete_folder(path: str, recursive=True) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def delete_filelist(path: str, filenames: List[str],
|
def delete_filelist(path: str, filenames: List[str],
|
||||||
delete_root_directory: bool = False) -> bool:
|
delete_root_directory: bool = False,
|
||||||
|
silent: bool = False) -> bool:
|
||||||
dirs = set()
|
dirs = set()
|
||||||
no_error = True
|
no_error = True
|
||||||
|
|
||||||
|
@ -40,7 +41,8 @@ def delete_filelist(path: str, filenames: List[str],
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(path, _dir, _fn))
|
os.remove(os.path.join(path, _dir, _fn))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Failed deleting file {filename} with {e!r}')
|
if not silent:
|
||||||
|
logger.error(f'Failed deleting file {filename} with {e!r}')
|
||||||
no_error = False
|
no_error = False
|
||||||
|
|
||||||
# add intermediate directories that would have been missed otherwise
|
# add intermediate directories that would have been missed otherwise
|
||||||
|
@ -58,14 +60,16 @@ def delete_filelist(path: str, filenames: List[str],
|
||||||
# directory has already been deleted, ignore that
|
# directory has already been deleted, ignore that
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Failed removing directory "{_dir}" with {e!r}')
|
if not silent:
|
||||||
|
logger.error(f'Failed removing directory "{_dir}" with {e!r}')
|
||||||
no_error = False
|
no_error = False
|
||||||
|
|
||||||
if delete_root_directory:
|
if delete_root_directory:
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Removing game directory failed with {e!r}')
|
if not silent:
|
||||||
|
logger.error(f'Removing game directory failed with {e!r}')
|
||||||
|
|
||||||
return no_error
|
return no_error
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue