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:
parent
b4299b497e
commit
d92be415f8
3 changed files with 10 additions and 14 deletions
|
|
@ -1,23 +1,26 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import configparser
|
import configparser
|
||||||
import os
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import osbuild.api
|
import osbuild.api
|
||||||
|
|
||||||
|
|
||||||
def main(tree, options):
|
def main(tree, options):
|
||||||
path = options["path"]
|
|
||||||
conf = options["conf"]
|
conf = options["conf"]
|
||||||
|
name = conf["name"]
|
||||||
|
|
||||||
inip = configparser.ConfigParser()
|
inip = configparser.ConfigParser()
|
||||||
inip[conf["name"]] = conf
|
inip[name] = conf
|
||||||
|
|
||||||
# we need to handle enabled profiles as a string as configparser
|
# we need to handle enabled profiles as a string as configparser
|
||||||
# would normally write [a, b]
|
# 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)
|
inip.write(file)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"description": "DNF configuration.",
|
"description": "DNF configuration.",
|
||||||
"properties": {
|
"properties": {
|
||||||
"path": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Path to write the module configuration to."
|
|
||||||
},
|
|
||||||
"conf": {
|
"conf": {
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ STAGE_NAME = "org.osbuild.dnf.module-config"
|
||||||
@pytest.mark.parametrize("test_data,expected_err", [
|
@pytest.mark.parametrize("test_data,expected_err", [
|
||||||
# bad
|
# bad
|
||||||
({"conf": "must-be-object"}, "'must-be-object' is not of type 'object'"),
|
({"conf": "must-be-object"}, "'must-be-object' is not of type 'object'"),
|
||||||
({"path": {}}, "{} is not of type 'string'"),
|
|
||||||
# good
|
# good
|
||||||
({
|
({
|
||||||
"conf":
|
"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):
|
def test_dnf_module_config_writes_file(tmp_path, stage_module):
|
||||||
treepath = tmp_path / "tree"
|
treepath = tmp_path / "tree"
|
||||||
confpath = "etc/dnf/modules.d/module.conf"
|
confpath = "etc/dnf/modules.d/some-module.conf"
|
||||||
|
|
||||||
fullpath = treepath / confpath
|
fullpath = treepath / confpath
|
||||||
|
|
||||||
fullpath.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
"path": confpath,
|
|
||||||
"conf": {
|
"conf": {
|
||||||
"name": "some-module",
|
"name": "some-module",
|
||||||
"stream": "some-stream",
|
"stream": "some-stream",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue