Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ the manual commands above to ship in your Flatpak repository, so you can run:
$ flatpak run --command=bash --share=network --filesystem=`pwd` -d org.freedesktop.Sdk//21.08 ./script.sh
$ flatpak-gradle-generator.py gradle-log.txt gradle-dependencies.json
```

If necessary, you can modify the level of output from the script by setting the
`LOGLEVEL` environment variable to a [supported log level](https://docs.python.org/3/library/logging.html#logging-levels):
```
$ LOGLEVEL=debug flatpak-gradle-generator.py gradle-log.txt gradle-dependencies.json
```
27 changes: 16 additions & 11 deletions gradle/flatpak-gradle-generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import hashlib
import logging
import re
import os

arches = {
'linux-x86_64': 'x86_64',
Expand All @@ -16,23 +17,22 @@
'linux-aarch_32': 'arm'
}

async def get_remote_sha256(url):
async def get_remote_sha256(http_session, url):
logging.info(f"started sha256({url})")
sha256 = hashlib.sha256()
async with aiohttp.ClientSession(raise_for_status=True) as http_session:
async with http_session.get(url) as response:
while True:
data = await response.content.read(4096)
if not data:
break
sha256.update(data)
async with http_session.get(url) as response:
while True:
data = await response.content.read(4096)
if not data:
break
sha256.update(data)
logging.info(f"done sha256({url})")
return sha256.hexdigest()

async def parse_url(url, destdir, arch=None):
async def parse_url(http_session, url, destdir, arch=None):
ret = [{ 'type': 'file',
'url': url,
'sha256': await get_remote_sha256(url),
'sha256': await get_remote_sha256(http_session, url),
'dest': destdir, }]
if arch:
ret[0]['only-arches'] = [arch]
Expand All @@ -49,10 +49,12 @@ def arch_for_url(url, urls_arch):
async def parse_urls(urls, urls_arch, destdir):
sources = []
sha_coros = []
http_session = aiohttp.ClientSession()
for url in urls:
arch = arch_for_url(url, urls_arch)
sha_coros.append(parse_url(str(url), destdir, arch))
sha_coros.append(parse_url(http_session, str(url), destdir, arch))
sources.extend(sum(await asyncio.gather(*sha_coros), []))
await http_session.close()
return sources

def gradle_arch_to_flatpak_arch(arch):
Expand All @@ -63,6 +65,9 @@ def flatpak_arch_to_gradle_arch(arch):
return rev_arches[arch]

def main():
logging.basicConfig(
level=os.environ.get('LOGLEVEL', 'WARNING').upper()
)
parser = argparse.ArgumentParser()
parser.add_argument('input', help='The gradle log file')
parser.add_argument('output', help='The output JSON sources file')
Expand Down