summaryrefslogtreecommitdiffstats
path: root/dist-git/dist_git/dist_git_importer.py
diff options
context:
space:
mode:
authorValentin Gologuzov <vgologuz@redhat.com>2015-08-20 10:12:00 (GMT)
committerValentin Gologuzov <vgologuz@redhat.com>2015-08-20 10:12:00 (GMT)
commit7c1aa0c74c7bf5c40cf5f83f2dfb9c63d2228d21 (patch)
tree3cf83e1aaa5c3f8e10eab4827d02dbedf796d6cf /dist-git/dist_git/dist_git_importer.py
parent5e4b75d231bb2ebf9ef39ca22c035d880008f4d8 (diff)
downloadcopr-7c1aa0c74c7bf5c40cf5f83f2dfb9c63d2228d21.zip
copr-7c1aa0c74c7bf5c40cf5f83f2dfb9c63d2228d21.tar.gz
copr-7c1aa0c74c7bf5c40cf5f83f2dfb9c63d2228d21.tar.xz
[dist-git] replace urllib.urlretrieve with requests.get to catch non-200 HTTP status codes
Diffstat (limited to 'dist-git/dist_git/dist_git_importer.py')
-rwxr-xr-xdist-git/dist_git/dist_git_importer.py36
1 files changed, 27 insertions, 9 deletions
diff --git a/dist-git/dist_git/dist_git_importer.py b/dist-git/dist_git/dist_git_importer.py
index 52ab501..701e030 100755
--- a/dist-git/dist_git/dist_git_importer.py
+++ b/dist-git/dist_git/dist_git_importer.py
@@ -94,6 +94,32 @@ class ImportTask(object):
}
+def do_srpm_fetch(task, target_path):
+ """
+ :param ImportTask task:
+ :param str target_path:
+ :raises PackageDownloadException:
+ """
+ log.debug("download the package")
+ try:
+ r = get(task.package_url, stream=True)
+ except Exception:
+ raise PackageDownloadException("Unexpected error during URL fetch: {}"
+ .format(task.package_url))
+
+ if 200 <= r.status_code < 400:
+ try:
+ with open(target_path, 'wb') as f:
+ for chunk in r.iter_content(1024):
+ f.write(chunk)
+ except Exception:
+ raise PackageDownloadException("Unexpected error during URL retrieval: {}"
+ .format(task.package_url))
+ else:
+ raise PackageDownloadException("Failed to fetch: {} with HTTP status: {}"
+ .format(task.package_url, r.status_code))
+
+
class DistGitImporter(object):
def __init__(self, opts):
self.is_running = False
@@ -121,14 +147,6 @@ class DistGitImporter(object):
log.exception("Failed acquire new packages for import")
return
- @staticmethod
- def fetch_srpm(task, fetched_srpm_path):
- log.debug("download the package")
- try:
- urlretrieve(task.package_url, fetched_srpm_path)
- except IOError:
- raise PackageDownloadException()
-
def git_import_srpm(self, task, filepath):
"""
Imports a source rpm file into local dist git.
@@ -208,7 +226,7 @@ class DistGitImporter(object):
fetched_srpm_path = os.path.join(tmp_root, "package.src.rpm")
try:
- self.fetch_srpm(task, fetched_srpm_path)
+ do_srpm_fetch(task, fetched_srpm_path)
task.package_name, task.package_version = self.pkg_name_evr(fetched_srpm_path)
self.before_git_import(task)