# Create a tar file
with tarfile.open(fileobj=f, mode="w|gz") as tarball:
# Write the list
- self._write_list(tarball, self.list)
+ self._write_list(tarball)
- def _write_list(self, tarball, list):
+ def _write_list(self, tarball):
# Create a new
- file = tarfile.TarInfo(name="%s/domains" % list.slug)
+ file = tarfile.TarInfo(name="%s/domains" % self.list.slug)
# Write the payload to memory
f = io.BytesIO()
# Create a domain exporter
- exporter = DomainsExporter(self.backend, list)
+ exporter = DomainsExporter(self.backend, self.list)
# Write all domains to the buffer
exporter(f)
file.size = f.tell()
# Set the mtime
- if self.list.updated_at:
- file.mtime = self.list.updated_at.timestamp()
+ file.mtime = self.list.updated_at.timestamp()
# Reset the buffer
f.seek(0)
# Write the buffer to the tarball
tarball.addfile(file, fileobj=f)
+
+
+class CombinedSquidGuardExporter(object):
+ """
+ This is a special exporter which combines all lists into a single tarball
+ """
+ def __init__(self, backend, lists):
+ self.backend = backend
+ self.lists = lists
+
+ def __call__(self, f):
+ # Create a tar file
+ with tarfile.open(fileobj=f, mode="w|gz") as tarball:
+ for list in self.lists:
+ exporter = SquidGuardExporter(self.backend, list)
+ exporter._write_list(tarball)
import argparse
import dnsbl
+import dnsbl.exporters
import logging
import os
import pathlib
# Once the output has been written in full, we will rename the file
os.link(f.name, name)
+ # Write all lists as one tarball for squidGuard
+ exporter = dnsbl.exporters.CombinedSquidGuardExporter(backend, backend.lists)
+ with open(root / "squidguard.tar.gz", "wb") as f:
+ exporter(f)
+
def __add_source(self, backend, args):
"""
Adds a new source to a list