From 1c2f65b43322c0d945581934c2e250b8dca8b771 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 19 Dec 2023 10:19:24 +0100 Subject: [PATCH] fix: load remote blocklist for export and fix diff with toml input --- fediverse_blocklist_deploy/cli.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fediverse_blocklist_deploy/cli.py b/fediverse_blocklist_deploy/cli.py index ed5df7c..5192282 100644 --- a/fediverse_blocklist_deploy/cli.py +++ b/fediverse_blocklist_deploy/cli.py @@ -12,12 +12,16 @@ from fediverse_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_ def load_blocklist_file(filename: str) -> [Instance]: - with open(filename, "r") as f: - data = toml.load(f) - instances = [] - for instance_dict in data["instances"]: - instance = Instance(instance_dict) - instances.append(instance) + if filename.endswith("json"): + with open(filename) as f: + instances = blocklist_json_to_instances(json.load(f)) + else: + with open(filename, "r") as f: + data = toml.load(f) + instances = [] + for instance_dict in data["instances"]: + instance = Instance(instance_dict) + instances.append(instance) return instances @@ -121,11 +125,10 @@ def cli(): token = os.getenv('MBD_TOKEN') """Get a remote blocklist only when necessary""" - if args.action in ["diff", "deploy"]: + if args.action in ["diff", "deploy", "export"]: """if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)""" if args.remote_blocklist: - with open(args.remote_blocklist) as f: - remote_blocklist = blocklist_json_to_instances(json.load(f)) + remote_blocklist = load_blocklist_file(args.remote_blocklist) else: remote_blocklist = load_blocklist_from_instance(server=args.server, token=token)