From aaf61ce9fc79dbcf19bade91db4e4426dba65b26 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 8 Dec 2020 18:13:33 +0100 Subject: [PATCH] formats: extract manifest loading into module Extract the code that loads a pipeline from a pipeline description, i.e. a manifest, into a new module inside a new 'formats' package. The idea is to have different descriptions, i.e. different formats, for the same internal representation. This allows changing the internal representation, i.e. data structures, but still having the same external description. Later a new description might be added that better matches the new internal representation. --- osbuild/__init__.py | 4 ++-- osbuild/formats/__init__.py | 3 +++ osbuild/formats/v1.py | 32 ++++++++++++++++++++++++++++++++ osbuild/pipeline.py | 29 ----------------------------- 4 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 osbuild/formats/__init__.py create mode 100644 osbuild/formats/v1.py diff --git a/osbuild/__init__.py b/osbuild/__init__.py index fed324ef..50fc83c1 100644 --- a/osbuild/__init__.py +++ b/osbuild/__init__.py @@ -8,8 +8,8 @@ The utility module `osbuild.util` provides access to common functionality independent of osbuild but used across the osbuild codebase. """ - -from .pipeline import Assembler, load, load_build, Pipeline, Stage +from .formats.v1 import load, load_build +from .pipeline import Assembler, Pipeline, Stage __all__ = [ diff --git a/osbuild/formats/__init__.py b/osbuild/formats/__init__.py new file mode 100644 index 00000000..8eeb5e19 --- /dev/null +++ b/osbuild/formats/__init__.py @@ -0,0 +1,3 @@ +""" +Concrete representation of manifest descriptions +""" diff --git a/osbuild/formats/v1.py b/osbuild/formats/v1.py new file mode 100644 index 00000000..ce7fd6b9 --- /dev/null +++ b/osbuild/formats/v1.py @@ -0,0 +1,32 @@ +# Version 1 of the manifest description + +from ..pipeline import Pipeline, detect_host_runner + + +def load_build(description, sources_options): + pipeline = description.get("pipeline") + if pipeline: + build_pipeline = load(pipeline, sources_options) + else: + build_pipeline = None + + return build_pipeline, description["runner"] + + +def load(description, sources_options): + build = description.get("build") + if build: + build_pipeline, runner = load_build(build, sources_options) + else: + build_pipeline, runner = None, detect_host_runner() + + pipeline = Pipeline(runner, build_pipeline) + + for s in description.get("stages", []): + pipeline.add_stage(s["name"], sources_options, s.get("options", {})) + + a = description.get("assembler") + if a: + pipeline.set_assembler(a["name"], a.get("options", {})) + + return pipeline diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 9773fc1b..87fdd47e 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -363,32 +363,3 @@ def detect_host_runner(): """Use os-release(5) to detect the runner for the host""" osname = osrelease.describe_os(*osrelease.DEFAULT_PATHS) return "org.osbuild." + osname - - -def load_build(description, sources_options): - pipeline = description.get("pipeline") - if pipeline: - build_pipeline = load(pipeline, sources_options) - else: - build_pipeline = None - - return build_pipeline, description["runner"] - - -def load(description, sources_options): - build = description.get("build") - if build: - build_pipeline, runner = load_build(build, sources_options) - else: - build_pipeline, runner = None, detect_host_runner() - - pipeline = Pipeline(runner, build_pipeline) - - for s in description.get("stages", []): - pipeline.add_stage(s["name"], sources_options, s.get("options", {})) - - a = description.get("assembler") - if a: - pipeline.set_assembler(a["name"], a.get("options", {})) - - return pipeline