stage/dnf.module-config: remove path

Instead of passing in the path we name the file according to the module
name. Path can be reintroduced later if absolutely necessary.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
This commit is contained in:
Simon de Vlieger 2025-01-22 09:37:03 +01:00 committed by Ondřej Budai
parent b4299b497e
commit d92be415f8
3 changed files with 10 additions and 14 deletions

View file

@ -1,23 +1,26 @@
#!/usr/bin/python3
import configparser
import os
import pathlib
import sys
import osbuild.api
def main(tree, options):
path = options["path"]
conf = options["conf"]
name = conf["name"]
inip = configparser.ConfigParser()
inip[conf["name"]] = conf
inip[name] = conf
# we need to handle enabled profiles as a string as configparser
# would normally write [a, b]
inip[conf["name"]]["profiles"] = ", ".join(conf["profiles"])
inip[name]["profiles"] = ", ".join(conf["profiles"])
with open(os.path.join(tree, path), "w", encoding="utf-8") as file:
path = pathlib.Path(tree) / "etc/dnf/modules.d" / f"{name}.conf"
path.parent.mkdir(parents=True, exist_ok=True)
with open(path, "w", encoding="utf-8") as file:
inip.write(file)
return 0

View file

@ -9,10 +9,6 @@
"additionalProperties": false,
"description": "DNF configuration.",
"properties": {
"path": {
"type": "string",
"description": "Path to write the module configuration to."
},
"conf": {
"additionalProperties": false,
"type": "object",

View file

@ -10,7 +10,6 @@ STAGE_NAME = "org.osbuild.dnf.module-config"
@pytest.mark.parametrize("test_data,expected_err", [
# bad
({"conf": "must-be-object"}, "'must-be-object' is not of type 'object'"),
({"path": {}}, "{} is not of type 'string'"),
# good
({
"conf":
@ -40,13 +39,11 @@ def test_dnf_module_config_schema_validation(stage_schema, test_data, expected_e
def test_dnf_module_config_writes_file(tmp_path, stage_module):
treepath = tmp_path / "tree"
confpath = "etc/dnf/modules.d/module.conf"
confpath = "etc/dnf/modules.d/some-module.conf"
fullpath = treepath / confpath
fullpath.parent.mkdir(parents=True, exist_ok=True)
options = {
"path": confpath,
"conf": {
"name": "some-module",
"stream": "some-stream",