Skip to content

Commit

Permalink
Merge pull request #383 from ParaToolsInc/nchaimov-fix-release-mirrors
Browse files Browse the repository at this point in the history
Add mirror support to setup.py
  • Loading branch information
zbeekman authored Nov 3, 2020
2 parents e744966 + 2beca60 commit e14f62d
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,25 +341,38 @@ def _download(self, pkg):
try:
arch_dct = repos[self.target_arch]
except KeyError:
src = default
srcs = default
else:
src = arch_dct.get(self.target_os, arch_dct.get(None, default))
pkg = os.path.basename(src)
cache_dir = tempfile.gettempdir()
cache_db = os.path.join(cache_dir, 'taucmdr.setup_py.downloads')
cache_pkg = os.path.join(cache_dir, pkg)
try:
with open(cache_db, 'r') as fin:
cache = pickle.load(fin)
except IOError:
cache = {}
if not os.path.exists(cache_pkg) or src != cache.get(cache_pkg):
print "Downloading '{}' for ({}, {})".format(pkg, self.target_arch, self.target_os)
util.download(src, cache_pkg)
cache[cache_pkg] = src
with open(cache_db, 'w') as fout:
pickle.dump(cache, fout)
util.download(cache_pkg, os.path.join('system', 'src', pkg))
srcs = arch_dct.get(self.target_os, arch_dct.get(None, default))
if not isinstance(srcs, list):
srcs = [srcs]
success = False
while srcs and not success:
try:
src = srcs.pop(0)
pkg = os.path.basename(src)
cache_dir = tempfile.gettempdir()
cache_db = os.path.join(cache_dir, 'taucmdr.setup_py.downloads')
cache_pkg = os.path.join(cache_dir, pkg)
try:
with open(cache_db, 'r') as fin:
cache = pickle.load(fin)
except IOError:
cache = {}
if not os.path.exists(cache_pkg) or src != cache.get(cache_pkg):
print "Downloading '{}' for ({}, {})".format(pkg, self.target_arch, self.target_os)
util.download(src, cache_pkg)
cache[cache_pkg] = src
with open(cache_db, 'w') as fout:
pickle.dump(cache, fout)
util.download(cache_pkg, os.path.join('system', 'src', pkg))
success = True
except IOError:
print "Failed to download {} from URL {}; falling back to next mirror.".format(pkg, src)
pass
if not success:
raise IOError("Unable to download {} from any mirror.".format(pkg))


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

0 comments on commit e14f62d

Please sign in to comment.