From 4b94769f6bc002bf8ffa8f8a05e7aa9a7c40cf4c Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 25 Nov 2022 13:29:48 +0100 Subject: [PATCH] format: read metadata from object not result Now that metadata is stored and can be accessed via `Object.meta`, read it from the built or stored objects when serializing the result in the `format.output` functions. --- osbuild/formats/v1.py | 13 ++++++++----- osbuild/formats/v2.py | 16 ++++++++++++---- osbuild/main_cli.py | 2 +- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/osbuild/formats/v1.py b/osbuild/formats/v1.py index 5943fa54..76e9d5c8 100644 --- a/osbuild/formats/v1.py +++ b/osbuild/formats/v1.py @@ -195,17 +195,17 @@ def load(description: Dict, index: Index) -> Manifest: return manifest -def output(manifest: Manifest, res: Dict) -> Dict: +def output(manifest: Manifest, res: Dict, store=None) -> Dict: """Convert a result into the v1 format""" - def result_for_stage(result: BuildResult): + def result_for_stage(result: BuildResult, obj): return { "id": result.id, "type": result.name, "success": result.success, "error": result.error, "output": result.output, - "metadata": result.metadata, + "metadata": obj and obj.meta.get(result.id), } def result_for_pipeline(pipeline): @@ -223,10 +223,12 @@ def output(manifest: Manifest, res: Dict) -> Dict: retval["build"] = result_for_pipeline(build) retval["success"] = retval["build"]["success"] + obj = store and pipeline.id and store.get(pipeline.id) + stages = current.get("stages") if stages: retval["stages"] = [ - result_for_stage(r) for r in stages + result_for_stage(r, obj) for r in stages ] return retval @@ -244,8 +246,9 @@ def output(manifest: Manifest, res: Dict) -> Dict: # The assembler pipeline must have exactly one stage # which is the v1 assembler + obj = store and store.get(assembler.id) stage = current["stages"][0] - result["assembler"] = result_for_stage(stage) + result["assembler"] = result_for_stage(stage, obj) if not result["assembler"]["success"]: result["success"] = False diff --git a/osbuild/formats/v2.py b/osbuild/formats/v2.py index 555bfb8b..5640b6ac 100644 --- a/osbuild/formats/v2.py +++ b/osbuild/formats/v2.py @@ -7,6 +7,7 @@ from typing import Any, Dict from osbuild.meta import Index, ModuleInfo, ValidationResult from ..inputs import Input +from ..objectstore import ObjectStore from ..pipeline import Manifest, Pipeline, Runner, Stage from ..sources import Source @@ -391,14 +392,21 @@ def load(description: Dict, index: Index) -> Manifest: #pylint: disable=too-many-branches -def output(manifest: Manifest, res: Dict) -> Dict: +def output(manifest: Manifest, res: Dict, store: ObjectStore = None) -> Dict: """Convert a result into the v2 format""" def collect_metadata(p: Pipeline) -> Dict[str, Any]: data: Dict[str, Any] = {} - r = res.get(p.id, {}) - for stage in r.get("stages", []): - md = stage.metadata + + if not store: # for testing + return data + + obj = store.get(p.id) + if not obj: + return data + + for stage in p.stages: + md = obj.meta.get(stage.id) if not md: continue val = data.setdefault(stage.name, {}) diff --git a/osbuild/main_cli.py b/osbuild/main_cli.py index cee74542..fbf23916 100644 --- a/osbuild/main_cli.py +++ b/osbuild/main_cli.py @@ -169,7 +169,7 @@ def osbuild_cli(): export(pid, output_directory, object_store, manifest) if args.json: - r = fmt.output(manifest, r) + r = fmt.output(manifest, r, object_store) json.dump(r, sys.stdout) sys.stdout.write("\n") else: