From: Michael Tremer Date: Mon, 22 Dec 2025 10:20:11 +0000 (+0000) Subject: dnsbl: Implement forcing a list update X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1db5f521c81d4e1548cd4ea170ba94fb0f9b8126;p=dbl.git dnsbl: Implement forcing a list update Signed-off-by: Michael Tremer --- diff --git a/src/dnsbl/lists.py b/src/dnsbl/lists.py index 24001da..595aa67 100644 --- a/src/dnsbl/lists.py +++ b/src/dnsbl/lists.py @@ -260,7 +260,7 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): # Update! - def update(self): + def update(self, **kwargs): """ Updates the list """ @@ -269,7 +269,7 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True): # Update all sources for source in self.sources: - if source.update(): + if source.update(**kwargs): updated = True # Update the timestamp if at least one source has actually fetched new data diff --git a/src/dnsbl/sources.py b/src/dnsbl/sources.py index 7edef26..77f5102 100644 --- a/src/dnsbl/sources.py +++ b/src/dnsbl/sources.py @@ -158,7 +158,7 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): # Log action log.info(_("Source '%s' has been deleted from '%s'") % (self, self.list)) - def update(self): + def update(self, force=False): """ Updates this source. """ @@ -173,7 +173,7 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): with self.db.transaction(): with self.backend.client() as client: # Compose some request headers - headers = self._make_headers() + headers = self._make_headers(force=force) with client.stream("GET", self.url, headers=headers) as response: # Parse the response headers @@ -242,20 +242,21 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True): # Signal that we have actually fetched new data return True - def _make_headers(self): + def _make_headers(self, force=False): """ Creates some headers we will send with the request. """ headers = {} - # Send If-Modified-Since so that we won't re-import the same list - if self.last_modified_at: - headers["If-Modified-Since"] = \ - self.last_modified_at.strftime("%a, %d %b %Y %H:%M:%S GMT") + if not force: + # Send If-Modified-Since so that we won't re-import the same list + if self.last_modified_at: + headers["If-Modified-Since"] = \ + self.last_modified_at.strftime("%a, %d %b %Y %H:%M:%S GMT") - # If we don't have the timestamp, we will send the ETag - elif self.etag: - headers["If-None-Match"] = self.etag + # If we don't have the timestamp, we will send the ETag + elif self.etag: + headers["If-None-Match"] = self.etag return headers diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index e7ca4c6..bcd4596 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -93,6 +93,7 @@ class CLI(object): # update update = subparsers.add_parser("update", help=_("Updates a list")) update.add_argument("list", help=_("The name of the list")) + update.add_argument("--force", action="store_true", help=_("Force an update")) update.set_defaults(func=self.__update) # update-all @@ -279,7 +280,7 @@ class CLI(object): list = backend.lists.get_by_slug(args.list) # Update! - list.update() + list.update(force=args.force) def __update_all(self, backend, args): """