From def24e1c4b88996778f5f92a71c054054ab95bbe Mon Sep 17 00:00:00 2001 From: Santeri Paavolainen Date: Tue, 23 Oct 2012 11:14:04 +0300 Subject: [PATCH] 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. --- jenkinsapi/artifact.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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): """ -- 2.7.4