unpack-zulip: Do 2-step upgrade for version <= 1.3.10.

If the current version is less than or equal to 1.3.10, first
recommend an upgrade to the version 1.4.3 and then to the final
version.
This commit is contained in:
Umair Khan 2017-06-21 17:32:22 +05:00 committed by showell
parent 090d7487cf
commit 908f099bb0
2 changed files with 34 additions and 1 deletions

View File

@ -10,7 +10,9 @@ import glob
os.environ["PYTHONUNBUFFERED"] = "y"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', ".."))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, make_deploy_path
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, make_deploy_path, \
get_deployment_version, is_invalid_upgrade
import version
if len(sys.argv) != 2:
print(FAIL + "Usage: %s <tarball>" % (sys.argv[0],) + ENDC)
@ -22,6 +24,17 @@ deploy_path = make_deploy_path()
extract_path = tempfile.mkdtemp()
subprocess.check_call(["tar", "-xf", tarball_path, "-C", extract_path])
new_version = get_deployment_version(extract_path)
current_version = version.ZULIP_VERSION
if is_invalid_upgrade(current_version, new_version):
print(FAIL +
"Your current version is very old. Please first upgrade to version "
"1.4.3 and then upgrade to {}.".format(new_version) +
ENDC)
subprocess.check_call(["rm", "-r", extract_path])
sys.exit(1)
subprocess.check_call(["mv", glob.glob(os.path.join(extract_path, "zulip-server-*"))[0], deploy_path])
subprocess.check_call(["rmdir", extract_path])
subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py",

View File

@ -4,6 +4,7 @@ import datetime
import errno
import os
import pwd
import re
import shutil
import subprocess
import sys
@ -25,6 +26,25 @@ ENDC = '\033[0m'
BLACKONYELLOW = '\x1b[0;30;43m'
WHITEONRED = '\x1b[0;37;41m'
def get_deployment_version(extract_path):
# type: (str) -> str
version = '0.0.0'
for item in os.listdir(extract_path):
item_path = os.path.join(extract_path, item)
if item.startswith('zulip-server') and os.path.isdir(item_path):
with open(os.path.join(item_path, 'version.py')) as f:
result = re.search('ZULIP_VERSION = "(.*)"', f.read())
if result:
version = result.groups()[0]
break
return version
def is_invalid_upgrade(current_version, new_version):
# type: (str, str) -> bool
if new_version > '1.4.3' and current_version <= '1.3.10':
return True
return False
def subprocess_text_output(args):
# type: (Sequence[str]) -> str
return subprocess.check_output(args, universal_newlines=True).strip()