From: Santeri Paavolainen Date: Tue, 23 Oct 2012 08:14:04 +0000 (+0300) Subject: Fix for https://github.com/salimfadhley/jenkinsapi/issues/54 X-Git-Tag: v0.2.23~268^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=def24e1c4b88996778f5f92a71c054054ab95bbe;p=tools%2Fpython-jenkinsapi.git Fix for https://github.com/salimfadhley/jenkinsapi/issues/54 Use opener via build object, if available. Fall back to direct urllib.urlretrieve if opener is not available. --- diff --git a/jenkinsapi/artifact.py b/jenkinsapi/artifact.py index e26c2ee..7edcd2b 100644 --- a/jenkinsapi/artifact.py +++ b/jenkinsapi/artifact.py @@ -20,7 +20,7 @@ log = logging.getLogger(__name__) class Artifact(object): """ - Represents a single Jenkins artifact, usually some kind of file + Represents a single Jenkins artifact, usually some kind of file generated as a by-product of executing a Jenkins build. """ @@ -63,8 +63,16 @@ class Artifact(object): """ Download the the artifact to a path. """ - filename, _ = urllib.urlretrieve(self.url, filename=fspath) - return filename + if self.build: + opener = self.build.get_jenkins_obj().get_opener() + f = opener(self.url) + with open(fspath, "wb") as out: + out.write(f.read()) + + return fspath + else: + filename, _ = urllib.urlretrieve(self.url, filename=fspath) + return filename def _verify_download(self, fspath): """