Skip to content

Commit

Permalink
external: split out the depsolve external
Browse files Browse the repository at this point in the history
This splits out the depsolve external along the lines of the previously
written partition externals. Using the external is now a two-step
process where you run one external in a define and then use its output
to generate stages and sources.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
  • Loading branch information
supakeen committed Sep 12, 2024
1 parent 43085dd commit 5af9a2b
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 123 deletions.
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ dependencies = [

[project.scripts]
otk = "otk.command:root"
otk_external_osbuild = "otk_external_osbuild.command:root"
osbuild-depsolve-dnf4 = "otk_external_osbuild.command.depsolve_dnf4:root"
osbuild-depsolve-dnf4-gen-rpm-stage = "otk_external_osbuild.command.depsolve_dnf4_gen_rpm_stage:root"
osbuild-depsolve-dnf4-gen-curl-source = "otk_external_osbuild.command.depsolve_dnf4_gen_curl_source:root"

[project.optional-dependencies]
dev = [
Expand Down
122 changes: 0 additions & 122 deletions src/otk_external_osbuild/command.py

This file was deleted.

Empty file.
66 changes: 66 additions & 0 deletions src/otk_external_osbuild/command/depsolve_dnf4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""`otk-osbuild` is the [otk](https://github.com/osbuild/otk) external to work
with [osbuild](https://github.com/osbuild/osbuild) manifests.
THIS FILE IS VERY, VERY PROOF OF CONCEPT AND NEEDS TO BE CLEANED UP"""

import json
import subprocess
import sys


def root():
data = json.loads(sys.stdin.read())

tree = data["tree"]

request = {
"command": "depsolve",
"arch": tree["architecture"],
"module_platform_id": "platform:" + tree["module_platform_id"],
"releasever": tree["releasever"],
"cachedir": "/tmp",
"arguments": {
"root_dir": "/tmp",
"repos": tree["repositories"],
"transactions": [
{
"package-specs": tree["packages"]["include"],
"exclude-specs": tree["packages"].get("exclude", []),
},
],
},
}

process = subprocess.run(
["/usr/libexec/osbuild-depsolve-dnf"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
input=json.dumps(request),
encoding="utf8",
check=False,
)

if process.returncode != 0:
# TODO: fix this
raise RuntimeError(
process.stderr
) # pylint: disable=broad-exception-raised

results = json.loads(process.stdout)
packages = results.get("packages", [])

sys.stdout.write(
json.dumps(
{
"tree": packages,
},
),
)


def main():
root()


if __name__ == "__main__":
main()
36 changes: 36 additions & 0 deletions src/otk_external_osbuild/command/depsolve_dnf4_gen_curl_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""`otk-osbuild` is the [otk](https://github.com/osbuild/otk) external to work
with [osbuild](https://github.com/osbuild/osbuild) manifests.
THIS FILE IS VERY, VERY PROOF OF CONCEPT AND NEEDS TO BE CLEANED UP"""

import itertools
import json
import sys


def root():
data = json.load(sys.stdin)
tree = data["tree"]

sources = {"org.osbuild.curl": {"items": {}}}

for package in itertools.chain.from_iterable(tree["packages"]):
sources["org.osbuild.curl"]["items"][package["checksum"]] = {
"url": package["remote_location"],
}

sys.stdout.write(
json.dumps(
{
"tree": sources,
}
)
)


def main():
root()


if __name__ == "__main__":
main()
45 changes: 45 additions & 0 deletions src/otk_external_osbuild/command/depsolve_dnf4_gen_rpm_stage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""`otk-osbuild` is the [otk](https://github.com/osbuild/otk) external to work
with [osbuild](https://github.com/osbuild/osbuild) manifests.
THIS FILE IS VERY, VERY PROOF OF CONCEPT AND NEEDS TO BE CLEANED UP"""

import json
import sys


def root():
data = json.load(sys.stdin)
tree = data["tree"]

sys.stdout.write(
json.dumps(
{
"tree": {
"type": "org.osbuild.rpm",
"inputs": {
"origin": "org.osbuild.source",
"references": [
{
"id": package["checksum"],
"options": {
"metadata": {"rpm.check_gpg": True}
},
}
for package in tree["packages"]
],
},
"options": {
"gpgkeys": tree["gpgkeys"],
},
}
}
)
)


def main():
root()


if __name__ == "__main__":
main()

0 comments on commit 5af9a2b

Please sign in to comment.