mpp/import: support for format version 2
Add support for foramt version 2. This is slightly easier than version 1, since there is no recursion. In addition to the path of the manifest to import the pipeline from, the pipeline identifier needs to be specified. Source merging is also different since in format version two, there is a generic "items" key, which means we can merge other sources than "org.osbuild.files".
This commit is contained in:
parent
a38a3fa502
commit
49e1800503
1 changed files with 79 additions and 1 deletions
|
|
@ -9,7 +9,9 @@ This tool imports a pipeline from another file and inserts it into a manifest
|
|||
at the same position the import instruction is located. Sources from the
|
||||
imported manifest are merged with the existing sources.
|
||||
|
||||
The parameters for this pre-processor look like this:
|
||||
Manifest format version "1" and "2" are supported.
|
||||
|
||||
The parameters for this pre-processor for format version "1" look like this:
|
||||
|
||||
```
|
||||
...
|
||||
|
|
@ -18,6 +20,17 @@ The parameters for this pre-processor look like this:
|
|||
}
|
||||
...
|
||||
```
|
||||
|
||||
The parameters for this pre-processor for format version "2" look like this:
|
||||
|
||||
```
|
||||
...
|
||||
"mpp-import-pipeline": {
|
||||
"path": "./manifest.json",
|
||||
"id:" "build"
|
||||
}
|
||||
...
|
||||
```
|
||||
"""
|
||||
|
||||
import argparse
|
||||
|
|
@ -112,6 +125,69 @@ def _manifest_import_v1(state, src):
|
|||
_manifest_process_v1(state, todo)
|
||||
|
||||
|
||||
def _manifest_parse_v2(state, manifest):
|
||||
todo = []
|
||||
|
||||
pipelines = manifest.get("pipelines", [])
|
||||
|
||||
for pipeline in pipelines:
|
||||
current = pipeline.get("mpp-import-pipeline")
|
||||
if current:
|
||||
todo.append(pipeline)
|
||||
|
||||
state.manifest = manifest
|
||||
state.manifest_todo = todo
|
||||
|
||||
|
||||
def _manifest_process_v2(state, todo):
|
||||
manifest = state.manifest
|
||||
sources = _manifest_enter(manifest, "sources", {})
|
||||
|
||||
mpp = todo["mpp-import-pipeline"]
|
||||
path = mpp["path"]
|
||||
|
||||
with open(os.path.join(state.cwd, path), "r") as f:
|
||||
imp = json.load(f)
|
||||
|
||||
# merge the sources
|
||||
for source, desc in imp.get("sources", {}).items():
|
||||
target = sources.get(source)
|
||||
if not target:
|
||||
# new source, just copy everything
|
||||
sources[source] = desc
|
||||
continue
|
||||
|
||||
if desc.get("options"):
|
||||
options = _manifest_enter(target, "options", {})
|
||||
options.update(desc["options"])
|
||||
|
||||
items = _manifest_enter(target, "items", {})
|
||||
items.update(desc.get("items", {}))
|
||||
|
||||
# get the pipeline
|
||||
pipelines = imp.get("pipelines", [])
|
||||
|
||||
pid = mpp["id"]
|
||||
|
||||
target = None
|
||||
for pipeline in pipelines:
|
||||
if pipeline["name"] == pid:
|
||||
target = pipeline
|
||||
break
|
||||
|
||||
if not target:
|
||||
raise ValueError(f"Pipeline '{pid}' not found in {path}")
|
||||
|
||||
todo.update(target)
|
||||
del(todo["mpp-import-pipeline"])
|
||||
|
||||
|
||||
def _manifest_import_v2(state, src):
|
||||
_manifest_parse_v2(state, src)
|
||||
for todo in state.manifest_todo:
|
||||
_manifest_process_v2(state, todo)
|
||||
|
||||
|
||||
def _main_args(argv):
|
||||
parser = argparse.ArgumentParser(description="Generate Test Manifests")
|
||||
|
||||
|
|
@ -138,6 +214,8 @@ def _main_process(state):
|
|||
version = src.get("version", "1")
|
||||
if version == "1":
|
||||
_manifest_import_v1(state, src)
|
||||
elif version == "2":
|
||||
_manifest_import_v2(state, src)
|
||||
else:
|
||||
return 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue