mirror of https://github.com/zulip/zulip.git
zulip_tools: Unify get_config and get_config_bool using overloads.
This commit is contained in:
parent
0ff1fb2e21
commit
f9f9392b93
|
@ -54,7 +54,7 @@ from urllib.parse import urlencode, urljoin, urlsplit
|
|||
from urllib.request import Request, urlopen
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))
|
||||
from scripts.lib.zulip_tools import get_config_bool, get_config_file
|
||||
from scripts.lib.zulip_tools import get_config, get_config_file
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
|
@ -133,7 +133,7 @@ def send_email_mirror(
|
|||
|
||||
if not urlsplit(host).scheme:
|
||||
config_file = get_config_file()
|
||||
http_only = get_config_bool(config_file, "application_server", "http_only", False)
|
||||
http_only = get_config(config_file, "application_server", "http_only", False)
|
||||
scheme = "http://" if http_only else "https://"
|
||||
host = scheme + host
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ from scripts.lib.zulip_tools import (
|
|||
DEPLOYMENTS_DIR,
|
||||
assert_running_as_root,
|
||||
get_config,
|
||||
get_config_bool,
|
||||
get_config_file,
|
||||
get_zulip_pwent,
|
||||
listening_publicly,
|
||||
|
@ -221,12 +220,12 @@ if not (args.skip_restart or args.skip_puppet):
|
|||
# We need to temporarily hold pgroonga, if installed -- upgrading
|
||||
# it without running the appropriate upgrade SQL can cause
|
||||
# PostgreSQL to crash
|
||||
if get_config_bool(config_file, "machine", "pgroonga"):
|
||||
if get_config(config_file, "machine", "pgroonga", False):
|
||||
subprocess.check_call(["apt-mark", "hold", "postgresql-*-pgdg-pgroonga"])
|
||||
logging.info("Upgrading system packages...")
|
||||
subprocess.check_call(["apt-get", "update"])
|
||||
subprocess.check_call(["apt-get", "-y", "--with-new-pkgs", "upgrade"])
|
||||
if get_config_bool(config_file, "machine", "pgroonga"):
|
||||
if get_config(config_file, "machine", "pgroonga", False):
|
||||
subprocess.check_call(["apt-mark", "unhold", "postgresql-*-pgdg-pgroonga"])
|
||||
|
||||
# To bootstrap zulip-puppet-apply, we need to install the system yaml
|
||||
|
|
|
@ -16,7 +16,7 @@ import sys
|
|||
import time
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from typing import IO, Any, Dict, List, Sequence, Set
|
||||
from typing import IO, Any, Dict, List, Sequence, Set, Union, overload
|
||||
from urllib.parse import SplitResult
|
||||
|
||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||
|
@ -583,24 +583,26 @@ def assert_running_as_root(strip_lib_from_paths: bool = False) -> None:
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
@overload
|
||||
def get_config(
|
||||
config_file: configparser.RawConfigParser, section: str, key: str, default_value: str = ""
|
||||
) -> str: ...
|
||||
@overload
|
||||
def get_config(
|
||||
config_file: configparser.RawConfigParser, section: str, key: str, default_value: bool
|
||||
) -> bool: ...
|
||||
def get_config(
|
||||
config_file: configparser.RawConfigParser,
|
||||
section: str,
|
||||
key: str,
|
||||
default_value: str = "",
|
||||
) -> str:
|
||||
if config_file.has_option(section, key):
|
||||
return config_file.get(section, key)
|
||||
return default_value
|
||||
|
||||
|
||||
def get_config_bool(
|
||||
config_file: configparser.RawConfigParser, section: str, key: str, default_value: bool = False
|
||||
) -> bool:
|
||||
default_value: Union[str, bool] = "",
|
||||
) -> Union[str, bool]:
|
||||
if config_file.has_option(section, key):
|
||||
val = config_file.get(section, key)
|
||||
if isinstance(default_value, bool):
|
||||
# This list is parallel to puppet/zulip/lib/puppet/functions/zulipconf.rb
|
||||
return val.lower() in ["1", "y", "t", "true", "yes", "enable", "enabled"]
|
||||
return val
|
||||
return default_value
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ from scripts.lib.zulip_tools import (
|
|||
ENDC,
|
||||
OKGREEN,
|
||||
WARNING,
|
||||
get_config_bool,
|
||||
get_config,
|
||||
get_config_file,
|
||||
get_tornado_ports,
|
||||
has_application_server,
|
||||
|
@ -185,7 +185,7 @@ if has_application_server():
|
|||
if (
|
||||
action == "restart"
|
||||
and not args.less_graceful
|
||||
and get_config_bool(config_file, "application_server", "rolling_restart")
|
||||
and get_config(config_file, "application_server", "rolling_restart", False)
|
||||
and os.path.exists("/home/zulip/deployments/uwsgi-control")
|
||||
):
|
||||
# See if it's currently running
|
||||
|
|
Loading…
Reference in New Issue