diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-09-21 13:54:45 +0000 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-09-21 15:24:31 +0100 |
commit | fd3f47c08865cbbbd3ec3b9196c1765e3ee099b9 (patch) | |
tree | 1e34684db52c9c994b8b9d55e4c9448d0dc81d55 | |
parent | dbc7cee2d8c0c307e8805bde876b30f2fac2eb46 (diff) | |
download | morph-fd3f47c08865cbbbd3ec3b9196c1765e3ee099b9.tar.gz |
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.
-rw-r--r-- | morphlib/localrepocache.py | 29 |
1 files changed, 18 insertions, 11 deletions
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. |