def _mirror_roots(): mirrors = spack.config.get('mirrors') return [ sup.substitute_path_variables(root) if root.endswith(os.sep) else sup.substitute_path_variables(root) + os.sep for root in mirrors.values() ]
def fetch(self, mirror_only=False): """Downloads an archive or checks out code from a repository.""" fetchers = [] if not mirror_only: fetchers.append(self.default_fetcher) # TODO: move mirror logic out of here and clean it up! # TODO: Or @alalazo may have some ideas about how to use a # TODO: CompositeFetchStrategy here. self.skip_checksum_for_mirror = True if self.mirror_path: mirrors = spack.config.get('mirrors') # Join URLs of mirror roots with mirror paths. Because # urljoin() will strip everything past the final '/' in # the root, so we add a '/' if it is not present. mir_roots = [ sup.substitute_path_variables(root) if root.endswith(os.sep) else sup.substitute_path_variables(root) + os.sep for root in mirrors.values() ] urls = [urljoin(root, self.mirror_path) for root in mir_roots] # If this archive is normally fetched from a tarball URL, # then use the same digest. `spack mirror` ensures that # the checksum will be the same. digest = None expand = True extension = None if isinstance(self.default_fetcher, fs.URLFetchStrategy): digest = self.default_fetcher.digest expand = self.default_fetcher.expand_archive extension = self.default_fetcher.extension # Have to skip the checksum for things archived from # repositories. How can this be made safer? self.skip_checksum_for_mirror = not bool(digest) # Add URL strategies for all the mirrors with the digest for url in urls: fetchers.insert( 0, fs.URLFetchStrategy(url, digest, expand=expand, extension=extension)) if self.default_fetcher.cachable: fetchers.insert( 0, spack.caches.fetch_cache.fetcher(self.mirror_path, digest, expand=expand, extension=extension)) def generate_fetchers(): for fetcher in fetchers: yield fetcher # The search function may be expensive, so wait until now to # call it so the user can stop if a prior fetcher succeeded if self.search_fn and not mirror_only: dynamic_fetchers = self.search_fn() for fetcher in dynamic_fetchers: yield fetcher for fetcher in generate_fetchers(): try: fetcher.set_stage(self) self.fetcher = fetcher self.fetcher.fetch() break except spack.fetch_strategy.NoCacheError: # Don't bother reporting when something is not cached. continue except spack.error.SpackError as e: tty.msg("Fetching from %s failed." % fetcher) tty.debug(e) continue else: err_msg = "All fetchers failed for %s" % self.name self.fetcher = self.default_fetcher raise fs.FetchError(err_msg, None)