From afe1dbf9cfbdd529d449efeaad08fe6c8dbbcd6f Mon Sep 17 00:00:00 2001
From: nrb <freifunk@nicoboehr.de>
Date: Wed, 30 Dec 2020 17:17:32 +0100
Subject: [PATCH] use WGET for downloading

WGET can retry automatically, so use it.
---
 download-latest-firmware-build.py | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/download-latest-firmware-build.py b/download-latest-firmware-build.py
index be27efa..8874ee2 100755
--- a/download-latest-firmware-build.py
+++ b/download-latest-firmware-build.py
@@ -84,11 +84,12 @@ pipeline_jobs_request.raise_for_status()
 pipeline_jobs = pipeline_jobs_request.json()
 for job in pipeline_jobs:
     if job["name"] == "package":
-        with tempfile.TemporaryFile() as artifact_temp:
-            with requests.get("{}/projects/{}/jobs/{}/artifacts".format(GITLAB_API_BASE, PROJECT_ID, job["id"]), stream=True) as artifact_request:
-                artifact_request.raise_for_status()
-                for chunk in artifact_request.iter_content(chunk_size=1024*1024):
-                    artifact_temp.write(chunk)
+        with tempfile.NamedTemporaryFile() as artifact_temp:
+            artifact_url = "{}/projects/{}/jobs/{}/artifacts".format(GITLAB_API_BASE, PROJECT_ID, job["id"])
+            logging.debug("Starting download via wget of URL '{}'".format(artifact_url))
+            wget_process = subprocess.run(["wget", "-O" + artifact_temp.name, artifact_url], encoding='utf-8')
+            if wget_process.returncode != 0:
+                print(wget_process.stdout)
 
             downloaded_version = extract_zip(artifact_temp)
 
-- 
GitLab