1
0
Fork 0

Add a cleanup option to app_caches.py

This commit is contained in:
Félix Piédallu 2024-03-13 23:13:27 +01:00
parent 10b972894e
commit d9e1182d38

View file

@ -17,8 +17,11 @@ from appslib.utils import (
from git import Repo
APPS_CACHE_DIR = REPO_APPS_ROOT / ".apps_cache"
def app_cache_folder(app: str) -> Path:
return REPO_APPS_ROOT / ".apps_cache" / app
return APPS_CACHE_DIR / app
def app_cache_clone(app: str, infos: dict[str, str]) -> None:
@ -84,14 +87,28 @@ def apps_cache_update_all(apps: dict[str, dict[str, Any]], parallel: int = 8) ->
pass
def apps_cache_cleanup(apps: dict[str, dict[str, Any]]) -> None:
for element in APPS_CACHE_DIR.iterdir():
if element.name not in apps.keys():
logging.warning(f"Removing {element}...")
if element.is_dir():
shutil.rmtree(element)
else:
element.unlink()
def __run_for_catalog():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="store_true")
parser.add_argument("-j", "--processes", type=int, default=8)
parser.add_argument("-c", "--cleanup", action="store_true", default=False,
help="Remove unknown directories from the app cache")
args = parser.parse_args()
if args.verbose:
logging.getLogger().setLevel(logging.INFO)
if args.cleanup:
apps_cache_cleanup(get_catalog())
apps_cache_update_all(get_catalog(), parallel=args.processes)