sources: introduce per-source content_type
Introduce a new class member `content_type` that specifies what type of items the source will store in the cache. Use that to generalize the setup step, which is shared across all sources.
This commit is contained in:
parent
34cd9ef9f0
commit
92fe237f24
5 changed files with 23 additions and 11 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue