diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-23 14:59:57 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-07-23 14:59:57 +0100 |
commit | 82ae6038c00ca7ceb0e1ed206bd07157e1658f50 (patch) | |
tree | cff2b166c37740b2301145bc0b44c647bd7b12a4 /morphlib/morphologyfactory.py | |
parent | e14084d535ddf37722da692133e9000d8f55a5d5 (diff) | |
parent | dfaf624b1fb97c2208bf03b9ff314c5566575e5f (diff) | |
download | morph-82ae6038c00ca7ceb0e1ed206bd07157e1658f50.tar.gz |
Merge branch 'liw/require-system-kind'
Reviewed-By: Richard Maw
Reviewed-By: Lars Wirzenius
Diffstat (limited to 'morphlib/morphologyfactory.py')
-rw-r--r-- | morphlib/morphologyfactory.py | 78 |
1 files changed, 62 insertions, 16 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index de9e03e5..925829e9 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -1,5 +1,3 @@ -#!/usr/bin/python -# # Copyright (C) 2012 Codethink Limited # # This program is free software; you can redistribute it and/or modify @@ -18,22 +16,27 @@ import morphlib import cliapp + class MorphologyFactoryError(cliapp.AppException): pass + class AutodetectError(MorphologyFactoryError): def __init__(self, repo_name, ref): MorphologyFactoryError.__init__(self, "Failed to determine the build system of repo %s at " "ref %s" % (repo_name, ref)) + class NotcachedError(MorphologyFactoryError): def __init__(self, repo_name): MorphologyFactoryError.__init__(self, "Repository %s is not cached locally and there is no " "remote cache specified" % repo_name) + class MorphologyFactory(object): + '''An way of creating morphologies which will provide a default''' def __init__(self, local_repo_cache, remote_repo_cache=None): @@ -47,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): @@ -103,3 +98,54 @@ 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) + + if not morphology['system-kind']: + raise morphlib.Error('No system-kind defined in system %s ' + '(it 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'] + + morphology.needs_staging_area = False + morphology.needs_artifact_metadata_cached = False + + 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']] + morphology.needs_staging_area = False + morphology.needs_artifact_metadata_cached = True + + 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']] + + morphology.needs_staging_area = True + morphology.needs_artifact_metadata_cached = False + |