summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-07-10 15:43:26 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-07-11 12:11:23 +0100
commitc95302b925922ca0b900421fe9ecf7842d1949cc (patch)
treea11f2a4526d8466a6e689ff81ebdf52535a7e5cb
parentf653e5fc67c521668d07896ca164c5615c2f9dae (diff)
downloadmorph-c95302b925922ca0b900421fe9ecf7842d1949cc.tar.gz
Move stratum verification to morphologyfactory
I think morphologies should be verified closer to where they are created, not when they are traversed, since this verification would be useful in more code paths. This is in morphologyfactory, rather than Morphology itself, since it may be useful to be able to create morphologies without checking, such as in unit tests.
-rwxr-xr-xmorphlib/app.py12
-rw-r--r--morphlib/morphologyfactory.py13
2 files changed, 12 insertions, 13 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index 5d5a2039..64c1b6b7 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -476,19 +476,7 @@ class Morph(cliapp.Application):
def _create_source_pool(self, lrc, rrc, triplet):
pool = morphlib.sourcepool.SourcePool()
- def check_stratum(filename, morphology):
- for source in morphology['sources']:
- if source.get('build-depends', None) is None:
- name = source.get('name', source.get('repo', 'unknown'))
- raise morphlib.Error('No build dependencies '
- 'stratum %s for chunk %s '
- '(build-depends is a mandatory '
- 'field)' %
- (filename, name))
-
def add_to_pool(reponame, ref, filename, absref, morphology):
- if morphology['kind'] == 'stratum':
- check_stratum(filename, morphology)
source = morphlib.source.Source(reponame, ref, absref,
morphology, filename)
pool.add(source)
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py
index 6f9915fb..c84acd52 100644
--- a/morphlib/morphologyfactory.py
+++ b/morphlib/morphologyfactory.py
@@ -45,7 +45,18 @@ class MorphologyFactory(object):
text = self._cat_text(reponame, sha1, filename)
except:
text = self._autodetect_text(reponame, sha1, filename)
- return morphlib.morph2.Morphology(text)
+
+ morphology = morphlib.morph2.Morphology(text)
+ if morphology['kind'] == 'stratum': #pragma: no cover
+ for source in morphology['sources']:
+ if source.get('build-depends', None) is None:
+ name = source.get('name', source.get('repo', 'unknown'))
+ raise morphlib.Error('No build dependencies '
+ 'stratum %s for chunk %s '
+ '(build-depends is a mandatory '
+ 'field)' %
+ (filename, name))
+ return morphology
def _cat_text(self, reponame, sha1, filename):
if self._lrc.has_repo(reponame):