mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-30 18:03:07 +03:00
Attempt download from pillow-depends mirror first
This commit is contained in:
parent
c556c5f241
commit
c50b11b3ca
|
@ -421,25 +421,41 @@ def find_msvs():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def extract_dep(url, filename):
|
def download_dep(url: str, file: str) -> None:
|
||||||
import tarfile
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
|
ex = None
|
||||||
|
for i in range(3):
|
||||||
|
try:
|
||||||
|
print(f"Fetching {url} (attempt {i + 1})...")
|
||||||
|
content = urllib.request.urlopen(url).read()
|
||||||
|
with open(file, "wb") as f:
|
||||||
|
f.write(content)
|
||||||
|
break
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
ex = e
|
||||||
|
|
||||||
|
if ex:
|
||||||
|
raise RuntimeError(ex)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_dep(url: str, filename: str) -> None:
|
||||||
|
import tarfile
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
file = os.path.join(args.depends_dir, filename)
|
file = os.path.join(args.depends_dir, filename)
|
||||||
if not os.path.exists(file):
|
if not os.path.exists(file):
|
||||||
ex = None
|
# First try our mirror
|
||||||
for i in range(3):
|
mirror_url = (
|
||||||
try:
|
f"https://raw.githubusercontent.com/"
|
||||||
print("Fetching %s (attempt %d)..." % (url, i + 1))
|
f"python-pillow/pillow-depends/main/{filename}"
|
||||||
content = urllib.request.urlopen(url).read()
|
)
|
||||||
with open(file, "wb") as f:
|
try:
|
||||||
f.write(content)
|
download_dep(mirror_url, file)
|
||||||
break
|
except RuntimeError as exc:
|
||||||
except urllib.error.URLError as e:
|
# Otherwise try upstream
|
||||||
ex = e
|
print(exc)
|
||||||
else:
|
download_dep(url, file)
|
||||||
raise RuntimeError(ex)
|
|
||||||
|
|
||||||
print("Extracting " + filename)
|
print("Extracting " + filename)
|
||||||
sources_dir_abs = os.path.abspath(sources_dir)
|
sources_dir_abs = os.path.abspath(sources_dir)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user