|
6 | 6 | import subprocess |
7 | 7 | import sys |
8 | 8 | import tarfile |
| 9 | +from urllib.error import HTTPError, URLError |
| 10 | +import time |
9 | 11 | import urllib.request |
10 | 12 | from pathlib import Path |
11 | 13 | from typing import cast |
|
16 | 18 | from setuptools.command.install import install |
17 | 19 |
|
18 | 20 | CNS_BINARIES = { |
19 | | - "x86_64-linux": "https://surfdrive.surf.nl/files/index.php/s/BWa5OimzbNliTi6/download", |
20 | | - "x86_64-darwin": "https://surfdrive.surf.nl/files/index.php/s/3Fzzte0Zx0L8GTY/download", |
21 | | - "arm64-darwin": "https://surfdrive.surf.nl/files/index.php/s/bYB3xPWf7iwo07X/download", |
22 | | - "aarch64-linux": "https://surfdrive.surf.nl/files/index.php/s/3rHpxcufHGrntHn/download", |
| 21 | + "x86_64-linux": "https://surfdrive.surf.nl/public.php/dav/files/BWa5OimzbNliTi6", |
| 22 | + "x86_64-darwin": "https://surfdrive.surf.nl/public.php/dav/files/3Fzzte0Zx0L8GTY", |
| 23 | + "arm64-darwin": "https://surfdrive.surf.nl/public.php/dav/files/bYB3xPWf7iwo07X", |
| 24 | + "aarch64-linux": "https://surfdrive.surf.nl/public.php/dav/files/3rHpxcufHGrntHn", |
23 | 25 | } |
24 | 26 |
|
25 | 27 | HADDOCK_RESTRAINTS_VERSION = "0.10.0" |
@@ -163,13 +165,26 @@ def download_binaries(self): |
163 | 165 | os.chmod(executable, 0o755) |
164 | 166 |
|
165 | 167 | @staticmethod |
166 | | - def download_file(url, dest) -> tuple[bool, str]: |
| 168 | + def download_file(url, dest, max_retries=3, delay=2) -> tuple[bool, str]: |
167 | 169 | """Download a file from a URL""" |
168 | | - try: |
169 | | - urllib.request.urlretrieve(url, dest) |
170 | | - return True, "Download successful" |
171 | | - except Exception as e: # pylint: disable=broad-except |
172 | | - return False, f"Download failed: {e}" |
| 170 | + for attempt in range(max_retries): |
| 171 | + try: |
| 172 | + urllib.request.urlretrieve(url, dest) |
| 173 | + return True, "Download successful" |
| 174 | + except (URLError, HTTPError) as e: # pylint: disable=broad-except |
| 175 | + if attempt < max_retries - 1: |
| 176 | + time.sleep(delay) |
| 177 | + continue |
| 178 | + return ( |
| 179 | + False, |
| 180 | + f"Download of {dest} failed after {max_retries} attempts: {e} URL: {url}", |
| 181 | + ) |
| 182 | + except Exception as e: # pylint: disable=broad-except |
| 183 | + return False, f"Download of {dest} failed: {e} URL: {url}" |
| 184 | + return ( |
| 185 | + False, |
| 186 | + f"Download of {dest} failed after {max_retries} attempts URL: {url}", |
| 187 | + ) |
173 | 188 |
|
174 | 189 | @staticmethod |
175 | 190 | def get_arch(): |
|
0 commit comments