summaryrefslogtreecommitdiff
path: root/morphlib/morphologyfactory.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-18 16:34:56 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-18 17:29:59 +0100
commitb068b7fa1331a7c6e2ef0632d9566310bfa58b9d (patch)
treea5ba4624e87860920059cc4a4b931c75a5b5d778 /morphlib/morphologyfactory.py
parent0a1c41a539adee00cf4eefa81d4ab8841b65b10f (diff)
downloadmorph-b068b7fa1331a7c6e2ef0632d9566310bfa58b9d.tar.gz
Have MorphologyFactory set Morphology.builds_artifacts
This way we can have one place in the code where we determine what artifacts get built from a specific morphology, rather than spreading the information around the code base. From now on, everything is supposed to use the builds_artifacts attribute to get the list of artifacts. ArtifactResolver has been changed to do that. Some of the tests are now a bit messier, and should really be changed to create Morphology objects using MorphologyFactory, but that's a change for another day.
Diffstat (limited to 'morphlib/morphologyfactory.py')
-rw-r--r--morphlib/morphologyfactory.py59
1 files changed, 45 insertions, 14 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py
index b28f2a4a..c53d2478 100644
--- a/morphlib/morphologyfactory.py
+++ b/morphlib/morphologyfactory.py
@@ -50,20 +50,12 @@ class MorphologyFactory(object):
text = self._autodetect_text(reponame, sha1, filename)
morphology = morphlib.morph2.Morphology(text)
- if morphology['kind'] == 'system' and \
- morphology['arch'] is None: #pragma: no cover
- raise morphlib.Error('No arch specified in system %s '
- '(arch is a mandatory field)' %
- filename)
- 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))
+
+ method_name = '_check_and_tweak_%s' % morphology['kind']
+ if hasattr(self, method_name):
+ method = getattr(self, method_name)
+ method(morphology, reponame, sha1, filename)
+
return morphology
def _cat_text(self, reponame, sha1, filename):
@@ -106,3 +98,42 @@ class MorphologyFactory(object):
morph_name = filename[:-len('.morph')]
morph_text = bs.get_morphology_text(morph_name)
return morph_text
+
+ def _check_and_tweak_system(self, morphology, reponame, sha1, filename):
+ '''Check and tweak a system morphology.'''
+
+ if morphology['arch'] is None: #pragma: no cover
+ raise morphlib.Error('No arch specified in system %s '
+ '(arch is a mandatory field)' %
+ filename)
+
+ name = morphology['name']
+ if morphology['arch'] == 'arm':
+ morphology.builds_artifacts = [name + '-kernel', name + '-rootfs']
+ else:
+ # FIXME: -rootfs is a misnomer, should be -disk, but can't
+ # change this during refactoring.
+ morphology.builds_artifacts = [name + '-rootfs']
+
+ def _check_and_tweak_stratum(self, morphology, reponame, sha1, filename):
+ '''Check and tweak a stratum morphology.'''
+
+ for source in morphology['sources']: # pragma: no cover
+ 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))
+
+ morphology.builds_artifacts = [morphology['name']]
+
+ def _check_and_tweak_chunk(self, morphology, reponame, sha1, filename):
+ '''Check and tweak a chunk morphology.'''
+
+ if 'chunks' in morphology and len(morphology['chunks']) > 1:
+ morphology.builds_artifacts = morphology['chunks'].keys()
+ else:
+ morphology.builds_artifacts = [morphology['name']]
+