Skip to content

Commit

Permalink
Merge pull request #2126 from YunoHost/app_cache_clenup
Browse files Browse the repository at this point in the history
Add a cleanup option to app_caches.py
  • Loading branch information
alexAubin authored Mar 13, 2024
2 parents 3a08c7c + 2e12fd0 commit bab6f34
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tools/app_caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
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:
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit bab6f34

Please sign in to comment.