2021-04-25 10:37:14 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
sys.path.append(ZULIP_PATH)
|
|
|
|
|
2022-01-12 21:52:48 +01:00
|
|
|
from scripts.lib.zulip_tools import maybe_perform_purging, parse_cache_script_args
|
2021-04-25 10:37:14 +02:00
|
|
|
|
|
|
|
YARN_CACHE_PATH = os.path.expanduser("~/.cache/yarn/")
|
|
|
|
CURRENT_VERSION = "v6"
|
|
|
|
|
|
|
|
|
|
|
|
def remove_unused_versions_dir(args: argparse.Namespace) -> None:
|
|
|
|
"""Deletes cache data from obsolete Yarn versions.
|
|
|
|
|
|
|
|
Yarn does not provide an interface for removing obsolete data from
|
|
|
|
~/.cache/yarn for packages that you haven't installed in years; but one
|
|
|
|
can always remove the cache entirely.
|
|
|
|
"""
|
|
|
|
current_version_dir = os.path.join(YARN_CACHE_PATH, CURRENT_VERSION)
|
2021-04-27 12:18:45 +02:00
|
|
|
try:
|
2021-08-02 23:16:44 +02:00
|
|
|
dirs_to_purge = {
|
|
|
|
os.path.join(YARN_CACHE_PATH, directory)
|
|
|
|
for directory in os.listdir(YARN_CACHE_PATH)
|
|
|
|
if directory != CURRENT_VERSION
|
|
|
|
}
|
2021-04-27 12:18:45 +02:00
|
|
|
except FileNotFoundError:
|
|
|
|
return
|
2021-04-25 10:37:14 +02:00
|
|
|
|
2021-06-18 00:46:01 +02:00
|
|
|
no_headings = getattr(args, "no_headings", False)
|
2022-01-12 21:52:48 +01:00
|
|
|
maybe_perform_purging(
|
2021-04-25 10:37:14 +02:00
|
|
|
dirs_to_purge,
|
|
|
|
{current_version_dir},
|
|
|
|
"yarn cache",
|
|
|
|
args.dry_run,
|
|
|
|
args.verbose,
|
2021-06-18 00:46:01 +02:00
|
|
|
no_headings,
|
2021-04-25 10:37:14 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def main(args: argparse.Namespace) -> None:
|
|
|
|
remove_unused_versions_dir(args)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = parse_cache_script_args("This script cleans redundant Zulip yarn caches.")
|
|
|
|
main(args)
|