From bb16cf08d6c76783e200d5f8e0c0607bbefafe71 Mon Sep 17 00:00:00 2001 From: "Alex Xu (Hello71)" Date: Sat, 15 Aug 2020 13:43:06 -0400 Subject: tools/adoptopenjdk-manifest: fetch adoptopenjdk sums --- tools/adoptopenjdk-manifest | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/adoptopenjdk-manifest (limited to 'tools/adoptopenjdk-manifest') diff --git a/tools/adoptopenjdk-manifest b/tools/adoptopenjdk-manifest new file mode 100755 index 0000000..1789fdf --- /dev/null +++ b/tools/adoptopenjdk-manifest @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +from collections import ChainMap +from pathlib import Path +import os +import re + +import asyncio +import httpx +import portage + +async def do_manifest(client, filename, size, url): + resp = await client.get(f'{url}.sha256.txt') + sha256 = resp.text.split(' ')[0] + return (filename, size, sha256) + +async def do_api(client, ghauth, tagl): + owner, repo, tag = tagl + apiurl = f'https://api.github.com/repos/{owner}/{repo}/releases/tags/{tag}' + resp = await client.get(apiurl, auth=ghauth) + return {asset['browser_download_url']: asset['size'] + for asset in resp.json()['assets']} + +async def handle(fm): + tags = set() + res = r'^https://github.com/([^/]*)/([^/]*)/releases/download/([^/]*)/([^/]*)$' + rec = re.compile(res) + for _, urls in fm.items(): + m = re.match(rec, urls[0]) + if m: + tags.add(m.group(1, 2, 3)) + + headers = {'User-Agent': 'gentoo-adoptopenjdk-manifest'} + async with httpx.AsyncClient(headers=headers) as client: + if 'GITHUB_USER' in os.environ and 'GITHUB_PASS' in os.environ: + ghauth = (os.environ['GITHUB_USER'], os.environ['GITHUB_PASS']) + else: + ghauth = None + + apijobs = (do_api(client, ghauth, tagl) for tagl in tags) + assetsizes = ChainMap(*await asyncio.gather(*apijobs)) + + manifestjobs = (do_manifest(client, filename, assetsizes[urls[0]], urls[0]) + for filename, urls in fm.items()) + return sorted(await asyncio.gather(*manifestjobs)) + +def main(pkgdir): + p = portage.db['/']['porttree'].dbapi + pkgdir = Path(pkgdir).resolve() + mytree = str(pkgdir.parents[1]) + cp = str(pkgdir.relative_to(pkgdir.parents[1])) + cpvs = p.cp_list(cp, mytree=mytree) + fms = (p.getFetchMap(cpv, mytree=mytree) for cpv in cpvs) + for filename, size, sha256 in asyncio.run(handle(ChainMap(*fms))): + print(f'DIST {filename} {size} SHA256 {sha256}') + +if __name__ == '__main__': + main('.') -- cgit v1.2.3-70-g09d2