manifest: use newly introduced Source class

Add a new `add_source` method that will add an individual `Source`
to a `Manifest` give its `ModuleInfo` and options. The dictionary
of source options in the manifest is replaced with a list of such
`Sources` and `add_source` will append to it. Adap the version 1
format code to use `add_source` and reconstruct the source options
from the list of source on `describe`.
Remove the `sources_options` constructor parameter for `Manifest`
and adapt all the source base for this.
This commit is contained in:
Christian Kellner 2021-01-22 18:39:19 +00:00
parent 8423da368a
commit 12c9173faf
3 changed files with 24 additions and 6 deletions

View file

@ -41,7 +41,11 @@ def describe(manifest: Manifest, *, with_id=False) -> Dict:
description = {"pipeline": pipeline}
if manifest.sources:
description["sources"] = manifest.sources
sources = {
s.info.name: s.options
for s in manifest.sources
}
description["sources"] = sources
return description
@ -109,7 +113,7 @@ def load(description: Dict, index: Index) -> Manifest:
pipeline = description.get("pipeline", {})
sources = description.get("sources", {})
manifest = Manifest(sources)
manifest = Manifest()
load_pipeline(pipeline, index, manifest)
@ -118,6 +122,11 @@ def load(description: Dict, index: Index) -> Manifest:
if assembler:
load_assembler(assembler, index, manifest)
# load the sources
for name, options in sources.items():
info = index.get_module_info("Source", name)
manifest.add_source(info, options)
for pipeline in manifest.pipelines.values():
for stage in pipeline.stages:
stage.sources = sources

View file

@ -3,13 +3,14 @@ import contextlib
import hashlib
import json
import os
from typing import Dict, Iterator, Optional
from typing import Dict, Iterator, List, Optional
from .api import API
from . import buildroot
from . import objectstore
from . import remoteloop
from . import sources
from .sources import Source
from .util import osrelease
@ -252,9 +253,9 @@ class Pipeline:
class Manifest:
"""Representation of a pipeline and its sources"""
def __init__(self, source_options: Dict):
def __init__(self):
self.pipelines = collections.OrderedDict()
self.sources = source_options
self.sources: List[Source] = []
def add_pipeline(self, name: str, runner: str, build: str) -> Pipeline:
pipeline = Pipeline(name, runner, build)
@ -263,9 +264,17 @@ class Manifest:
self.pipelines[name] = pipeline
return pipeline
def add_source(self, info, options: Dict) -> Source:
source = Source(info, options)
self.sources.append(source)
return source
def build(self, store, monitor, libdir, output_directory):
results = {"success": True}
for source in self.sources:
source.download(store, libdir)
for pl in self.pipelines.values():
res = pl.run(store, monitor, libdir, output_directory)
results[pl.id] = res

View file

@ -46,7 +46,7 @@ class TestDescriptions(unittest.TestCase):
info = index.get_module_info("Stage", "org.osbuild.noop")
manifest = Manifest({})
manifest = Manifest()
# each pipeline gets a noop stage with different
# options so that their ids are different