mirror of https://github.com/zulip/zulip.git
29 lines
1.1 KiB
Python
Executable File
29 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from __future__ import absolute_import
|
|
from __future__ import print_function
|
|
import glob
|
|
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()
|
|
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.decode('utf-8')))
|
|
|
|
for cache_dir_base in os.listdir(VENV_CACHE_DIR):
|
|
cache_dir = os.path.join(VENV_CACHE_DIR, cache_dir_base)
|
|
if cache_dir not in used_caches:
|
|
print("Cleaning unused venv %s" % (cache_dir,))
|
|
subprocess.check_call(["sudo", "rm", "-rf", cache_dir])
|
|
else:
|
|
print("Keeping used venv %s" % (cache_dir,))
|