+ success = False
+ while repeat:
+ repeat -= 1
+ session = None
+ try:
+ logging.info(f" Connecting to {url} ...")
+ session = requests_retry_session()
+ response = session.get(url, stream=True, verify=verify)
+ code = response.status_code
+ logging.info(f" {code}: {responses[code]}")
+
+ if code != codes[u"OK"]:
+ if session:
+ session.close()
+ url = url.replace(u"_info", u"")
+ logging.info(f" Connecting to {url} ...")
+ session = requests_retry_session()
+ response = session.get(url, stream=True, verify=verify)
+ code = response.status_code
+ logging.info(f" {code}: {responses[code]}")
+ if code != codes[u"OK"]:
+ return False, file_name
+ file_name = file_name.replace(u"_info", u"")
+
+ dst_file_name = file_name.replace(u".gz", u"")
+ logging.info(f" Downloading the file {url} to {dst_file_name}")
+ with open(dst_file_name, u"wb") as file_handle:
+ for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
+ if chunk:
+ file_handle.write(chunk)
+
+ if arch and u".gz" in file_name:
+ if session:
+ session.close()
+ logging.info(f" Downloading the file {url} to {file_name}")
+ session = requests_retry_session()
+ response = session.get(url, stream=True, verify=verify)
+ if response.status_code == codes[u"OK"]:
+ with open(file_name, u"wb") as file_handle:
+ file_handle.write(response.raw.read())
+ else:
+ logging.error(
+ f"Not possible to download the file "
+ f"{url} to {file_name}"
+ )
+
+ success = True
+ repeat = 0
+ except (HTTPException, HTTPError) as err:
+ logging.error(f"Connection broken:\n{repr(err)}")
+ except RequestException as err:
+ logging.error(f"HTTP Request exception:\n{repr(err)}")
+ except (IOError, ValueError, KeyError) as err:
+ logging.error(f"Download failed.\n{repr(err)}")
+ finally:
+ if session:
+ session.close()
+
+ logging.info(u" Download finished.")
+ return success, file_name
+
+
+def _unzip_file(spec, build, pid):