From: Michael Tremer Date: Sat, 6 Dec 2025 20:57:31 +0000 (+0000) Subject: dnsbl: Create a sub-directory for each exported list X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2e537e42ae442d489be576a325484341f255be1;p=dnsbl.git dnsbl: Create a sub-directory for each exported list Signed-off-by: Michael Tremer --- diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 3af9885..e219f77 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -23,6 +23,7 @@ import argparse import dnsbl import logging import os +import pathlib import rich.console import rich.table import sys @@ -286,8 +287,8 @@ class CLI(object): Exports all lists """ formats = { - "domains" : "%s.txt", - "rpz" : "%s.rpz", + "domains" : "domains.txt", + "rpz" : "rpz.zone", } # Ensure the output directory exists @@ -296,14 +297,26 @@ class CLI(object): except FileExistsError: pass + # Open the root + root = pathlib.Path(args.directory) + # Export all lists for list in backend.lists: for format, filename in formats.items(): + # Compose the directory for the list + dir = root / list.slug + # Compose the output filename - name = os.path.join(args.directory, filename % list.slug) + name = dir / filename + + # Create a directory for the list + try: + dir.mkdir() + except FileExistsError: + pass # Create a new temporary file - with tempfile.NamedTemporaryFile(dir=args.directory) as f: + with tempfile.NamedTemporaryFile(dir=dir) as f: list.export(f, format=format) # Remove the previous file (if it exists)