2017-05-23 23:04:54 +02:00
|
|
|
from typing import Optional, Tuple
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
import os
|
2019-06-20 18:27:09 +02:00
|
|
|
import sys
|
2017-03-26 04:48:25 +02:00
|
|
|
from distutils.version import LooseVersion
|
2016-10-14 00:57:08 +02:00
|
|
|
from version import PROVISION_VERSION
|
2017-10-18 05:02:44 +02:00
|
|
|
from scripts.lib.zulip_tools import get_dev_uuid_var_path
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
def get_major_version(v):
|
|
|
|
# type: (str) -> int
|
|
|
|
return int(v.split('.')[0])
|
|
|
|
|
|
|
|
def get_version_file():
|
|
|
|
# type: () -> str
|
2017-10-18 05:02:44 +02:00
|
|
|
uuid_var_path = get_dev_uuid_var_path()
|
|
|
|
return os.path.join(uuid_var_path, 'provision_version')
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
PREAMBLE = '''
|
|
|
|
Before we run tests, we make sure your provisioning version
|
|
|
|
is correct by looking at var/provision_version, which is at
|
|
|
|
version %s, and we compare it to the version in source
|
|
|
|
control (version.py), which is %s.
|
|
|
|
'''
|
|
|
|
|
|
|
|
def preamble(version):
|
|
|
|
# type: (str) -> str
|
|
|
|
text = PREAMBLE % (version, PROVISION_VERSION)
|
|
|
|
text += '\n'
|
|
|
|
return text
|
|
|
|
|
|
|
|
NEED_TO_DOWNGRADE = '''
|
|
|
|
It looks like you checked out a branch that expects an older
|
|
|
|
version of dependencies than the version you provisioned last.
|
|
|
|
This may be ok, but it's likely that you either want to rebase
|
|
|
|
your branch on top of upstream/master or re-provision your VM.
|
2016-12-10 17:57:41 +01:00
|
|
|
|
2017-01-14 11:19:26 +01:00
|
|
|
Do this: `./tools/provision`
|
2016-10-14 00:57:08 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
NEED_TO_UPGRADE = '''
|
|
|
|
It looks like you checked out a branch that has added
|
2016-12-30 00:59:46 +01:00
|
|
|
dependencies beyond what you last provisioned. Your command
|
|
|
|
is likely to fail until you add dependencies by provisioning.
|
2016-12-10 17:57:41 +01:00
|
|
|
|
2017-01-14 11:19:26 +01:00
|
|
|
Do this: `./tools/provision`
|
2016-10-14 00:57:08 +02:00
|
|
|
'''
|
|
|
|
|
|
|
|
def get_provisioning_status():
|
2017-05-23 23:04:54 +02:00
|
|
|
# type: () -> Tuple[bool, Optional[str]]
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
version_file = get_version_file()
|
|
|
|
if not os.path.exists(version_file):
|
|
|
|
# If the developer doesn't have a version_file written by
|
|
|
|
# a previous provision, then we don't do any safety checks
|
|
|
|
# here on the assumption that the developer is managing
|
2017-01-14 11:19:26 +01:00
|
|
|
# their own dependencies and not running provision.
|
2016-10-14 00:57:08 +02:00
|
|
|
return True, None
|
|
|
|
|
2019-07-14 21:37:08 +02:00
|
|
|
with open(version_file, 'r') as f:
|
|
|
|
version = f.read().strip()
|
2016-10-14 00:57:08 +02:00
|
|
|
|
|
|
|
# Normal path for people that provision--we're all good!
|
|
|
|
if version == PROVISION_VERSION:
|
|
|
|
return True, None
|
|
|
|
|
|
|
|
# We may be more provisioned than the branch we just moved to. As
|
|
|
|
# long as the major version hasn't changed, then we should be ok.
|
2017-03-26 04:48:25 +02:00
|
|
|
if LooseVersion(version) > LooseVersion(PROVISION_VERSION):
|
2016-10-14 00:57:08 +02:00
|
|
|
if get_major_version(version) == get_major_version(PROVISION_VERSION):
|
|
|
|
return True, None
|
|
|
|
else:
|
|
|
|
return False, preamble(version) + NEED_TO_DOWNGRADE
|
|
|
|
|
|
|
|
return False, preamble(version) + NEED_TO_UPGRADE
|
2019-06-20 18:27:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def assert_provisioning_status_ok(force):
|
|
|
|
# type: (bool) -> None
|
|
|
|
if not force:
|
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|