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
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
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 get_config_bool, get_config_file
|
from scripts.lib.zulip_tools import get_config, get_config_file
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def send_email_mirror(
|
||||||
|
|
||||||
if not urlsplit(host).scheme:
|
if not urlsplit(host).scheme:
|
||||||
config_file = get_config_file()
|
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://"
|
scheme = "http://" if http_only else "https://"
|
||||||
host = scheme + host
|
host = scheme + host
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ from scripts.lib.zulip_tools import (
|
||||||
DEPLOYMENTS_DIR,
|
DEPLOYMENTS_DIR,
|
||||||
assert_running_as_root,
|
assert_running_as_root,
|
||||||
get_config,
|
get_config,
|
||||||
get_config_bool,
|
|
||||||
get_config_file,
|
get_config_file,
|
||||||
get_zulip_pwent,
|
get_zulip_pwent,
|
||||||
listening_publicly,
|
listening_publicly,
|
||||||
|
@ -221,12 +220,12 @@ if not (args.skip_restart or args.skip_puppet):
|
||||||
# We need to temporarily hold pgroonga, if installed -- upgrading
|
# We need to temporarily hold pgroonga, if installed -- upgrading
|
||||||
# it without running the appropriate upgrade SQL can cause
|
# it without running the appropriate upgrade SQL can cause
|
||||||
# PostgreSQL to crash
|
# 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"])
|
subprocess.check_call(["apt-mark", "hold", "postgresql-*-pgdg-pgroonga"])
|
||||||
logging.info("Upgrading system packages...")
|
logging.info("Upgrading system packages...")
|
||||||
subprocess.check_call(["apt-get", "update"])
|
subprocess.check_call(["apt-get", "update"])
|
||||||
subprocess.check_call(["apt-get", "-y", "--with-new-pkgs", "upgrade"])
|
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"])
|
subprocess.check_call(["apt-mark", "unhold", "postgresql-*-pgdg-pgroonga"])
|
||||||
|
|
||||||
# To bootstrap zulip-puppet-apply, we need to install the system yaml
|
# To bootstrap zulip-puppet-apply, we need to install the system yaml
|
||||||
|
|
|
@ -16,7 +16,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timedelta
|
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
|
from urllib.parse import SplitResult
|
||||||
|
|
||||||
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
DEPLOYMENTS_DIR = "/home/zulip/deployments"
|
||||||
|
@ -583,24 +583,26 @@ def assert_running_as_root(strip_lib_from_paths: bool = False) -> None:
|
||||||
sys.exit(1)
|
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(
|
def get_config(
|
||||||
config_file: configparser.RawConfigParser,
|
config_file: configparser.RawConfigParser,
|
||||||
section: str,
|
section: str,
|
||||||
key: str,
|
key: str,
|
||||||
default_value: str = "",
|
default_value: Union[str, bool] = "",
|
||||||
) -> str:
|
) -> Union[str, bool]:
|
||||||
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:
|
|
||||||
if config_file.has_option(section, key):
|
if config_file.has_option(section, key):
|
||||||
val = config_file.get(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
|
# 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.lower() in ["1", "y", "t", "true", "yes", "enable", "enabled"]
|
||||||
|
return val
|
||||||
return default_value
|
return default_value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ from scripts.lib.zulip_tools import (
|
||||||
ENDC,
|
ENDC,
|
||||||
OKGREEN,
|
OKGREEN,
|
||||||
WARNING,
|
WARNING,
|
||||||
get_config_bool,
|
get_config,
|
||||||
get_config_file,
|
get_config_file,
|
||||||
get_tornado_ports,
|
get_tornado_ports,
|
||||||
has_application_server,
|
has_application_server,
|
||||||
|
@ -185,7 +185,7 @@ if has_application_server():
|
||||||
if (
|
if (
|
||||||
action == "restart"
|
action == "restart"
|
||||||
and not args.less_graceful
|
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")
|
and os.path.exists("/home/zulip/deployments/uwsgi-control")
|
||||||
):
|
):
|
||||||
# See if it's currently running
|
# See if it's currently running
|
||||||
|
|
Loading…
Reference in New Issue