Use urllib2.urlopen()/shutil.copyfileobj() in get_file() so that
fetching missing documents is properly reported as an exception instead
of fetching some dummy 404 document.
Signed-off-by: Mihai Rusu <dizzy@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3201 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 302c6be..02cbe45 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -4,7 +4,7 @@
import os, pickle, random, re, resource, select, shutil, signal, StringIO
import socket, struct, subprocess, sys, time, textwrap, urllib, urlparse
-import warnings, smtplib, logging
+import warnings, smtplib, logging, urllib2
from autotest_lib.client.common_lib import error, barrier
def deprecated(func):
@@ -238,18 +238,25 @@
def get_file(src, dest, permissions=None):
"""Get a file from src, which can be local or a remote URL"""
- if (src == dest):
+ if src == dest:
return
- if (is_url(src)):
- print 'PWD: ' + os.getcwd()
- print 'Fetching \n\t', src, '\n\t->', dest
+
+ if is_url(src):
+ logging.debug('PWD: %s', os.getcwd())
+ logging.info('Fetching %s -> %s', src, dest)
+
+ src_file = urllib2.urlopen(src)
try:
- urllib.urlretrieve(src, dest)
- except IOError, e:
- raise error.AutotestError('Unable to retrieve %s (to %s)'
- % (src, dest), e)
+ dest_file = open(dest, 'wb')
+ try:
+ shutil.copyfileobj(src_file, dest_file)
+ finally:
+ dest_file.close()
+ finally:
+ src_file.close()
else:
shutil.copyfile(src, dest)
+
if permissions:
os.chmod(dest, permissions)
return dest