clean: Longer but easier to maintain for me.

This commit is contained in:
Julien Palard 2024-01-02 09:40:30 +01:00
parent b5b638c997
commit 02344ed6f2
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
1 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,31 @@
#!/bin/sh
#!/usr/bin/env python3.12
import sys
from pathlib import Path
import shutil
find -maxdepth 4 \
\( -name '*~' -o -name '#*#' -o -name .tox -o -name .mypy_cache \) \
-print0 | xargs -0 rm -vfr
def find(path, maxdepth=3, prune=()):
for child in path.iterdir():
if child.name in prune:
continue
yield child
if child.is_dir() and maxdepth > 0:
yield from find(child, prune=prune, maxdepth=maxdepth - 1)
def rm(path):
print(f"rm -fr {path}")
if "-n" in sys.argv:
return
if path.is_file():
path.unlink()
else:
shutil.rmtree(path)
PRUNE = {"backup", "auto-save-list"}
TO_DROP = {Path(".tox"), Path(".mypy_cache"), Path(".envrc"), Path(".venv"), Path("*~"), Path("#*#")}
for file in find(Path("."), prune=PRUNE):
if any(file.match(pat) for pat in TO_DROP):
rm(file)