def insert_git_requirement(index, name, url): repo_data = prefetch_git(url) index[name] = index.GitEntry( url=repo_data["url"], rev=repo_data["rev"], sha256=repo_data["sha256"], )
def update_package_from_master(self, package_name: str) -> None: url = self._get_url_for_package(package_name) if url is None: self._log_no_update_warning(package_name) return repo_data = prefetch_git(url) self.index[package_name] = Index.GitEntry( url=repo_data["url"], rev=repo_data["rev"], sha256=repo_data["sha256"], ) self._log_update_success(package_name)
def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL, chunk_size=2048): """ """ if wheel['name'] in sources: release = dict() release['url'] = sources[wheel['name']]['url'] release['hash_type'] = 'sha256' repo_type = sources[wheel['name']]['type'] if repo_type == 'url': release['fetch_type'] = 'fetchurl' r = requests.get(release['url'], stream=True, timeout=None) r.raise_for_status() # TODO: handle this nicer with tempfile.TemporaryFile() as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) fd.seek(0) hash = hashlib.sha256(fd.read()) release['hash_value'] = hash.hexdigest() elif repo_type == 'git': revision = '' if release['url'].startswith('git+'): release['url'] = release['url'][4:] if '@' in release['url']: release['url'], revision = release['url'].split('@') release['fetch_type'] = 'fetchgit' repo_data = prefetch_git(release['url'], revision) release['hash_value'] = repo_data['sha256'] release['rev'] = repo_data['rev'] elif repo_type == 'hg': revision = '' if release['url'].startswith('hg+'): release['url'] = release['url'][3:] if '@' in release['url']: release['url'], revision = release['url'].split('@') release['fetch_type'] = 'fetchhg' command = 'nix-prefetch-hg {url} {revision}'.format( url=release['url'], revision=revision, ) return_code, output = cmd(command, verbose != 0) if return_code != 0: raise click.ClickException("URL {url} for package {name} is not valid.".format( url=release['url'], name=wheel['name'] )) HASH_PREFIX = 'hash is ' REV_PREFIX = 'hg revision is ' for output_line in output.split('\n'): print(output_line) output_line = output_line.strip() if output_line.startswith(HASH_PREFIX): release['hash_value'] = output_line[len(HASH_PREFIX):].strip() elif output_line.startswith(REV_PREFIX): release['rev'] = output_line[len(REV_PREFIX):].strip() if release.get('hash_value', None) is None: raise click.ClickException('Could not determine the hash from ouput:\n{output}'.format( output=output )) if release.get('rev', None) is None: raise click.ClickException('Could not determine the revision from ouput:\n{output}'.format( output=output )) elif repo_type == 'path': release['fetch_type'] = 'path' else: raise click.ClickException('Source type `{}` not implemented'.format(repo_type)) else: url = "{}/{}/json".format(index, wheel['name']) r = requests.get(url, timeout=None) r.raise_for_status() # TODO: handle this nicer wheel_data = r.json() if not wheel_data.get('releases'): raise click.ClickException( "Unable to find releases for packge {name}".format(**wheel)) release = find_release(wheel_cache_dir, wheel, wheel_data) wheel.update(release) return wheel
def _prefetch_data(self) -> Dict[str, str]: return prefetch_git(self.repository_url, self._logger, self._revision_name)
def prefetch_data(self) -> Dict[str, str]: if self._prefetch_data is None: self._prefetch_data = prefetch_git(self.url, self._revision) return self._prefetch_data
def process_wheel(wheel_cache_dir, wheel, sources, verbose, index=INDEX_URL, chunk_size=2048): """ """ if wheel["name"] in sources: release = dict() release["url"] = sources[wheel["name"]]["url"] release["hash_type"] = "sha256" repo_type = sources[wheel["name"]]["type"] if repo_type == "url": release["fetch_type"] = "fetchurl" r = requests.get(release["url"], stream=True, timeout=None) r.raise_for_status() # TODO: handle this nicer with tempfile.TemporaryFile() as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) fd.seek(0) hash = hashlib.sha256(fd.read()) release["hash_value"] = hash.hexdigest() elif repo_type == "git": revision = "" if release["url"].startswith("git+"): release["url"] = release["url"][4:] if "@" in release["url"]: release["url"], revision = release["url"].split("@") release["fetch_type"] = "fetchgit" repo_data = prefetch_git(release["url"], revision) release["hash_value"] = repo_data["sha256"] release["rev"] = repo_data["rev"] elif repo_type == "hg": revision = "" if release["url"].startswith("hg+"): release["url"] = release["url"][3:] if "@" in release["url"]: release["url"], revision = release["url"].split("@") release["fetch_type"] = "fetchhg" command = "nix-prefetch-hg {url} {revision}".format( url=release["url"], revision=revision) return_code, output = cmd(command, verbose != 0) if return_code != 0: raise click.ClickException( "URL {url} for package {name} is not valid.".format( url=release["url"], name=wheel["name"])) HASH_PREFIX = "hash is " REV_PREFIX = "hg revision is " for output_line in output.split("\n"): print(output_line) output_line = output_line.strip() if output_line.startswith(HASH_PREFIX): release["hash_value"] = output_line[len(HASH_PREFIX ):].strip() elif output_line.startswith(REV_PREFIX): release["rev"] = output_line[len(REV_PREFIX):].strip() if release.get("hash_value", None) is None: raise click.ClickException( "Could not determine the hash from ouput:\n{output}". format(output=output)) if release.get("rev", None) is None: raise click.ClickException( "Could not determine the revision from ouput:\n{output}". format(output=output)) elif repo_type == "path": release["fetch_type"] = "path" else: raise click.ClickException( "Source type `{}` not implemented".format(repo_type)) else: url = "{}/{}/json".format(index, wheel["name"]) r = requests.get(url, timeout=None) r.raise_for_status() # TODO: handle this nicer wheel_data = r.json() if not wheel_data.get("releases"): raise click.ClickException( "Unable to find releases for packge {name}".format(**wheel)) release = find_release(wheel_cache_dir, wheel, wheel_data) wheel.update(release) return wheel