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.
This commit is contained in:
Christian Kellner 2020-12-08 18:13:33 +01:00 committed by Tom Gundersen
parent 40a716d3ce
commit aaf61ce9fc
4 changed files with 37 additions and 31 deletions

View file

@ -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__ = [

View file

@ -0,0 +1,3 @@
"""
Concrete representation of manifest descriptions
"""

32
osbuild/formats/v1.py Normal file
View file

@ -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

View file

@ -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