mirror of https://github.com/zulip/zulip.git
upgrade-zulip-from-git: Refactor deploy_options logic to zulip_tools.py.
This a preparatory commit moving the deploy_options logic to zulip_tools.py so it can be imported and used in upgrade-zulip.
This commit is contained in:
parent
32f24bff8d
commit
29dce7c9b9
|
@ -6,25 +6,20 @@ import subprocess
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
|
from typing import List
|
||||||
|
import configparser
|
||||||
|
|
||||||
config_file = configparser.RawConfigParser()
|
|
||||||
config_file.read("/etc/zulip/zulip.conf")
|
|
||||||
LOCAL_GIT_CACHE_DIR = '/srv/zulip.git'
|
LOCAL_GIT_CACHE_DIR = '/srv/zulip.git'
|
||||||
|
|
||||||
try:
|
|
||||||
remote_url = config_file.get('deployment', 'git_repo_url')
|
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
||||||
remote_url = "https://github.com/zulip/zulip.git"
|
|
||||||
try:
|
|
||||||
deploy_options = config_file.get('deployment', 'deploy_options').strip().split()
|
|
||||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
|
||||||
deploy_options = []
|
|
||||||
|
|
||||||
os.environ["PYTHONUNBUFFERED"] = "y"
|
os.environ["PYTHONUNBUFFERED"] = "y"
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, WARNING, ENDC, make_deploy_path, \
|
||||||
get_deployment_lock, overwrite_symlink, release_deployment_lock, su_to_zulip, assert_running_as_root
|
get_deployment_lock, overwrite_symlink, release_deployment_lock, su_to_zulip, assert_running_as_root, \
|
||||||
|
get_config_file, get_deploy_options, get_config
|
||||||
|
|
||||||
|
config_file = get_config_file()
|
||||||
|
deploy_options = get_deploy_options(config_file)
|
||||||
|
remote_url = get_config(config_file, 'deployment', 'git_repo_url', "https://github.com/zulip/zulip.git")
|
||||||
|
|
||||||
assert_running_as_root(strip_lib_from_paths=True)
|
assert_running_as_root(strip_lib_from_paths=True)
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,10 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import configparser
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Sequence, Set, Any, Dict, List
|
from typing import Sequence, Set, Any, Dict, List, Optional
|
||||||
|
|
||||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||||
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")
|
||||||
|
@ -410,3 +411,18 @@ def assert_running_as_root(strip_lib_from_paths: bool=False) -> None:
|
||||||
if not is_root():
|
if not is_root():
|
||||||
print("{} must be run as root.".format(script_name))
|
print("{} must be run as root.".format(script_name))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def get_config(config_file, section, key, default_value=""):
|
||||||
|
# type: (configparser.RawConfigParser, str, str, str) -> str
|
||||||
|
if config_file.has_option(section, key):
|
||||||
|
return config_file.get(section, key)
|
||||||
|
return default_value
|
||||||
|
|
||||||
|
def get_config_file() -> configparser.RawConfigParser:
|
||||||
|
config_file = configparser.RawConfigParser()
|
||||||
|
config_file.read("/etc/zulip/zulip.conf")
|
||||||
|
return config_file
|
||||||
|
|
||||||
|
def get_deploy_options(config_file):
|
||||||
|
# type: (configparser.RawConfigParser) -> List[str]
|
||||||
|
return get_config(config_file, 'deployment', 'deploy_options', "").strip().split()
|
||||||
|
|
Loading…
Reference in New Issue