meta: ModuleInfo support for Sources

Add support for querying information about sources: add the mapping
from name to directory and accept "Source" as a module name. Adapt
the ModuleInfo schema property to handle the different styles for
stage-like schemata as well as sources now.
This commit is contained in:
Christian Kellner 2020-05-29 15:51:49 +02:00 committed by David Rheinsberg
parent f967bf7164
commit bdae02a6b5

View file

@ -1,10 +1,10 @@
"""Introspection and validation for osbuild """Introspection and validation for osbuild
This module contains utilities that help to introspect parts This module contains utilities that help to introspect parts
that constitute the inner parts of osbuild, i.e. its stages that constitute the inner parts of osbuild, i.e. its stages,
and assembler (which is also considered a type of stage in assemblers and sources. Additionally, it provides classes and
this context). Additionally, it provides classes and functions functions to do schema validation of OSBuild manifests and
to do schema validation of OSBuild manifests and stage options. module options.
A central `Index` class can be used to obtain stage and schema A central `Index` class can be used to obtain stage and schema
information. For the former a `ModuleInfo` class is returned via information. For the former a `ModuleInfo` class is returned via
@ -264,7 +264,7 @@ class ModuleInfo:
"""Meta information about a stage """Meta information about a stage
Represents the information about a osbuild pipeline Represents the information about a osbuild pipeline
modules, like a stage or an assembler. modules, like a stage, assembler or source.
Contains the short description (`desc`), a longer Contains the short description (`desc`), a longer
description (`info`) and the JSON schema of valid options description (`info`) and the JSON schema of valid options
(`opts`). The `validate` method will check a the options (`opts`). The `validate` method will check a the options
@ -288,15 +288,19 @@ class ModuleInfo:
"title": f"Pipeline {self.type}", "title": f"Pipeline {self.type}",
"type": "object", "type": "object",
"additionalProperties": False, "additionalProperties": False,
"properties": { }
if self.type in ("Stage", "Assembler"):
schema["properties"] = {
"name": {"type": "string"}, "name": {"type": "string"},
"options": { "options": {
"type": "object", "type": "object",
**self.opts **self.opts
} }
}, }
"required": ["name"] schema["required"] = ["name"]
} else:
schema.update(self.opts)
# if there are is a definitions node, it needs to be at # if there are is a definitions node, it needs to be at
# the top level schema node, since the schema inside the # the top level schema node, since the schema inside the
@ -355,7 +359,8 @@ class ModuleInfo:
def module_class_to_directory(klass: str) -> str: def module_class_to_directory(klass: str) -> str:
mapping = { mapping = {
"Stage": "stages", "Stage": "stages",
"Assembler": "assemblers" "Assembler": "assemblers",
"Source": "sources"
} }
return mapping.get(klass) return mapping.get(klass)
@ -413,7 +418,7 @@ class Index:
with contextlib.suppress(FileNotFoundError): with contextlib.suppress(FileNotFoundError):
with open(path, "r") as f: with open(path, "r") as f:
schema = json.load(f) schema = json.load(f)
elif klass in ["Stage", "Assembler"]: elif klass in ["Stage", "Assembler", "Source"]:
info = self.get_module_info(klass, name) info = self.get_module_info(klass, name)
if info: if info:
schema = info.schema schema = info.schema