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:
shubham-padia 2018-12-15 11:35:27 +05:30 committed by Tim Abbott
parent 32f24bff8d
commit 29dce7c9b9
2 changed files with 25 additions and 14 deletions

View File

@ -6,25 +6,20 @@ import subprocess
import logging
import time
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'
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"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
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)

View File

@ -15,9 +15,10 @@ import tempfile
import time
import json
import uuid
import configparser
if False:
from typing import Sequence, Set, Any, Dict, List
from typing import Sequence, Set, Any, Dict, List, Optional
DEPLOYMENTS_DIR = "/home/zulip/deployments"
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():
print("{} must be run as root.".format(script_name))
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()