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
|
2014-01-09 22:37:19 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2014-01-09 23:14:47 +01:00
|
|
|
import time
|
2014-01-09 22:37:19 +01:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
2014-01-09 22:37:19 +01:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
|
|
from django.conf import settings
|
|
|
|
|
2016-07-24 17:32:04 +02:00
|
|
|
from typing import Dict, List
|
|
|
|
|
2014-01-09 22:37:19 +01:00
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
|
|
|
STATIC_PATH = 'static/'
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def get_templates():
|
|
|
|
# type: () -> List[str]
|
2016-10-05 01:36:26 +02:00
|
|
|
return (glob.glob(os.path.join(STATIC_PATH, 'templates/*.handlebars')) +
|
2018-02-23 16:20:33 +01:00
|
|
|
glob.glob(os.path.join(STATIC_PATH, 'templates/settings/*.handlebars')) +
|
|
|
|
glob.glob(os.path.join(STATIC_PATH, 'templates/widgets/*.handlebars')))
|
2014-01-09 23:14:47 +01:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run():
|
|
|
|
# type: () -> None
|
2017-01-24 05:50:04 +01:00
|
|
|
subprocess.check_call(['node', 'node_modules/.bin/handlebars'] +
|
|
|
|
get_templates() +
|
|
|
|
['--output', os.path.join(STATIC_PATH, 'templates/compiled.js'),
|
|
|
|
'--known', 'if,unless,each,with'])
|
2014-01-09 22:37:19 +01:00
|
|
|
|
2017-02-28 05:42:19 +01:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def add_error_stamp_file(file_path):
|
|
|
|
# type: (str) -> None
|
2017-02-28 05:42:19 +01:00
|
|
|
file_dir = os.path.dirname(file_path)
|
|
|
|
if not os.path.exists(file_dir):
|
|
|
|
os.makedirs(file_dir)
|
|
|
|
open(file_path, 'a').close()
|
|
|
|
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def remove_error_stamp_file(file_path):
|
|
|
|
# type: (str) -> None
|
2017-02-28 05:42:19 +01:00
|
|
|
if os.path.exists(file_path):
|
|
|
|
os.remove(file_path)
|
|
|
|
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def run_forever():
|
|
|
|
# type: () -> None
|
2014-01-09 23:14:47 +01:00
|
|
|
# Keep polling for file changes, similar to how Django does it in
|
|
|
|
# django/utils/autoreload.py. If any of our templates change, rebuild
|
|
|
|
# compiled.js
|
2017-05-17 22:48:11 +02:00
|
|
|
mtimes = {} # type: Dict[str, float]
|
2017-02-28 05:42:19 +01:00
|
|
|
error_file_path = os.path.join(settings.DEPLOY_ROOT,
|
|
|
|
'var/handlebars-templates/compile.error')
|
2014-01-09 23:14:47 +01:00
|
|
|
while True:
|
|
|
|
changed = False
|
|
|
|
for fn in get_templates():
|
|
|
|
new_mtime = os.stat(fn).st_mtime
|
|
|
|
if new_mtime != mtimes.get(fn, None):
|
|
|
|
changed = True
|
|
|
|
mtimes[fn] = new_mtime
|
|
|
|
if changed:
|
2016-03-10 17:15:34 +01:00
|
|
|
print('Recompiling templates')
|
2014-01-09 23:14:47 +01:00
|
|
|
try:
|
|
|
|
run()
|
2017-02-28 05:42:19 +01:00
|
|
|
remove_error_stamp_file(error_file_path)
|
2016-03-10 17:15:34 +01:00
|
|
|
print('done')
|
2017-03-05 10:25:27 +01:00
|
|
|
except Exception:
|
2017-02-28 05:42:19 +01:00
|
|
|
add_error_stamp_file(error_file_path)
|
|
|
|
print('\n\n\n\033[91mPLEASE FIX!!\033[0m\n\n')
|
|
|
|
|
2014-01-09 23:14:47 +01:00
|
|
|
time.sleep(0.200)
|
|
|
|
|
2014-01-09 22:37:19 +01:00
|
|
|
if __name__ == '__main__':
|
2014-01-09 23:14:47 +01:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'forever':
|
2016-05-24 17:20:48 +02:00
|
|
|
try:
|
|
|
|
run_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print(sys.argv[0], "exited after receiving KeyboardInterrupt")
|
|
|
|
else:
|
|
|
|
run()
|