Skip to content
Snippets Groups Projects
Commit 1e15988a authored by Guido Gunther's avatar Guido Gunther :zzz:
Browse files

flash-image: Get size from meta data

This makes sure the progress bar matches the expected image size.

We don't make the lack of meta data fatal yet so we can use this
script on outdated build jobs too for some time.
parent 7a927b97
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import subprocess
import sys
import tempfile
import tqdm
import yaml
try:
import coloredlogs
......@@ -26,6 +27,7 @@ JENKINS = 'https://arm01.puri.sm'
TYPE = 'devkit'
DIST = 'buster+ci'
IMAGE = 'devkit.img'
META_YAML = 'files/meta.yml'
IMAGE_JOB_NAME = 'Images/Image Build'
UBOOT = 'u-boot-devkit-recovery.imx'
UBOOT_JOB_NAME = 'u-boot_builds/devkit-recovery_uboot_build'
......@@ -47,20 +49,34 @@ FB: flash -raw2sparse all {image}
FB: Done
'''
BLOCK_SIZE = 8192
# TODO store in image metadata
UNCOMPRESSED_SIZE = 3600000000
def download_image(url, target):
decomp = lzma.LZMADecompressor()
logging.info("Downloading image from {}".format(url))
# We expect metadata to be right next to the image
meta_yml_url = "{}/{}".format(url.rsplit('/', 1)[0], META_YAML)
resp = requests.get(meta_yml_url)
# No meta data is no yet fatal
try:
resp.raise_for_status()
meta = yaml.safe_load(resp.text)
uncompressed_size = int(meta['image']['size'])
logging.debug("Image size is %d", uncompressed_size)
except requests.exceptions.HTTPError:
logging.warning("No meta data found, size may be incorrect")
meta = None
uncompressed_size = UNCOMPRESSED_SIZE
resp = requests.get(url, stream=True)
resp.raise_for_status()
ts = int(resp.headers.get('content-length', 0))
download_bar = tqdm.tqdm(total=ts,
desc='Download',
leave=False)
decompress_bar = tqdm.tqdm(total=UNCOMPRESSED_SIZE,
decompress_bar = tqdm.tqdm(total=uncompressed_size,
desc='Decompr.',
leave=False)
with open(target, 'wb+') as f:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment