scripts/lib/unpack-zulip: Avoid shelling out for rm, mv, mkdir, ln.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2018-07-18 17:50:15 -04:00 committed by Tim Abbott
parent 9bad4003c6
commit a61eebd9e3
1 changed files with 8 additions and 8 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python3
import os
import shutil
import sys
import subprocess
import datetime
import tempfile
import glob
@ -10,7 +10,7 @@ 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, \
get_deployment_version, is_invalid_upgrade
get_deployment_version, is_invalid_upgrade, overwrite_symlink
import version
if len(sys.argv) != 2:
@ -31,14 +31,14 @@ if is_invalid_upgrade(current_version, new_version):
"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])
shutil.rmtree(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",
os.path.join(deploy_path, "zproject/prod_settings.py")])
subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "next")])
shutil.move(glob.glob(os.path.join(extract_path, "zulip-server-*"))[0], deploy_path)
os.rmdir(extract_path)
overwrite_symlink("/etc/zulip/settings.py",
os.path.join(deploy_path, "zproject/prod_settings.py"))
overwrite_symlink(deploy_path, os.path.join(DEPLOYMENTS_DIR, "next"))
print(deploy_path)
sys.exit(0)