summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-02-13 12:40:58 +0200
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-02-13 12:41:02 +0200
commitf8d3fc8a1f5fb7bb669abcbd0013e66ac877b983 (patch)
tree50dff29b86488286fdc0dc8dfd7eb9a27bb1e4dd
parentfc954aa57636836f60d3cdfe81b08cf29df4e27e (diff)
downloadgit-buildpackage-f8d3fc8a1f5fb7bb669abcbd0013e66ac877b983.tar.gz
git-buildpackage-f8d3fc8a1f5fb7bb669abcbd0013e66ac877b983.tar.bz2
git-buildpackage-f8d3fc8a1f5fb7bb669abcbd0013e66ac877b983.zip
import-srpm: move file download to a separate function
So that this functionality can be easily re-used elsewhere. Change-Id: I6f0f3e6efcbd6462810d0116da6d06bef57919cf Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rwxr-xr-xgbp/scripts/import_srpm.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py
index fd506654..b41e85ba 100755
--- a/gbp/scripts/import_srpm.py
+++ b/gbp/scripts/import_srpm.py
@@ -64,6 +64,20 @@ class PatchImportError(Exception):
pass
+def download_file(target_dir, url):
+ """Download a remote file"""
+ gbp.log.info("Downloading '%s'..." % url)
+ try:
+ urlobj = urllib2.urlopen(url)
+ local_fn = os.path.join(target_dir, os.path.basename(url))
+ with open(local_fn, "wb") as local_file:
+ local_file.write(urlobj.read())
+ except urllib2.HTTPError as err:
+ raise GbpError("Download failed: %s" % err)
+ except urllib2.URLError as err:
+ raise GbpError("Download failed: %s" % err.reason)
+ return local_fn
+
def download_source(pkg, dirs):
"""Download package from a remote location"""
if re.match(r'[a-z]{1,5}://', pkg):
@@ -72,7 +86,7 @@ def download_source(pkg, dirs):
mode = 'yumdownloader'
tmpdir = tempfile.mkdtemp(dir=dirs['tmp_base'], prefix='download_')
- gbp.log.info("Downloading '%s' using '%s'..." % (pkg, mode))
+ gbp.log.info("Trying to download '%s' using '%s'..." % (pkg, mode))
if mode == 'yumdownloader':
gbpc.RunAtCommand('yumdownloader',
['--source', '--destdir=', '.', pkg],