From 4ddac75d9a55cc145b310ecdff17a3ff55231bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Wed, 11 Jan 2023 20:21:01 +0100 Subject: [PATCH] Add nodelete option --- cli.py | 6 +++--- models.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli.py b/cli.py index 0d0ae47..ede52f8 100644 --- a/cli.py +++ b/cli.py @@ -68,8 +68,8 @@ def cli(): parser.add_argument('-i', '--input-file', help="The blocklist to use") parser.add_argument('-r', '--remote-blocklist', help="The remote blocklist as json for debugging reasons") parser.add_argument('-o', '--output', help="Filename where to export the blocklist") - parser.add_argument('-v', '--verbose', - action='store_true') + parser.add_argument('-v', '--verbose', action='store_true') + parser.add_argument('-n', '--no-delete', action='store_true', help="Do not delete existing blocks") args = parser.parse_args() if args.verbose: logging.basicConfig(level=logging.DEBUG) @@ -95,7 +95,7 @@ def cli(): Instance.show_diffs(local_blocklist, remote_blocklist) elif args.action == "deploy": diffs = Instance.list_diffs(local_blocklist, remote_blocklist) - Instance.apply_blocks_from_diff(diffs, args.server, args.token) + Instance.apply_blocks_from_diff(diffs, args.server, args.token, args.no_delete) elif args.action == "export": export_blocklist_toml(remote_blocklist, args.output) diff --git a/models.py b/models.py index ee0ef31..c481517 100644 --- a/models.py +++ b/models.py @@ -107,9 +107,9 @@ class Instance: return diffs @staticmethod - def apply_blocks_from_diff(diffs, server, token): + def apply_blocks_from_diff(diffs, server, token, no_delete: bool): for diff in diffs: - if diff["local"] is None: + if diff["local"] is None and not no_delete: """Delete the block on the remote server""" diff['remote'].delete(server, token) logging.info(f"Deleted {diff['remote'].domain} from blocklist")