diff options
-rwxr-xr-x | morphlib/app.py | 12 | ||||
-rw-r--r-- | morphlib/remoteartifactcache.py | 19 | ||||
-rw-r--r-- | morphlib/remoteartifactcache_tests.py | 3 |
3 files changed, 25 insertions, 9 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 18187a36..443b1733 100755 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -252,9 +252,15 @@ class Morph(cliapp.Application): os.path.exists(staging_area.tempdir)): shutil.rmtree(staging_area.tempdir) - def install_artifacts(self, staging_area, lac, chunk_artifacts): + def install_artifacts(self, staging_area, lac, rac, chunk_artifacts): for chunk_artifact in chunk_artifacts: self.msg(' Installing %s' % chunk_artifact.name) + if not lac.has(chunk_artifact) and rac: + remote = rac.get(chunk_artifact) + local = lac.put(chunk_artifact) + shutil.copyfileobj(remote, local) + remote.close() + local.close() handle = lac.get(chunk_artifact) staging_area.install_artifact(handle) @@ -347,7 +353,7 @@ class Morph(cliapp.Application): to_install = [] for group in order.groups: if install_chunks: - self.install_artifacts(staging_area, lac, to_install) + self.install_artifacts(staging_area, lac, rac, to_install) del to_install[:] for artifact in set(group).difference(set(needed)): self.msg('Using cached %s' % artifact.name) @@ -360,7 +366,7 @@ class Morph(cliapp.Application): # If we are running bootstrap we probably also want the last # build group to be installed as well if self.settings['bootstrap']: - self.install_artifacts(staging_area, lac, to_install) + self.install_artifacts(staging_area, lac, rac, to_install) self.remove_staging_area(staging_area) diff --git a/morphlib/remoteartifactcache.py b/morphlib/remoteartifactcache.py index e2101b5d..aaab4a3c 100644 --- a/morphlib/remoteartifactcache.py +++ b/morphlib/remoteartifactcache.py @@ -15,6 +15,7 @@ import cliapp +import logging import urllib2 import urlparse @@ -29,8 +30,9 @@ class GetError(cliapp.AppException): def __init__(self, cache, artifact): cliapp.AppException.__init__( - self, 'Failed to get the artifact %s from the ' - 'artifact cache %s' % (artifact, cache)) + self, 'Failed to get the artifact %s with cache key %s ' + 'from the artifact cache %s' % + (artifact, artifact.cache_key, cache)) class GetArtifactMetadataError(cliapp.AppException): @@ -68,24 +70,27 @@ class RemoteArtifactCache(object): def get(self, artifact): try: return self._get_file(artifact.basename()) - except: + except urllib2.URLError, e: + logging.error(str(e)) raise GetError(self, artifact) def get_artifact_metadata(self, artifact, name): try: return self._get_file(artifact.metadata_basename(name)) - except: + except urllib2.URLError, e: + logging.error(str(e)) raise GetArtifactMetadataError(self, artifact, name) def get_source_metadata(self, source, cachekey, name): filename = '%s.%s' % (cachekey, name) try: return self._get_file(filename) - except: + except urllib2.URLError: raise GetSourceMetadataError(self, source, cachekey, name) def _has_file(self, filename): # pragma: no cover url = self._request_url(filename) + logging.debug('RemoteArtifactCache._has_file: url=%s' % url) request = HeadRequest(url) try: urllib2.urlopen(request) @@ -95,6 +100,7 @@ class RemoteArtifactCache(object): def _get_file(self, filename): # pragma: no cover url = self._request_url(filename) + logging.debug('RemoteArtifactCache._get_file: url=%s' % url) return urllib2.urlopen(url) def _request_url(self, filename): # pragma: no cover @@ -103,3 +109,6 @@ class RemoteArtifactCache(object): server_url += '/' return urlparse.urljoin( server_url, '/1.0/artifacts?filename=%s' % filename) + + def __str__(self): # pragma: no cover + return self.server_url diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py index b7f10450..201cfc50 100644 --- a/morphlib/remoteartifactcache_tests.py +++ b/morphlib/remoteartifactcache_tests.py @@ -16,6 +16,7 @@ import StringIO import unittest +import urllib2 import morphlib @@ -76,7 +77,7 @@ class RemoteArtifactCacheTests(unittest.TestCase): if filename in self.existing_files: return StringIO.StringIO('%s' % filename) else: - raise Exception('foo') + raise urllib2.URLError('foo') def test_sets_server_url(self): self.assertEqual(self.cache.server_url, self.server_url) |