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-01-03 17:16:08 +01:00
|
|
|
|
|
|
|
import os
|
|
|
|
import platform
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
2017-01-12 19:47:24 +01:00
|
|
|
if False:
|
|
|
|
from typing import Callable, List
|
2017-01-03 17:16:08 +01:00
|
|
|
|
|
|
|
TOOLS_DIR = os.path.dirname(__file__)
|
|
|
|
ROOT_DIR = os.path.dirname(TOOLS_DIR)
|
|
|
|
sys.path.insert(0, ROOT_DIR)
|
2017-10-18 05:02:44 +02:00
|
|
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
|
|
|
UUID_VAR_PATH = get_dev_uuid_var_path()
|
2017-01-03 17:16:08 +01:00
|
|
|
|
|
|
|
def run(check_func):
|
2017-10-31 07:34:20 +01:00
|
|
|
# type: (Callable[[], bool]) -> None
|
2017-01-03 17:16:08 +01:00
|
|
|
'''
|
|
|
|
This decorator simply runs functions. It makes it more
|
|
|
|
convenient to add new checks without a big main() function.
|
|
|
|
'''
|
|
|
|
rc = check_func()
|
|
|
|
if not rc:
|
|
|
|
sys.exit(1)
|
|
|
|
|
2017-01-03 20:07:27 +01:00
|
|
|
def run_command(args):
|
|
|
|
# type: (List[str]) -> None
|
|
|
|
print(' '.join(args))
|
|
|
|
subprocess.check_call(args)
|
|
|
|
|
2017-01-03 17:16:08 +01:00
|
|
|
@run
|
|
|
|
def check_python_version():
|
|
|
|
# type: () -> bool
|
|
|
|
subprocess.check_call(['/usr/bin/env', 'python', '-V'])
|
|
|
|
return True
|
|
|
|
|
|
|
|
@run
|
|
|
|
def pwd():
|
|
|
|
# type: () -> bool
|
2018-07-18 23:50:16 +02:00
|
|
|
print(os.getcwd())
|
2017-01-03 17:16:08 +01:00
|
|
|
return True
|
|
|
|
|
|
|
|
@run
|
|
|
|
def host_info():
|
|
|
|
# type: () -> bool
|
|
|
|
print(platform.platform())
|
|
|
|
return True
|
|
|
|
|
|
|
|
@run
|
|
|
|
def check_django():
|
|
|
|
# type: () -> bool
|
2017-01-12 20:21:05 +01:00
|
|
|
try:
|
|
|
|
import django
|
|
|
|
print('Django version:', django.get_version())
|
|
|
|
return True
|
|
|
|
except ImportError:
|
|
|
|
print('''
|
|
|
|
ERROR!
|
|
|
|
We cannot import Django, which is usually a
|
|
|
|
symptom of not having your Python venv
|
|
|
|
set up correctly.
|
|
|
|
|
|
|
|
Make sure your shell does this at init time:
|
|
|
|
|
2017-08-09 00:44:40 +02:00
|
|
|
source /srv/zulip-py3-venv/bin/activate
|
2017-01-12 20:21:05 +01:00
|
|
|
|
|
|
|
Or maybe you forget to run inside your VM?
|
|
|
|
''')
|
|
|
|
return False
|
2017-01-03 17:16:08 +01:00
|
|
|
|
|
|
|
@run
|
|
|
|
def provision_version():
|
|
|
|
# type: () -> bool
|
2017-10-18 05:02:44 +02:00
|
|
|
fn = os.path.join(UUID_VAR_PATH, 'provision_version')
|
2017-01-03 17:16:08 +01:00
|
|
|
with open(fn) as f:
|
|
|
|
version = f.read().strip()
|
|
|
|
print('latest version provisioned:', version)
|
|
|
|
from version import PROVISION_VERSION
|
|
|
|
print('desired version:', PROVISION_VERSION)
|
|
|
|
if version != PROVISION_VERSION:
|
|
|
|
print('You need to provision!')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
@run
|
|
|
|
def node_stuff():
|
|
|
|
# type: () -> bool
|
|
|
|
print('node version:')
|
|
|
|
subprocess.check_call(['node', '--version'])
|
|
|
|
return True
|
|
|
|
|
|
|
|
@run
|
|
|
|
def test_models():
|
|
|
|
# type: () -> bool
|
2017-01-04 17:48:54 +01:00
|
|
|
settings_module = "zproject.settings"
|
2017-01-03 17:16:08 +01:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
|
|
|
|
import django
|
|
|
|
django.setup()
|
|
|
|
from zerver.models import UserProfile, Realm
|
|
|
|
print('Num realms: ', Realm.objects.count())
|
|
|
|
print('Num users: ', UserProfile.objects.count())
|
|
|
|
return True
|
|
|
|
|
2017-01-03 20:07:27 +01:00
|
|
|
@run
|
|
|
|
def check_venv():
|
|
|
|
# type: () -> bool
|
|
|
|
path = os.path.join(ROOT_DIR, 'scripts', 'lib', 'hash_reqs.py')
|
|
|
|
cache_dir = '/srv/zulip-venv-cache/'
|
2017-11-17 02:41:06 +01:00
|
|
|
for fn in ['dev.txt']:
|
2017-01-03 20:07:27 +01:00
|
|
|
requirements_file = os.path.join(ROOT_DIR, "requirements", fn)
|
|
|
|
output = subprocess.check_output([path, requirements_file], universal_newlines=True)
|
|
|
|
sha1sum = output.split()[0]
|
|
|
|
print(fn, 'venv sha: ', sha1sum)
|
|
|
|
if not os.path.exists(os.path.join(cache_dir, sha1sum)):
|
|
|
|
print('Your venv may be improperly installed!')
|
|
|
|
return False
|
|
|
|
return True
|
2017-01-03 20:25:13 +01:00
|
|
|
|
|
|
|
@run
|
|
|
|
def check_migrations():
|
|
|
|
# type: () -> bool
|
|
|
|
print()
|
|
|
|
rc = subprocess.check_call('./tools/test-migrations')
|
|
|
|
return (rc == 0)
|