2017-06-18 02:41:27 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
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:
|
|
|
|
subprocess.check_output(['npm', '--version'])
|
|
|
|
except OSError:
|
|
|
|
print('NPM not found. Most probably we are running static-analysis and '
|
|
|
|
'hence npm is not installed. Exiting without cleaning npm cache.')
|
|
|
|
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)
|
|
|
|
current_cached_node_modules = os.path.join(current_cache_dir_base, 'node_modules')
|
2017-07-22 01:10:38 +02:00
|
|
|
current_success_stamp = os.path.join(current_cached_node_modules, '.success-stamp')
|
2017-06-18 02:41:27 +02:00
|
|
|
|
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])
|