summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-02-10 12:46:50 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-02-11 16:04:44 +0000
commitadbf4083b8d88bbcb17d3d1a4bf56f204a909d13 (patch)
tree3c17706715eeb0fd84d5cf3c0aa0b7121ab78cdb
parent81905d738a1343ad1d9da7f3977743c04601f0ba (diff)
downloadmorph-adbf4083b8d88bbcb17d3d1a4bf56f204a909d13.tar.gz
WIPO
-rw-r--r--morphlib/buildcommand.py11
-rw-r--r--morphlib/localartifactcache.py13
-rw-r--r--morphlib/remoteartifactcache.py7
-rw-r--r--morphlib/remoteartifactcache_tests.py8
-rw-r--r--morphlib/source.py2
5 files changed, 25 insertions, 16 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index 04321b42..d97d52fb 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -296,8 +296,15 @@ class BuildCommand(object):
if self.rac is not None:
try:
self.cache_artifacts_locally([source])
- except morphlib.remoteartifactcache.GetError:
- # Error is logged by the RemoteArtifactCache object.
+ except morphlib.remoteartifactcache.GetError as e:
+ if e.http_error.response.status_code == 404:
+ error = 'not present.'
+ else
+ error = e.http_error
+
+ self.status(
+ msg='Unable to fetch artifact from cache: %(error)s'
+ error=error)
pass
artifacts = source.artifacts.values()
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
index e1bfe6a3..c7eccf4c 100644
--- a/morphlib/localartifactcache.py
+++ b/morphlib/localartifactcache.py
@@ -48,16 +48,17 @@ class LocalArtifactCache(object):
def __init__(self, cachefs):
self.cachefs = cachefs
- def put_file(self, basename):
- filename = self._join(basename)
- return morphlib.savefile.SaveFile(filename, mode='w')
+ def put(self, artifact):
+ return self.put_file(artifact.basename())
def put_artifact_metadata(self, artifact, name):
- filename = self._artifact_metadata_filename(artifact, name)
- return morphlib.savefile.SaveFile(filename, mode='w')
+ return self.put_file(artifact.metadata_basename(name))
def put_source_metadata(self, source, cachekey, name):
- filename = self._source_metadata_filename(source, cachekey, name)
+ return self.put_file('%s.%s' % (cachekey, name))
+
+ def put_file(self, basename):
+ filename = self._join(basename)
return morphlib.savefile.SaveFile(filename, mode='w')
def has_file(self, basename):
diff --git a/morphlib/remoteartifactcache.py b/morphlib/remoteartifactcache.py
index 76867c14..1b48f8f4 100644
--- a/morphlib/remoteartifactcache.py
+++ b/morphlib/remoteartifactcache.py
@@ -24,10 +24,11 @@ import requests
class GetError(cliapp.AppException):
- def __init__(self, cache, filename, error):
+ def __init__(self, cache, filename, http_error):
+ self.http_error = http_error
cliapp.AppException.__init__(
self, 'Failed to get the file %s from the artifact cache %s: %s' %
- (filename, cache, error))
+ (filename, cache, http_error))
class RemoteArtifactCache(object):
@@ -115,7 +116,7 @@ class RemoteArtifactCache(object):
if len(to_fetch) > 0:
if status_cb:
status_cb(
- msg='Fetching to local cache: built artifacts of %(name)s',
+ msg='Fetching built artifacts of %(name)s',
name=source.name)
self._fetch_files(to_fetch)
diff --git a/morphlib/remoteartifactcache_tests.py b/morphlib/remoteartifactcache_tests.py
index 79c581ac..680bb22d 100644
--- a/morphlib/remoteartifactcache_tests.py
+++ b/morphlib/remoteartifactcache_tests.py
@@ -112,8 +112,8 @@ class RemoteArtifactCacheTests(unittest.TestCase):
lac = morphlib.testutils.FakeLocalArtifactCache()
self.assertFalse(lac.has(an_artifact))
- rac.get_artifacts(
- chunk.artifacts.values(), lac, self.fake_status_cb)
+ rac.get_artifacts_for_source(
+ chunk, lac, self.fake_status_cb)
self.assertTrue(lac.has(an_artifact))
def test_artifacts_are_not_cached(self):
@@ -131,8 +131,8 @@ class RemoteArtifactCacheTests(unittest.TestCase):
lac = morphlib.testutils.FakeLocalArtifactCache()
with self.assertRaises(morphlib.remoteartifactcache.GetError):
- rac.get_artifacts(
- chunk.artifacts.values(), lac, self.fake_status_cb)
+ rac.get_artifacts_for_source(
+ chunk, lac, self.fake_status_cb)
def test_escapes_pluses_in_request_urls(self):
rac = morphlib.remoteartifactcache.RemoteArtifactCache(
diff --git a/morphlib/source.py b/morphlib/source.py
index e37d8cba..83f61dad 100644
--- a/morphlib/source.py
+++ b/morphlib/source.py
@@ -84,7 +84,7 @@ class Source(object):
if self.morphology['kind'] == 'chunk':
files.add(self.build_log_basename())
- for artifact in self.artifacts:
+ for artifact in self.artifacts.values():
files.add(artifact.basename())
if self.morphology.needs_artifact_metadata_cached:
files.add(artifact.metadata_basename())