summaryrefslogtreecommitdiff
path: root/morphlib/builder2.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-06-14 11:15:43 +0100
committerRichard Maw <richard.maw@codethink.co.uk>2012-06-14 11:32:57 +0000
commit18a3b4dbf2fabf46cca6f163ec949d22437ee966 (patch)
treeb3a9d5187c6d1e026b65b44a756d16b546ceae22 /morphlib/builder2.py
parent7bd0212869917b0aa32455764b9b763f8e0d64e1 (diff)
downloadmorph-18a3b4dbf2fabf46cca6f163ec949d22437ee966.tar.gz
morphlib.builder2: write overlaps to cache
Rather than just log the overlaps, write them to the cache as well
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r--morphlib/builder2.py53
1 files changed, 38 insertions, 15 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 56834902..08427b6f 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -78,13 +78,13 @@ def get_chunk_files(f):
tar.close()
def get_stratum_files(f, lac):
- for ca in ((ArtifactCacheReference(a) for a in json.load(f)):
+ for ca in (ArtifactCacheReference(a) for a in json.load(f)):
cf = lac.get(ca)
for filename in get_chunk_files(cf):
yield filename
cf.close()
-def check_overlap(artifact, constituents, lac): #pragma: no cover
+def get_overlaps(artifact, constituents, lac): #pragma: no cover
# check whether strata overlap
installed = defaultdict(set)
for dep in constituents:
@@ -100,15 +100,26 @@ def check_overlap(artifact, constituents, lac): #pragma: no cover
for filename, artifacts in installed.iteritems():
if len(artifacts) > 1:
overlaps[frozenset(artifacts)].add(filename)
- if len(overlaps) > 0:
- logging.warning('Overlaps in artifact %s detected' % artifact.name)
- for overlapping, files in sorted(overlaps.iteritems()):
- logging.warning(' Artifacts %s overlap with files:' %
- ', '.join(sorted(a.name for a in overlapping))
- )
- for filename in sorted(files):
- logging.warning(' %s' % filename)
-
+ return overlaps
+
+def log_overlaps(overlaps):
+ for overlapping, files in sorted(overlaps.iteritems()):
+ logging.warning(' Artifacts %s overlap with files:' %
+ ', '.join(sorted(a.name for a in overlapping))
+ )
+ for filename in sorted(files):
+ logging.warning(' %s' % filename)
+
+def write_overlap_metadata(artifact, overlaps, lac):
+ f = lac.put_artifact_metadata(artifact, 'overlaps')
+ # the big list comprehension is because json can't serialize
+ # artifacts, sets or dicts with non-string keys
+ json.dump([
+ [
+ [a.name for a in afs], list(files)
+ ] for afs, files in overlaps.iteritems()
+ ], f, indent=4)
+ f.close()
class BuilderBase(object):
@@ -376,8 +387,14 @@ class StratumBuilder(BuilderBase):
self.local_artifact_cache,
self.remote_artifact_cache)
# check for chunk overlaps
- check_overlap(self.artifact, constituents,
- self.local_artifact_cache)
+ overlaps = get_overlaps(self.artifact, constituents,
+ self.local_artifact_cache)
+ if len(overlaps) > 0:
+ logging.warning('Overlaps in stratum artifact %s detected'
+ % self.artifact.name)
+ log_overlaps(overlaps)
+ write_overlap_metadata(self.artifact, overlaps,
+ self.local_artifact_cache)
with self.build_watch('create-chunk-list'):
artifact_name = self.artifact.source.morphology['name']
@@ -508,8 +525,14 @@ class SystemBuilder(BuilderBase): # pragma: no cover
f.close()
# check whether the strata overlap
- check_overlap(self.artifact, self.artifact.dependencies,
- self.local_artifact_cache)
+ overlaps = get_overlaps(self.artifact, self.artifact.dependencies,
+ self.local_artifact_cache)
+ if len(overlaps) > 0:
+ logging.warning('Overlaps in system artifact %s detected' %
+ self.artifact.name)
+ log_overlaps(overlaps)
+ write_overlap_metadata(self.artifact, overlaps,
+ self.local_artifact_cache)
# unpack it from the local artifact cache
for stratum_artifact in self.artifact.dependencies: