def resolve(self, resolve_context): from guild import pip_util # expensive if self.resource.config: return _resolve_config_path(self.resource.config, self.source.resdef.name) download_dir = url_source_download_dir(self.source) util.ensure_dir(download_dir) try: source_path = pip_util.download_url(self.source.uri, download_dir, self.source.sha256) except pip_util.HashMismatch as e: raise ResolutionError( "bad sha256 for '%s' (expected %s but got %s)" % (e.path, e.expected, e.actual)) except Exception as e: if log.getEffectiveLevel() <= logging.DEBUG: log.exception(self.source.uri) raise ResolutionError(e) else: unpack_dir = self._unpack_dir(source_path, resolve_context.unpack_dir) resolved = resolve_source_files(source_path, self.source, unpack_dir) post_process(self.source, unpack_dir or os.path.dirname(source_path)) return resolved
def resolve(self): download_dir = self._source_download_dir() util.ensure_dir(download_dir) try: return pip_util.download_url(self.source.uri, download_dir, self.source.sha256) except pip_util.HashMismatch as e: raise ResolutionError( "bad sha256 for '%s' (expected %s but got %s)" % (self.source.uri, e.expected, e.actual))
def main(args): resdef = resourcedef.ResourceDef("download", {}) source = resourcedef.ResourceSource(resdef, args.url) download_dir = resolver.url_source_download_dir(source) util.ensure_dir(download_dir) try: source_path = pip_util.download_url(source.uri, download_dir) except Exception as e: _handle_download_error(e, source) else: sha256 = util.file_sha256(source_path, use_cache=False) print("{} {}".format(sha256, source_path))
def obtain(self, dest): url, rev = self.get_url_rev(self.url) archive_url = "{}/archive/{}.zip".format(url, rev) util.ensure_dir(dest) downloaded_file = pip_util.download_url(archive_url, dest) zf = zipfile.ZipFile(downloaded_file) for name in zf.namelist(): dest_path = os.path.join(*([dest] + name.split("/")[1:])) if name.endswith("/"): util.ensure_dir(dest_path) else: with open(dest_path, "wb") as fdst: fsrc = zf.open(name) shutil.copyfileobj(fsrc, fdst)
def resolve(self, unpack_dir=None): from guild import pip_util # expensive and far reaching if self.resource.config: return _resolve_config_path(self.resource.config, self.source.resdef.name) download_dir = url_source_download_dir(self.source) util.ensure_dir(download_dir) try: source_path = pip_util.download_url(self.source.uri, download_dir, self.source.sha256) except pip_util.HashMismatch as e: raise ResolutionError( "bad sha256 for '%s' (expected %s but got %s)" % (e.path, e.expected, e.actual)) else: resolved = resolve_source_files(source_path, self.source, unpack_dir) post_process(self.source, unpack_dir or os.path.dirname(source_path)) return resolved