debian-forge/osbuild/sources.py
Christian Kellner c902a7a754 sources: port to host services
Port sources to also use the host services infrastructure that is
used by inputs, devices and mounts. Sources are a bit different
from the other services that they don't run for the duration of
the stage but are run before anything is built. By using the same
infrastructure we re-use the process management and inter process
communcation. Additionally, this will forward all messages from
sources to the existing monitoring framework.
Adapt all existing sources and tests.
2021-09-22 00:00:20 +02:00

53 lines
1.3 KiB
Python

import abc
import os
from . import host
from .objectstore import ObjectStore
from .util.types import PathLike
class Source:
"""
A single source with is corresponding options.
"""
def __init__(self, info, items, options) -> None:
self.info = info
self.items = items or {}
self.options = options
def download(self, mgr: host.ServiceManager, store: ObjectStore, libdir: PathLike):
source = self.info.name
cache = os.path.join(store.store, "sources")
args = {
"items": self.items,
"options": self.options,
"cache": cache,
"output": None,
"checksums": [],
"libdir": os.fspath(libdir)
}
client = mgr.start(f"source/{source}", self.info.path)
reply = client.call("download", args)
return reply
class SourceService(host.Service):
"""Source host service"""
@abc.abstractmethod
def download(self, items, cache, options):
pass
def dispatch(self, method: str, args, _fds):
if method == "download":
r = self.download(args["items"],
args["cache"],
args["options"])
return r, None
raise host.ProtocolError("Unknown method")