summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-06-22 13:21:51 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2012-06-22 13:21:51 +0100
commit73e8bed080a2f5e19266646f306296c68637e8d0 (patch)
treeec24577119d4849ff811737037e337516f9692fc
parent1dfaa88a7e3f39d9479be25b60e27414e803f91b (diff)
parented3cce014aeaa4d1f45973dd58a55405f6d9ebd1 (diff)
downloadmorph-73e8bed080a2f5e19266646f306296c68637e8d0.tar.gz
Merge branch 'liw/distbuild-refactor' of git://roadtrain.codethink.co.uk/baserock/morph
-rwxr-xr-xmorphlib/app.py12
-rw-r--r--morphlib/remoteartifactcache.py19
-rw-r--r--morphlib/remoteartifactcache_tests.py3
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)