From fd3f47c08865cbbbd3ec3b9196c1765e3ee099b9 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 21 Sep 2012 13:54:45 +0000 Subject: Refactor _fetch() and log bundle fetches. Log (at chatty) when we start and finish bundle downloads. If we fail for any reason, log that reason since otherwise it gets swallowed if the plain git clone succeeds. --- morphlib/localrepocache.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'morphlib/localrepocache.py') diff --git a/morphlib/localrepocache.py b/morphlib/localrepocache.py index 89be56c8..de619770 100644 --- a/morphlib/localrepocache.py +++ b/morphlib/localrepocache.py @@ -126,17 +126,24 @@ class LocalRepoCache(object): This method is meant to be overridden by unit tests. ''' - - source_handle = urllib2.urlopen(url) - target_handle = open(filename, 'wb') - - data = source_handle.read(4096) - while data: - target_handle.write(data) - data = source_handle.read(4096) - - source_handle.close() - target_handle.close() + self._app.status(msg="Trying to fetch %(bundle)s to seed the cache", + bundle=url, + chatty=True) + source_handle = None + try: + source_handle = urllib2.urlopen(url) + with open(filename, 'wb') as target_handle: + shutil.copyfileobj(source_handle, target_handle) + self._app.status(msg="Bundle fetch successful", + chatty=True) + except Exception, e: + self._app.status(msg="Bundle fetch failed: %(reason)s", + reason=e, + chatty=True) + raise + finally: + if source_handle is not None: + source_handle.close() def _mkdir(self, dirname): # pragma: no cover '''Create a directory. -- cgit v1.2.1