import dnsbl
import logging
import os
+import pathlib
import rich.console
import rich.table
import sys
Exports all lists
"""
formats = {
- "domains" : "%s.txt",
- "rpz" : "%s.rpz",
+ "domains" : "domains.txt",
+ "rpz" : "rpz.zone",
}
# Ensure the output directory exists
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)