Add nodelete option

This commit is contained in:
moanos [he/him] 2023-01-11 20:21:01 +01:00
parent de5b454ed6
commit 4ddac75d9a
2 changed files with 5 additions and 5 deletions

6
cli.py
View File

@ -68,8 +68,8 @@ def cli():
parser.add_argument('-i', '--input-file', help="The blocklist to use") 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('-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('-o', '--output', help="Filename where to export the blocklist")
parser.add_argument('-v', '--verbose', parser.add_argument('-v', '--verbose', action='store_true')
action='store_true') parser.add_argument('-n', '--no-delete', action='store_true', help="Do not delete existing blocks")
args = parser.parse_args() args = parser.parse_args()
if args.verbose: if args.verbose:
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
@ -95,7 +95,7 @@ def cli():
Instance.show_diffs(local_blocklist, remote_blocklist) Instance.show_diffs(local_blocklist, remote_blocklist)
elif args.action == "deploy": elif args.action == "deploy":
diffs = Instance.list_diffs(local_blocklist, remote_blocklist) 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": elif args.action == "export":
export_blocklist_toml(remote_blocklist, args.output) export_blocklist_toml(remote_blocklist, args.output)

View File

@ -107,9 +107,9 @@ class Instance:
return diffs return diffs
@staticmethod @staticmethod
def apply_blocks_from_diff(diffs, server, token): def apply_blocks_from_diff(diffs, server, token, no_delete: bool):
for diff in diffs: 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""" """Delete the block on the remote server"""
diff['remote'].delete(server, token) diff['remote'].delete(server, token)
logging.info(f"Deleted {diff['remote'].domain} from blocklist") logging.info(f"Deleted {diff['remote'].domain} from blocklist")