Fix for https://github.com/salimfadhley/jenkinsapi/issues/54
authorSanteri Paavolainen <santeri.paavolainen@codento.com>
Tue, 23 Oct 2012 08:14:04 +0000 (11:14 +0300)
committerSanteri Paavolainen <santeri.paavolainen@codento.com>
Tue, 23 Oct 2012 08:15:57 +0000 (11:15 +0300)
Use opener via build object, if available. Fall back to direct
urllib.urlretrieve if opener is not available.

jenkinsapi/artifact.py

index e26c2ee..7edcd2b 100644 (file)
@@ -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):
         """