diff --git a/osbuild/sources.py b/osbuild/sources.py index 2903fae9..74fc4e6e 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -51,8 +51,13 @@ class Source: class SourceService(host.Service): """Source host service""" + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.cache = None + self.options = None + @abc.abstractmethod - def download(self, items, cache, options): + def download(self, items): pass @property @@ -61,19 +66,20 @@ class SourceService(host.Service): def content_type(cls): """The content type of the source.""" + @staticmethod + def load_items(fds): + with os.fdopen(fds.steal(0)) as f: + items = json.load(f) + return items + def setup(self, args): self.cache = os.path.join(args["cache"], self.content_type) os.makedirs(self.cache, exist_ok=True) + self.options = args["options"] def dispatch(self, method: str, args, fds): if method == "download": self.setup(args) - with os.fdopen(fds.steal(0)) as f: - items = json.load(f) - - r = self.download(items, - args["cache"], - args["options"]) - return r, None + return self.download(SourceService.load_items(fds)), None raise host.ProtocolError("Unknown method") diff --git a/sources/org.osbuild.curl b/sources/org.osbuild.curl index 82f88683..daf05510 100755 --- a/sources/org.osbuild.curl +++ b/sources/org.osbuild.curl @@ -167,7 +167,7 @@ class CurlSource(sources.SourceService): content_type = "org.osbuild.files" - def download(self, items, _cache, _options): + def download(self, items): download(items, self.cache) diff --git a/sources/org.osbuild.inline b/sources/org.osbuild.inline index 2939de82..53098d18 100755 --- a/sources/org.osbuild.inline +++ b/sources/org.osbuild.inline @@ -83,7 +83,7 @@ class InlineSource(sources.SourceService): content_type = "org.osbuild.files" - def download(self, items, _cache, _options): + def download(self, items): with tempfile.TemporaryDirectory(prefix=".unverified-", dir=self.cache) as tmpdir: process(items, self.cache, tmpdir) diff --git a/sources/org.osbuild.ostree b/sources/org.osbuild.ostree index 024d11f5..099781ba 100755 --- a/sources/org.osbuild.ostree +++ b/sources/org.osbuild.ostree @@ -116,7 +116,7 @@ class OSTreeSource(sources.SourceService): content_type = "org.osbuild.ostree" - def download(self, items, _cache, _options): + def download(self, items): download(items, self.cache) diff --git a/sources/org.osbuild.skopeo b/sources/org.osbuild.skopeo index 8a3b1c07..a61e9f65 100755 --- a/sources/org.osbuild.skopeo +++ b/sources/org.osbuild.skopeo @@ -120,7 +120,7 @@ class SkopeoSource(sources.SourceService): content_type = "org.osbuild.containers" - def download(self, items, _cache, _options): + def download(self, items): download(items, self.cache)