python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -17,9 +17,12 @@ from scripts.lib.zulip_tools import get_config_file, get_tornado_ports
def write_realm_nginx_config_line(f: Any, host: str, port: str) -> None:
f.write(f"""if ($host = '{host}') {{
f.write(
f"""if ($host = '{host}') {{
set $tornado_server http://tornado{port};
}}\n""")
}}\n"""
)
# Basic system to do Tornado sharding. Writes two output .tmp files that need
# to be renamed to the following files to finalize the changes:
@@ -32,12 +35,14 @@ def write_updated_configs() -> None:
config_file = get_config_file()
ports = get_tornado_ports(config_file)
expected_ports = list(range(9800, max(ports)+1))
assert sorted(ports) == expected_ports, \
f"ports ({sorted(ports)}) must be contiguous, starting with 9800"
expected_ports = list(range(9800, max(ports) + 1))
assert (
sorted(ports) == expected_ports
), f"ports ({sorted(ports)}) must be contiguous, starting with 9800"
with open('/etc/zulip/nginx_sharding.conf.tmp', 'w') as nginx_sharding_conf_f, \
open('/etc/zulip/sharding.json.tmp', 'w') as sharding_json_f:
with open('/etc/zulip/nginx_sharding.conf.tmp', 'w') as nginx_sharding_conf_f, open(
'/etc/zulip/sharding.json.tmp', 'w'
) as sharding_json_f:
if len(ports) == 1:
nginx_sharding_conf_f.write("set $tornado_server http://tornado;\n")
@@ -46,9 +51,10 @@ def write_updated_configs() -> None:
nginx_sharding_conf_f.write("set $tornado_server http://tornado9800;\n")
shard_map: Dict[str, int] = {}
external_host = subprocess.check_output([os.path.join(BASE_DIR, 'scripts/get-django-setting'),
'EXTERNAL_HOST'],
universal_newlines=True).strip()
external_host = subprocess.check_output(
[os.path.join(BASE_DIR, 'scripts/get-django-setting'), 'EXTERNAL_HOST'],
universal_newlines=True,
).strip()
for port in config_file["tornado_sharding"]:
shards = config_file["tornado_sharding"][port].strip()
@@ -65,12 +71,14 @@ def write_updated_configs() -> None:
sharding_json_f.write(json.dumps(shard_map) + '\n')
parser = argparse.ArgumentParser(
description="Adjust Tornado sharding configuration",
)
parser.add_argument(
"--errors-ok", action="store_true",
help="Exits 1 if there are no changes; if there are errors or changes, exits 0."
"--errors-ok",
action="store_true",
help="Exits 1 if there are no changes; if there are errors or changes, exits 0.",
)
options = parser.parse_args()