From: Michael Tremer Date: Sun, 11 Dec 2016 22:13:19 +0000 (+0100) Subject: http: Add option for client code to skip mirrors X-Git-Tag: 0.9.28~1285^2~1370 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fded166b6c8aebffd0196afc4a099ead4866c52b;p=pakfire.git http: Add option for client code to skip mirrors In case any higher-level code is not satisfied with a download (checksum doesn't match, data too old), it can decide to skip the current mirror and the next best one is chosen. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/http.py b/src/pakfire/http.py index ec9aa3d7a..5dace8e92 100644 --- a/src/pakfire/http.py +++ b/src/pakfire/http.py @@ -131,6 +131,25 @@ class Client(object): except IndexError as e: raise DownloadError(_("No more mirrors to try")) from e + def skip_current_mirror(self): + """ + Called from a user of this class when a download + was not acceptable (e.g. invalid checksum or too old + metadata). + + It will drop the current mirror. + + If no mirrors are left, or no mirrors are available, + it will raise DownloadError. + """ + if not self.mirrors: + raise DownloadError(_("No more mirrors to try")) + + log.warning(_("Skipping mirror %s") % self.mirror) + + self.mirrors.remove(self.mirror) + self._next_mirror() + def _make_request(self, url, method="GET", data=None, auth=None, baseurl=None, mirror=None): # If a mirror is given, we use it as baseurl if mirror: