diff --git a/osbuild/sources.py b/osbuild/sources.py index 20235095..2903fae9 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -3,6 +3,7 @@ import contextlib import os import json import tempfile +from abc import abstractmethod from . import host from .objectstore import ObjectStore @@ -54,12 +55,19 @@ class SourceService(host.Service): def download(self, items, cache, options): pass - def setup(self, cache, content_type): - self.cache = os.path.join(cache, content_type) + @property + @classmethod + @abstractmethod + def content_type(cls): + """The content type of the source.""" + + def setup(self, args): + self.cache = os.path.join(args["cache"], self.content_type) os.makedirs(self.cache, exist_ok=True) 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) diff --git a/sources/org.osbuild.curl b/sources/org.osbuild.curl index a0953bfa..82f88683 100755 --- a/sources/org.osbuild.curl +++ b/sources/org.osbuild.curl @@ -165,8 +165,9 @@ def download(items, cache): class CurlSource(sources.SourceService): - def download(self, items, cache, _options): - self.setup(cache, "org.osbuild.files") + content_type = "org.osbuild.files" + + def download(self, items, _cache, _options): download(items, self.cache) diff --git a/sources/org.osbuild.inline b/sources/org.osbuild.inline index a2c45c2f..2939de82 100755 --- a/sources/org.osbuild.inline +++ b/sources/org.osbuild.inline @@ -81,9 +81,10 @@ def process(items: Dict, cache: str, tmpdir): class InlineSource(sources.SourceService): - def download(self, items, cache, _options): - self.setup(cache, "org.osbuild.files") - with tempfile.TemporaryDirectory(prefix=".unverified-", dir=cache) as tmpdir: + content_type = "org.osbuild.files" + + def download(self, items, _cache, _options): + 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 836ff6a1..024d11f5 100755 --- a/sources/org.osbuild.ostree +++ b/sources/org.osbuild.ostree @@ -114,8 +114,9 @@ def download(items, cache): class OSTreeSource(sources.SourceService): - def download(self, items, cache, _options): - self.setup(cache, "org.osbuild.ostree") + content_type = "org.osbuild.ostree" + + def download(self, items, _cache, _options): download(items, self.cache) diff --git a/sources/org.osbuild.skopeo b/sources/org.osbuild.skopeo index 1146b0a6..8a3b1c07 100755 --- a/sources/org.osbuild.skopeo +++ b/sources/org.osbuild.skopeo @@ -118,8 +118,9 @@ def download(items, cache): class SkopeoSource(sources.SourceService): - def download(self, items, cache, _options): - self.setup(cache, "org.osbuild.containers") + content_type = "org.osbuild.containers" + + def download(self, items, _cache, _options): download(items, self.cache)