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
def config_list(mailman_bin: Path, mailing_list: str):
def config_list(mailman_bin: Path, mailing_list: str, dry_run: bool):
config_changes = """
# TODO: set real_name, moderator, subject prefix, and reply-to address
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:
config_file.write(config_changes)
config_file.flush()
command = [
mailman_bin / "config_list",
"--inputfile",
config_file.name,
mailing_list,
]
if dry_run:
command.append("--checkonly")
output = subprocess.run(
[
mailman_bin / "config_list",
"--inputfile",
config_file.name,
mailing_list,
],
command,
encoding="ascii",
capture_output=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
if list_name in existing_lists:
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)
else:
print(f"Skipping {list_name}, as it does not exist in Mailman")