Skip to content

Commit 2beca60

Browse files
committed
Add mirror support to setup.py
setup.py has its own download functionality, separate from that used in installation.py. It had not been updated to support lists of mirrors instead of a single string for a source URL. This commit updates it to support lists of mirrors.
1 parent e744966 commit 2beca60

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

setup.py

+31-18
Original file line numberDiff line numberDiff line change
@@ -341,25 +341,38 @@ def _download(self, pkg):
341341
try:
342342
arch_dct = repos[self.target_arch]
343343
except KeyError:
344-
src = default
344+
srcs = default
345345
else:
346-
src = arch_dct.get(self.target_os, arch_dct.get(None, default))
347-
pkg = os.path.basename(src)
348-
cache_dir = tempfile.gettempdir()
349-
cache_db = os.path.join(cache_dir, 'taucmdr.setup_py.downloads')
350-
cache_pkg = os.path.join(cache_dir, pkg)
351-
try:
352-
with open(cache_db, 'r') as fin:
353-
cache = pickle.load(fin)
354-
except IOError:
355-
cache = {}
356-
if not os.path.exists(cache_pkg) or src != cache.get(cache_pkg):
357-
print "Downloading '{}' for ({}, {})".format(pkg, self.target_arch, self.target_os)
358-
util.download(src, cache_pkg)
359-
cache[cache_pkg] = src
360-
with open(cache_db, 'w') as fout:
361-
pickle.dump(cache, fout)
362-
util.download(cache_pkg, os.path.join('system', 'src', pkg))
346+
srcs = arch_dct.get(self.target_os, arch_dct.get(None, default))
347+
if not isinstance(srcs, list):
348+
srcs = [srcs]
349+
success = False
350+
while srcs and not success:
351+
try:
352+
src = srcs.pop(0)
353+
pkg = os.path.basename(src)
354+
cache_dir = tempfile.gettempdir()
355+
cache_db = os.path.join(cache_dir, 'taucmdr.setup_py.downloads')
356+
cache_pkg = os.path.join(cache_dir, pkg)
357+
try:
358+
with open(cache_db, 'r') as fin:
359+
cache = pickle.load(fin)
360+
except IOError:
361+
cache = {}
362+
if not os.path.exists(cache_pkg) or src != cache.get(cache_pkg):
363+
print "Downloading '{}' for ({}, {})".format(pkg, self.target_arch, self.target_os)
364+
util.download(src, cache_pkg)
365+
cache[cache_pkg] = src
366+
with open(cache_db, 'w') as fout:
367+
pickle.dump(cache, fout)
368+
util.download(cache_pkg, os.path.join('system', 'src', pkg))
369+
success = True
370+
except IOError:
371+
print "Failed to download {} from URL {}; falling back to next mirror.".format(pkg, src)
372+
pass
373+
if not success:
374+
raise IOError("Unable to download {} from any mirror.".format(pkg))
375+
363376

364377
def _download_python(self):
365378
from taucmdr.cf.platforms import X86_64, INTEL_KNC, INTEL_KNL, IBM64, PPC64LE, ARM64, DARWIN, LINUX

0 commit comments

Comments
 (0)