Fixed up Unreal cleanup script. Included folders and files that might be included with source control, removed some configured paths. Tidied up script.
This commit is contained in:
parent
229bcdb9c2
commit
9e74109604
1 changed files with 68 additions and 58 deletions
|
|
@ -24,17 +24,18 @@ ignore_folders = {
|
||||||
'.git'
|
'.git'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# NOTE: These are recursively deleted.
|
||||||
dirs_to_delete = {
|
dirs_to_delete = {
|
||||||
".idea",
|
|
||||||
".vs",
|
".vs",
|
||||||
"Binaries",
|
|
||||||
"DerivedDataCache",
|
"DerivedDataCache",
|
||||||
"Intermediate",
|
"Intermediate",
|
||||||
"Saved",
|
"Saved",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# NOTE: These are recursively deleted.
|
||||||
|
# Be careful not to mark for deletion files that are included with your version
|
||||||
|
# control.
|
||||||
files_to_delete = {
|
files_to_delete = {
|
||||||
".vsconfig",
|
|
||||||
"*.sln",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_file_directory():
|
def get_file_directory():
|
||||||
|
|
@ -54,82 +55,91 @@ def clean_unreal_temps(dry_run = False, verbose = False, quiet = False):
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f"Iterating {target_path} for directories and files to cleanup{', doing a dry-run ' if dry_run else ''}...")
|
print(f"Iterating {target_path} for directories and files to cleanup{', doing a dry-run ' if dry_run else ''}...")
|
||||||
|
|
||||||
# TODO: If not doing a dry run could give people a 5+ second countdown or something to cancel the script.
|
# TODO: If not doing a dry run could give people a 5+ second countdown or
|
||||||
|
# something to cancel the script.
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
counted_iterated = 0
|
counted_iterated = 0
|
||||||
|
|
||||||
for root, dirs, files, in os.walk(target_path):
|
if len(dirs_to_delete) or len(files_to_delete):
|
||||||
counted_iterated += 1
|
for root, dirs, files, in os.walk(target_path):
|
||||||
|
counted_iterated += 1
|
||||||
|
|
||||||
# Don't waste time processing an empty directory.
|
# Don't waste time processing an empty directory.
|
||||||
if len(dirs) == 0 and len(files) == 0:
|
if len(dirs) == 0 and len(files) == 0:
|
||||||
continue
|
|
||||||
|
|
||||||
root_path = pathlib.Path(root)
|
|
||||||
|
|
||||||
for dir in reversed(dirs):
|
|
||||||
if dir in ignore_folders:
|
|
||||||
dirs.remove(dir)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if dir not in dirs_to_delete:
|
root_path = pathlib.Path(root)
|
||||||
# We do want os.walk to continue to look into this directory.
|
|
||||||
continue
|
|
||||||
|
|
||||||
# We're processing a directory we're going to delete, no need to leave
|
if len(dirs_to_delete) or len(ignore_folders):
|
||||||
# os.walk to iterate over the files in this directory. Helpful during
|
for dir in reversed(dirs):
|
||||||
# a dry-run to run similarly during non-dry-run. But also if we were
|
if dir in ignore_folders:
|
||||||
# multi-threaded, this wouldn't try to iterate files we're already
|
dirs.remove(dir)
|
||||||
# trying to delete.
|
continue
|
||||||
dirs.remove(dir)
|
|
||||||
|
|
||||||
dir_path = root_path / dir
|
if dir not in dirs_to_delete:
|
||||||
|
# We do want os.walk to continue to look into this directory.
|
||||||
|
continue
|
||||||
|
|
||||||
if not dry_run:
|
# We're processing a directory we're going to delete, no need to leave
|
||||||
shutil.rmtree(dir_path, onerror=del_rw)
|
# os.walk to iterate over the files in this directory. Helpful during
|
||||||
|
# a dry-run to run similarly during non-dry-run. But also if we were
|
||||||
|
# multi-threaded, this wouldn't try to iterate files we're already
|
||||||
|
# trying to delete.
|
||||||
|
dirs.remove(dir)
|
||||||
|
|
||||||
count_dirs_deleted += 1
|
dir_path = root_path / dir
|
||||||
|
|
||||||
if verbose and not quiet:
|
if not dry_run:
|
||||||
if dry_run:
|
shutil.rmtree(dir_path, onerror=del_rw)
|
||||||
print(f" Pretend Deleted: {dir_path}")
|
|
||||||
else:
|
|
||||||
print(f" Deleted: {dir_path}")
|
|
||||||
|
|
||||||
for file in files:
|
count_dirs_deleted += 1
|
||||||
if not any(pathlib.PurePath(file).match(pattern) for pattern in files_to_delete):
|
|
||||||
continue
|
|
||||||
|
|
||||||
file_path = root_path / file
|
if verbose and not quiet:
|
||||||
|
if dry_run:
|
||||||
|
print(f" Pretend Deleted: {dir_path}")
|
||||||
|
else:
|
||||||
|
print(f" Deleted: {dir_path}")
|
||||||
|
|
||||||
if not dry_run:
|
if len(files_to_delete):
|
||||||
file_path.unlink()
|
for file in files:
|
||||||
|
if not any(pathlib.PurePath(file).match(pattern) for pattern in files_to_delete):
|
||||||
|
continue
|
||||||
|
|
||||||
count_files_deleted += 1
|
file_path = root_path / file
|
||||||
|
|
||||||
if verbose and not quiet:
|
if not dry_run:
|
||||||
if dry_run:
|
file_path.unlink()
|
||||||
print(f" Pretend Deleted: {dir_path}")
|
|
||||||
else:
|
|
||||||
print(f" Deleted: {dir_path}")
|
|
||||||
|
|
||||||
# Done, summarize everything.
|
count_files_deleted += 1
|
||||||
if not quiet:
|
|
||||||
prefix = None
|
if verbose and not quiet:
|
||||||
if dry_run:
|
if dry_run:
|
||||||
prefix = "Dry-run, would have deleted"
|
print(f" Pretend Deleted: {file_path}")
|
||||||
else:
|
else:
|
||||||
prefix = "Deleted"
|
print(f" Deleted: {file_path}")
|
||||||
|
|
||||||
|
# Done, summarize everything.
|
||||||
|
if not quiet:
|
||||||
|
prefix = None
|
||||||
|
if dry_run:
|
||||||
|
prefix = "Dry-run, would have deleted"
|
||||||
|
else:
|
||||||
|
prefix = "Deleted"
|
||||||
|
|
||||||
|
|
||||||
print(f" {prefix} {count_dirs_deleted} director{'ies' if count_dirs_deleted != 1 else 'y'}, {count_files_deleted} file{'s' if count_files_deleted != 1 else ''}. Iterated {counted_iterated} paths.")
|
print(f" {prefix} {count_dirs_deleted} director{'ies' if count_dirs_deleted != 1 else 'y'}, {count_files_deleted} file{'s' if count_files_deleted != 1 else ''}. Iterated {counted_iterated} paths.")
|
||||||
|
|
||||||
if count_dirs_deleted > 0:
|
# TODO: Add up the file size deleted (including from deleted folders)
|
||||||
print(f" (NOTE: Number of {'potentially ' if dry_run else ''}deleted files does not currently include a count of files from a deleted directory.)")
|
# in a verbose run, or have that as an extra param.
|
||||||
|
|
||||||
print(f" Done. Finished in {str(time.time() - start)}s")
|
if count_dirs_deleted > 0:
|
||||||
|
print(f" (NOTE: Number of {'potentially ' if dry_run else ''}deleted files does not include files from a deleted directory.)")
|
||||||
|
|
||||||
|
print(f" Done. Finished in {str(time.time() - start)}s")
|
||||||
|
else:
|
||||||
|
print(" Skipped. Nothing configured to be deleted.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue