Commit dd17f51f authored by Guido Gunther's avatar Guido Gunther
Browse files

librem5-devkit-image: Don't redownload image if it's recent

Closes: #14
parent c342b871
......@@ -128,9 +128,20 @@ def stream_file(url, attempts):
return resuming_stream(url, ts, attempts), ts
def needs_download(target, meta):
if not os.path.exists(target):
return True
verify_image(target, meta)
except VerifyImageException:
return True
return False
def download_image(url, target, attempts):
decomp = lzma.LZMADecompressor()"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)
......@@ -140,6 +151,11 @@ def download_image(url, target, attempts):
uncompressed_size = int(meta['image']['size'])
logging.debug("Image size is %d", uncompressed_size)
if not needs_download(target, meta):"Image already up to date - no download needed.")
return"Downloading image from {}".format(url))
stream, ts = stream_file(url, attempts)
download_bar = tqdm.tqdm(total=ts,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment