py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-05-03 23:44:31 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2016-06-28 05:28:53 +02:00
|
|
|
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
2016-05-03 23:44:31 +02:00
|
|
|
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()
|
2016-06-28 05:28:53 +02:00
|
|
|
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()
|
2016-06-28 05:39:22 +02:00
|
|
|
used_caches.add(os.path.join(VENV_CACHE_DIR, hash_val.decode('utf-8')))
|
2016-05-03 23:44:31 +02:00
|
|
|
|
|
|
|
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,))
|