diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-10-11 15:58:25 +0100 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2012-10-11 17:36:46 +0100 |
commit | de6180d4cd4e4f29c12dcaea876d7e88659dc7dc (patch) | |
tree | 88cae1768aef96f3154fc5496e9fa707cc20b1ad /morphlib/plugins | |
parent | 8b092e0124f8a06337ffaa44a4d9d04f6cb90b5b (diff) | |
download | morph-de6180d4cd4e4f29c12dcaea876d7e88659dc7dc.tar.gz |
Add morphology validation to branch+merge
Diffstat (limited to 'morphlib/plugins')
-rw-r--r-- | morphlib/plugins/branch_and_merge_plugin.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py index c7681030..6d8387eb 100644 --- a/morphlib/plugins/branch_and_merge_plugin.py +++ b/morphlib/plugins/branch_and_merge_plugin.py @@ -273,8 +273,43 @@ class BranchAndMergePlugin(cliapp.Plugin): raise morphlib.Error("Error parsing %s: %s" % (filename, str(e))) + self._validate_morphology(morphology, '%s.morph' % name) + return morphology + def _validate_morphology(self, morphology, basename): + # FIXME: This really should be in MorphologyFactory. Later. + + def require(field): + if field not in morphology: + raise morphlib.Error( + 'Required field "%s" is missing from morphology %s' % + (field, basename)) + + required = { + 'system': [ + 'name', + 'system-kind', + 'arch', + 'strata', + ], + 'stratum': [ + 'name', + 'chunks', + ], + 'chunk': [ + 'name', + ] + } + + require('kind') + kind = morphology['kind'] + if kind not in required: + raise morphlib.Error( + 'Unknown morphology kind "%s" in %s' % (kind, basename)) + for field in required[kind]: + require(field) + def reset_work_tree_safe(self, repo_dir): # This function avoids throwing any exceptions, so it is safe to call # inside an 'except' block without altering the backtrace. |