From d9e1182d38f8b04b6d3714e2403076a866555f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Wed, 13 Mar 2024 23:13:27 +0100 Subject: [PATCH] Add a cleanup option to app_caches.py --- app_caches.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app_caches.py b/app_caches.py index b991a98..cd6859d 100755 --- a/app_caches.py +++ b/app_caches.py @@ -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)