formats: load function takes combined manifest

Instead of having the pipeline and the source option as separate
arguments, the load function now takes the full manifest, which
has those two items combined.
This commit is contained in:
Christian Kellner 2020-12-16 17:49:37 +01:00 committed by Tom Gundersen
parent 0b6f36158d
commit a13783f67b
4 changed files with 17 additions and 12 deletions

View file

@ -8,14 +8,14 @@ from ..pipeline import Pipeline, detect_host_runner
def load_build(description: Dict, sources_options: Dict):
pipeline = description.get("pipeline")
if pipeline:
build_pipeline = load(pipeline, sources_options)
build_pipeline = load_pipeline(pipeline, sources_options)
else:
build_pipeline = None
return build_pipeline, description["runner"]
def load(description: Dict, sources_options: Dict) -> Pipeline:
def load_pipeline(description: Dict, sources_options: Dict) -> Pipeline:
build = description.get("build")
if build:
build_pipeline, runner = load_build(build, sources_options)
@ -34,6 +34,15 @@ def load(description: Dict, sources_options: Dict) -> Pipeline:
return pipeline
def load(description: Dict) -> Pipeline:
"""Load a manifest description"""
pipeline = description.get("pipeline", {})
sources = description.get("sources", {})
return load_pipeline(pipeline, sources)
def validate(manifest: Dict, index: Index) -> ValidationResult:
"""Validate a OSBuild manifest

View file

@ -116,10 +116,7 @@ def osbuild_cli():
show_validation(res, args.manifest_path)
return 2
pipeline = manifest.get("pipeline", {})
sources_options = manifest.get("sources", {})
pipeline = fmt.load(pipeline, sources_options)
pipeline = fmt.load(manifest)
if args.checkpoint:
missed = mark_checkpoints(pipeline, args.checkpoint)
@ -131,8 +128,8 @@ def osbuild_cli():
if args.inspect:
result = {"pipeline": pipeline.description(with_id=True)}
if sources_options:
result["sources"] = sources_options
if manifest.get("sources_options"):
result["sources"] = manifest["sources_options"]
json.dump(result, sys.stdout)
sys.stdout.write("\n")
return 0

View file

@ -30,8 +30,9 @@ class TestDescriptions(unittest.TestCase):
{"build": None}
]
for pipeline in cases:
manifest = {"pipeline": pipeline}
with self.subTest(pipeline):
self.assertEqual(fmt.load(pipeline, {}).description(), {})
self.assertEqual(fmt.load(manifest).description(), {})
def test_stage(self):
name = "org.osbuild.test"

View file

@ -353,10 +353,8 @@ class OSBuild(contextlib.AbstractContextManager):
"""
manifest_json = json.loads(manifest_data)
manifest_pipeline = manifest_json.get("pipeline", {})
manifest_sources = manifest_json.get("sources", {})
manifest_parsed = fmt.load(manifest_pipeline, manifest_sources)
manifest_parsed = fmt.load(manifest_json)
return manifest_parsed.tree_id
@contextlib.contextmanager