mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
zulip_tools.py: Extract may_be_perform_purging() function.
Based on the `dry_run` flag, this function either purges the list of directories passed to them or prints a listing of the directories it would have purged/kept_back, had the `dry_run` flag been false.
This commit is contained in:
committed by
Tim Abbott
parent
5662726a22
commit
20f062f726
@@ -50,7 +50,8 @@ def main():
|
||||
# type: () -> None
|
||||
args = parse_args()
|
||||
caches_in_use = get_caches_in_use(args.threshold_days)
|
||||
purge_unused_caches(EMOJI_CACHE_PATH, caches_in_use, args.threshold_days, args.dry_run, "emoji")
|
||||
purge_unused_caches(
|
||||
EMOJI_CACHE_PATH, caches_in_use, args.threshold_days, args.dry_run, "emoji cache")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -61,7 +61,8 @@ def main():
|
||||
args = parse_args()
|
||||
caches_in_use = get_caches_in_use(args.threshold_days)
|
||||
purge_unused_caches(
|
||||
NODE_MODULES_CACHE_PATH, caches_in_use, args.threshold_days, args.dry_run, "node modules")
|
||||
NODE_MODULES_CACHE_PATH, caches_in_use, args.threshold_days,
|
||||
args.dry_run, "node modules cache")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -50,7 +50,8 @@ def main():
|
||||
# type: () -> None
|
||||
args = parse_args()
|
||||
caches_in_use = get_caches_in_use(args.threshold_days)
|
||||
purge_unused_caches(VENV_CACHE_DIR, caches_in_use, args.threshold_days, args.dry_run, "venv")
|
||||
purge_unused_caches(
|
||||
VENV_CACHE_DIR, caches_in_use, args.threshold_days, args.dry_run, "venv cache")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -227,19 +227,7 @@ def purge_unused_caches(caches_dir, caches_in_use, threshold_days, dry_run, cach
|
||||
caches_to_purge = get_caches_to_be_purged(caches_dir, caches_in_use, threshold_days)
|
||||
caches_to_keep = all_caches - caches_to_purge
|
||||
|
||||
if dry_run:
|
||||
print("Performing a dry run...")
|
||||
else:
|
||||
print("Cleaning unused %s caches..." % (cache_type,))
|
||||
|
||||
for cache_dir in caches_to_purge:
|
||||
print("Cleaning unused %s cache: %s" % (cache_type, cache_dir))
|
||||
if not dry_run:
|
||||
subprocess.check_call(["sudo", "rm", "-rf", cache_dir])
|
||||
|
||||
for cache_dir in caches_to_keep:
|
||||
print("Keeping used %s cache: %s" % (cache_type, cache_dir))
|
||||
|
||||
may_be_perform_purging(caches_to_purge, caches_to_keep, cache_type, dry_run)
|
||||
print("Done!\n")
|
||||
|
||||
def generate_sha1sum_emoji(zulip_path):
|
||||
@@ -264,3 +252,18 @@ def generate_sha1sum_emoji(zulip_path):
|
||||
sha.update(emoji_datasource_version)
|
||||
|
||||
return sha.hexdigest()
|
||||
|
||||
def may_be_perform_purging(dirs_to_purge, dirs_to_keep, dir_type, dry_run):
|
||||
# type: (Set[Text], Set[Text], Text, bool) -> None
|
||||
if dry_run:
|
||||
print("Performing a dry run...")
|
||||
else:
|
||||
print("Cleaning unused %ss..." % (dir_type,))
|
||||
|
||||
for directory in dirs_to_purge:
|
||||
print("Cleaning unused %s: %s" % (dir_type, directory))
|
||||
if not dry_run:
|
||||
subprocess.check_call(["sudo", "rm", "-rf", directory])
|
||||
|
||||
for directory in dirs_to_keep:
|
||||
print("Keeping used %s: %s" % (dir_type, directory))
|
||||
|
||||
Reference in New Issue
Block a user