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
|
2017-06-18 02:41:27 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import print_function
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from scripts.lib.node_cache import generate_sha1sum_node_modules
|
|
|
|
|
2017-07-22 00:51:36 +02:00
|
|
|
NODE_MODULES_CACHE_PATH = "/srv/zulip-npm-cache"
|
2017-06-18 02:41:27 +02:00
|
|
|
if "--travis" in sys.argv:
|
2017-07-22 00:57:22 +02:00
|
|
|
NODE_MODULES_CACHE_PATH = os.path.join(os.environ["HOME"], "zulip-npm-cache")
|
2017-06-18 02:41:27 +02:00
|
|
|
try:
|
2017-07-27 23:22:52 +02:00
|
|
|
subprocess.check_output([os.path.join(NODE_MODULES_CACHE_PATH, "yarn/bin/yarn"), '--version'])
|
2017-06-18 02:41:27 +02:00
|
|
|
except OSError:
|
2017-07-27 23:22:52 +02:00
|
|
|
print('yarn not found. Most probably we are running static-analysis and '
|
|
|
|
'hence yarn is not installed. Exiting without cleaning npm cache.')
|
2017-06-18 02:41:27 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
sha1sum = generate_sha1sum_node_modules()
|
2017-07-22 01:11:16 +02:00
|
|
|
current_cache_dir_base = os.path.join(NODE_MODULES_CACHE_PATH, sha1sum)
|
2017-07-22 01:15:15 +02:00
|
|
|
current_success_stamp = os.path.join(current_cache_dir_base, '.success-stamp')
|
2017-06-18 02:41:27 +02:00
|
|
|
|
2017-07-27 23:22:52 +02:00
|
|
|
print("Current cache stamp at %s" % (current_success_stamp,))
|
|
|
|
|
2017-07-22 00:51:36 +02:00
|
|
|
for cache_dir_base in os.listdir(NODE_MODULES_CACHE_PATH):
|
2017-07-22 01:08:11 +02:00
|
|
|
node_modules_dir = os.path.join(NODE_MODULES_CACHE_PATH, cache_dir_base)
|
2017-07-22 01:11:16 +02:00
|
|
|
if node_modules_dir == current_cache_dir_base and os.path.exists(current_success_stamp):
|
2017-07-22 01:08:11 +02:00
|
|
|
print("Keeping used node_modules cache dir %s" % (node_modules_dir,))
|
2017-07-22 01:07:15 +02:00
|
|
|
else:
|
2017-07-22 01:08:11 +02:00
|
|
|
print("Cleaning unused node_modules cache dir %s" % (node_modules_dir,))
|
|
|
|
subprocess.check_call(["sudo", "rm", "-rf", node_modules_dir])
|