- file_handle.close()
-
- if spec.input["file-name"].endswith(".zip"):
- expected_length = None
- try:
- expected_length = int(response.
- headers["Content-Length"])
- logging.debug(" Expected file size: {0}B".
- format(expected_length))
- except KeyError:
- logging.debug(" No information about expected size.")
-
- real_length = getsize(new_name)
- logging.debug(" Downloaded size: {0}B".format(real_length))
-
- if expected_length:
- if real_length == expected_length:
- status = "downloaded"
- logging.info("{0}: {1}".format(code,
- responses[code]))
- else:
- logging.error("The file size differs from the "
- "expected size.")
- else:
- status = "downloaded"
- logging.info("{0}: {1}".format(code, responses[code]))
-
- elif spec.input["file-name"].endswith(".gz"):
- rename(new_name, new_name[:-3])
- with open(new_name[:-3], 'r') as xml_file:
- with gzip.open(new_name, 'wb') as gz_file:
- gz_file.write(xml_file.read())
- new_name = new_name[:-3]
- status = "downloaded"
- logging.info("{0}: {1}".format(code, responses[code]))
-
- except ConnectionError as err:
- logging.error("Not possible to connect to '{0}'.".format(url))
- logging.debug(err)
- except HTTPError as err:
- logging.error("Invalid HTTP response from '{0}'.".format(url))
- logging.debug(err)
- except TooManyRedirects as err:
- logging.error("Request exceeded the configured number "
- "of maximum re-directions.")
- logging.debug(err)
- except Timeout as err:
- logging.error("Request timed out.")
- logging.debug(err)
- except RequestException as err:
- logging.error("Unexpected HTTP request exception.")
- logging.debug(err)
- except (IOError, ValueError, KeyError) as err:
- logging.error("Download failed.")
- logging.debug("Reason: {0}".format(err))
-
- spec.set_input_state(job, build["build"], status)
- spec.set_input_file_name(job, build["build"], new_name)
-
- if status == "failed":
- logging.info("Removing the file '{0}'".format(new_name))
- try:
- remove(new_name)
- except OSError as err:
- logging.warning(str(err))
- spec.set_input_file_name(job, build["build"], None)
-
- unzip_files(spec)
-
-
-def unzip_files(spec):
- """Unzip downloaded zip files
-
- :param spec: Specification.
+
+ 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):
+ """Unzip downloaded source file.
+
+ :param spec: Specification read form the specification file.
+ :param build: Information about the build.