From 8fe1c6ddcca215458a021239e873df334f7d53a0 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 29 Feb 2020 20:21:02 +0300 Subject: boost/build: try multiple mirrors --- boost/build/build.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'boost') diff --git a/boost/build/build.py b/boost/build/build.py index c4b008c..0450593 100755 --- a/boost/build/build.py +++ b/boost/build/build.py @@ -205,11 +205,19 @@ class BoostVersion: def archive_name(self): return f'{self.dir_name}{self.archive_ext}' - def get_download_url(self): - if self._impl < _Version(1, 63, 0): - return f'https://sourceforge.net/projects/boost/files/boost/{self}/{self.archive_name}/download' + def _get_bintray_url(self): return f'https://dl.bintray.com/boostorg/release/{self}/source/{self.archive_name}' + def _get_sourceforge_url(self): + return f'https://sourceforge.net/projects/boost/files/boost/{self}/{self.archive_name}/download' + + def get_download_urls(self): + if self._impl < _Version(1, 63, 0): + # For versions older than 1.63.0, SourceForge is the only option: + return [self._get_sourceforge_url()] + # Otherwise, Bintray is preferred (the official website links to it). + return [self._get_bintray_url(), self._get_sourceforge_url()] + class BoostArchive: def __init__(self, version, path): @@ -238,12 +246,20 @@ class ArchiveStorage(abc.ABC): yield BoostArchive(version, path) return - url = version.get_download_url() - logging.info('Download URL: %s', url) + urls = version.get_download_urls() - with urllib.request.urlopen(url) as request: - with self.write_archive(version, request.read()) as path: - yield BoostArchive(version, path) + for url in urls: + logging.info('Trying URL: %s', url) + try: + with urllib.request.urlopen(url) as request: + with self.write_archive(version, request.read()) as path: + yield BoostArchive(version, path) + return + except urllib.request.URLError as e: + logging.error("Couldn't download from this mirror, an error occured:") + logging.exception(e) + + raise RuntimeError("Couldn't download Boost from any of the mirrors") @abc.abstractmethod def get_archive(self, version): -- cgit v1.2.3