Support dry run for config_list

This commit is contained in:
Adam Goldsmith 2023-01-09 21:34:28 -05:00
parent c8f3e229c8
commit ef8a299e65

View File

@ -13,7 +13,7 @@ import tempfile
import requests import requests
def config_list(mailman_bin: Path, mailing_list: str): def config_list(mailman_bin: Path, mailing_list: str, dry_run: bool):
config_changes = """ config_changes = """
# TODO: set real_name, moderator, subject prefix, and reply-to address # TODO: set real_name, moderator, subject prefix, and reply-to address
from_is_list = 1 from_is_list = 1
@ -38,13 +38,18 @@ forward_auto_discards = 0 # don't notify admin about discards
with tempfile.NamedTemporaryFile("w", suffix=".py") as config_file: with tempfile.NamedTemporaryFile("w", suffix=".py") as config_file:
config_file.write(config_changes) config_file.write(config_changes)
config_file.flush() config_file.flush()
output = subprocess.run(
[ command = [
mailman_bin / "config_list", mailman_bin / "config_list",
"--inputfile", "--inputfile",
config_file.name, config_file.name,
mailing_list, mailing_list,
], ]
if dry_run:
command.append("--checkonly")
output = subprocess.run(
command,
encoding="ascii", encoding="ascii",
capture_output=True, capture_output=True,
check=True, check=True,
@ -97,7 +102,7 @@ def main(mailman_bin: Path, api: str, api_auth: str, list_suffix: str, dry_run:
list_name = name + list_suffix list_name = name + list_suffix
if list_name in existing_lists: if list_name in existing_lists:
print(f"Configuring/syncing {list_name}...") print(f"Configuring/syncing {list_name}...")
config_list(mailman_bin, list_name) config_list(mailman_bin, list_name, dry_run)
sync_members(mailman_bin, list_name, members, dry_run) sync_members(mailman_bin, list_name, members, dry_run)
else: else:
print(f"Skipping {list_name}, as it does not exist in Mailman") print(f"Skipping {list_name}, as it does not exist in Mailman")