Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions PCbuild/get_external.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python3

import argparse
import functools
import os
import pathlib
import platform
import subprocess
import sys
import tarfile
import time
Expand All @@ -12,6 +14,27 @@
import zipfile


@functools.cache
def trigger_automatic_root_certificate_update(url: str, timeout: int = 30) -> None:
escaped_url = url.replace("'", "''")
try:
subprocess.run(
[
"powershell",
"-NoProfile",
"-Command",
f"Invoke-WebRequest -Uri '{escaped_url}'"
f" -UseBasicParsing -Method HEAD -MaximumRedirection 0"
f" -TimeoutSec {timeout}",
],
check=True,
capture_output=True,
timeout=timeout + 5,
)
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
print(e)


def retrieve_with_retries(download_location, output_path, reporthook,
max_retries=7):
"""Download a file with exponential backoff retry and save to disk."""
Expand All @@ -25,6 +48,7 @@ def retrieve_with_retries(download_location, output_path, reporthook,
except (urllib.error.URLError, ConnectionError) as ex:
if attempt == max_retries:
raise OSError(f'Download from {download_location} failed.') from ex
trigger_automatic_root_certificate_update(download_location)
time.sleep(2.25**attempt)
else:
return resp
Expand Down
Loading