From ba7f6fe7c77e340b56db297e17a459782e371a91 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 26 Jan 2021 22:10:57 +0000 Subject: [PATCH] formats/v1: extract stage parsing into function Extract the code that creates a stage given its description into its own function. --- osbuild/formats/v1.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osbuild/formats/v1.py b/osbuild/formats/v1.py index 1cf34e59..c66bcddb 100644 --- a/osbuild/formats/v1.py +++ b/osbuild/formats/v1.py @@ -80,6 +80,13 @@ def load_build(description: Dict, index: Index, manifest: Manifest, n: int): return build_pipeline, description["runner"] +def load_stage(description: Dict, index: Index, pipeline: Pipeline): + name = description["name"] + opts = description.get("options", {}) + info = index.get_module_info("Stage", name) + pipeline.add_stage(info, opts) + + def load_pipeline(description: Dict, index: Index, manifest: Manifest, n: int = 0) -> Pipeline: build = description.get("build") if build: @@ -99,9 +106,8 @@ def load_pipeline(description: Dict, index: Index, manifest: Manifest, n: int = build_id = build_pipeline and build_pipeline.id pipeline = manifest.add_pipeline(name, runner, build_id) - for s in description.get("stages", []): - info = index.get_module_info("Stage", s["name"]) - pipeline.add_stage(info, s.get("options", {})) + for stage in description.get("stages", []): + load_stage(stage, index, pipeline) return pipeline