From b85005d6034536c88b2d825de785c1d6ef314286 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 25 Dec 2022 02:25:24 -0500 Subject: [PATCH] Add dry run argument --- mailman_sync.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mailman_sync.py b/mailman_sync.py index 93786c4..0acb7e9 100755 --- a/mailman_sync.py +++ b/mailman_sync.py @@ -11,12 +11,12 @@ import subprocess import requests -def sync_members(mailman_bin: Path, mailing_list: str, members: list[str]): +def sync_members(mailman_bin: Path, mailing_list: str, members: list[str], dry_run: bool): members_data = "\n".join(members) output = subprocess.run( [ mailman_bin / "sync_members", - "--no-change", + "--no-change" if dry_run else "", "--welcome-msg=no", "--goodbye-msg=no", "--notifyadmin=no", @@ -32,7 +32,7 @@ def sync_members(mailman_bin: Path, mailing_list: str, members: list[str]): print(output.stdout) -def main(mailman_bin: Path, api: str, token: str, list_suffix: str): +def main(mailman_bin: Path, api: str, token: str, list_suffix: str, dry_run: bool): r = requests.get(api, headers={"Authorization": "Token " + token}) if not r.ok: print(f"Failed to get mailing list data from api: {r.status_code} {r.text}") @@ -48,7 +48,7 @@ def main(mailman_bin: Path, api: str, token: str, list_suffix: str): for name, members in certification_lists.items(): list_name = name + list_suffix if list_name in existing_lists: - sync_members(mailman_bin, list_name, members) + sync_members(mailman_bin, list_name, members, dry_run) else: print(f"Skipping {list_name}, as it does not exist in Mailman") @@ -64,10 +64,11 @@ if __name__ == "__main__": argp.add_argument("--api", required=True, help="API endpoint to retrieve JSON from") argp.add_argument("--token", required=True, help="Authorization Token for API") argp.add_argument("--list-suffix", help="Suffix for mailing lists") + argp.add_argument("-n", "--dry-run", help="Don't make changes, just print what would happen") args = argp.parse_args() try: - main(args.bin, args.api, args.token, args.list_suffix) + main(args.bin, args.api, args.token, args.list_suffix, args.dry_run) except subprocess.CalledProcessError as e: print(e.stderr) raise