From 404c61ba97bfa322be0bb7ffaf610411a519547c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 27 Jun 2016 20:28:53 -0700 Subject: [PATCH] clean-venv-cache: Use better approach to pruning caches. Rather than looking at which venvs are used by this particular build, we instead look at which venvs have a hash that is the hash_reqs value of a current requirements.txt file. --- tools/clean-venv-cache | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/clean-venv-cache b/tools/clean-venv-cache index f6f854d961..f6148563d8 100755 --- a/tools/clean-venv-cache +++ b/tools/clean-venv-cache @@ -6,17 +6,18 @@ import os import subprocess import sys +ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) VENV_CACHE_DIR = "/srv/zulip-venv-cache" if "--travis" in sys.argv: VENV_CACHE_DIR = os.path.join(os.environ["HOME"], "zulip-venv-cache") used_caches = set() -for d in glob.glob('/srv/zulip-*venv'): - used_caches.add(os.path.dirname(os.readlink(d))) -for d in ['/root/zulip/zulip-venv']: - if not os.path.exists(d): - continue - used_caches.add(os.path.dirname(os.readlink(d))) +hash_reqs = os.path.join(ZULIP_PATH, 'scripts', 'lib', 'hash_reqs.py') + +for filename in os.listdir(os.path.join(ZULIP_PATH, "requirements")): + requirements_file = os.path.join(ZULIP_PATH, "requirements", filename) + hash_val = subprocess.check_output([hash_reqs, requirements_file]).strip() + used_caches.add(os.path.join(VENV_CACHE_DIR, hash_val)) for cache_dir_base in os.listdir(VENV_CACHE_DIR): cache_dir = os.path.join(VENV_CACHE_DIR, cache_dir_base)