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.
This commit is contained in:
parent
1205de0abb
commit
4b94769f6b
3 changed files with 21 additions and 10 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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, {})
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue