From aa19a1c4c0d5fa7a6a1d81cee179dbfee980b6db Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 28 Apr 2021 09:16:36 +0000 Subject: [PATCH] sources: remove server and get method The usage of the `sources.SourcesServer` and `sources.get` have been removed from `Stage.run`, which was the only usage throughout osbuild and thus it is not needed anymore and can be removed. --- osbuild/sources.py | 54 +--------------------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/osbuild/sources.py b/osbuild/sources.py index 384180af..5015eb58 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -3,9 +3,7 @@ import importlib import json import subprocess -from . import api from .objectstore import ObjectStore -from .util import jsoncomm from .util.types import PathLike @@ -13,6 +11,7 @@ class Source: """ A single source with is corresponding options. """ + def __init__(self, info, items, options) -> None: self.info = info self.items = items or {} @@ -56,54 +55,3 @@ class Source: if r.returncode != 0: raise RuntimeError(f"{source}: error {r.returncode}") - - -class SourcesServer(api.BaseAPI): - - endpoint = "sources" - - def __init__(self, libdir, options, cache, output, *, socket_address=None): - super().__init__(socket_address) - self.libdir = libdir - self.cache = cache - self.output = output - self.options = options or {} - - def _run_source(self, source, checksums): - msg = { - "items": {}, - "options": self.options.get(source, {}), - "cache": self.cache, - "output": f"{self.output}/{source}", - "checksums": checksums, - "libdir": self.libdir - } - - r = subprocess.run( - [f"{self.libdir}/sources/{source}"], - input=json.dumps(msg), - stdout=subprocess.PIPE, - encoding="utf-8", - check=False) - - try: - return json.loads(r.stdout) - except ValueError: - return {"error": f"source returned malformed json: {r.stdout}"} - - def _message(self, msg, fds, sock): - reply = self._run_source(msg["source"], msg["checksums"]) - sock.send(reply) - - -def get(source, checksums, api_path="/run/osbuild/api/sources"): - with jsoncomm.Socket.new_client(api_path) as client: - msg = { - "source": source, - "checksums": checksums - } - client.send(msg) - reply, _, _ = client.recv() - if "error" in reply: - raise RuntimeError(f"{source}: " + reply["error"]) - return reply