debian-forge/stages/io.weldr.dnf
Lars Karlitski 34d620feea stages/dnf: don't use configparser to write dnf.conf
configparser writes strings with quotes and lists with enclosing
brackets, both of which may not appear in dnf.conf.

dnf.conf(5) defines the format loosely.
2019-07-08 14:22:25 +02:00

64 lines
1.8 KiB
Python
Executable file

#!/usr/bin/python3
import json
import os
import subprocess
import sys
def main(tree, options):
repos = options["repos"]
packages = options["packages"]
releasever = options["releasever"]
operation = options.get("operation", "install")
verbosity = options.get("verbosity", "info")
with open("/tmp/dnf.conf", "w") as conf:
for repoid, repo in repos.items():
conf.write(f"[{repoid}]\n")
for key, value in repo.items():
if type(value) == str:
s = value
elif type(value) == list:
s = " ".join(value)
elif type(value) == bool:
s = "1" if value else "0"
elif type(value) == int:
s = str(value)
else:
print(f"unkown type for `{key}`: {value} ({type(value)})")
return 1
conf.write(f"{key}={s}\n")
script = f"""
set -e
mkdir -p {tree}/dev {tree}/sys {tree}/proc
mount -t devtmpfs none {tree}/dev
mount -t sysfs none {tree}/sys
mount -t proc none {tree}/proc
"""
returncode = subprocess.run(["/bin/sh", "-c", script]).returncode
if returncode != 0:
print(f"setting up API VFS in target tree failed: {returncode}")
return returncode
cmd = [
"dnf", "-yv",
"--installroot", tree,
"--setopt", "reposdir=",
"--setopt", "install_weak_deps=False",
"--releasever", releasever,
"--rpmverbosity", verbosity,
"--config", "/tmp/dnf.conf",
operation
] + packages
print(" ".join(cmd), flush=True)
return subprocess.run(cmd).returncode
if __name__ == '__main__':
args = json.load(sys.stdin)
r = main(args["tree"], args["options"])
sys.exit(r)