sources: generalize cache generation
Introduce a `setup` step in the workflow that is responsible of generating the cache folder. This is then used in each download method.
This commit is contained in:
parent
5337374b50
commit
34cd9ef9f0
5 changed files with 12 additions and 14 deletions
|
|
@ -54,6 +54,10 @@ class SourceService(host.Service):
|
||||||
def download(self, items, cache, options):
|
def download(self, items, cache, options):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def setup(self, cache, content_type):
|
||||||
|
self.cache = os.path.join(cache, content_type)
|
||||||
|
os.makedirs(self.cache, exist_ok=True)
|
||||||
|
|
||||||
def dispatch(self, method: str, args, fds):
|
def dispatch(self, method: str, args, fds):
|
||||||
if method == "download":
|
if method == "download":
|
||||||
with os.fdopen(fds.steal(0)) as f:
|
with os.fdopen(fds.steal(0)) as f:
|
||||||
|
|
|
||||||
|
|
@ -166,10 +166,8 @@ def download(items, cache):
|
||||||
class CurlSource(sources.SourceService):
|
class CurlSource(sources.SourceService):
|
||||||
|
|
||||||
def download(self, items, cache, _options):
|
def download(self, items, cache, _options):
|
||||||
cache = os.path.join(cache, "org.osbuild.files")
|
self.setup(cache, "org.osbuild.files")
|
||||||
os.makedirs(cache, exist_ok=True)
|
download(items, self.cache)
|
||||||
|
|
||||||
download(items, cache)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
|
|
@ -82,11 +82,9 @@ def process(items: Dict, cache: str, tmpdir):
|
||||||
class InlineSource(sources.SourceService):
|
class InlineSource(sources.SourceService):
|
||||||
|
|
||||||
def download(self, items, cache, _options):
|
def download(self, items, cache, _options):
|
||||||
cache = os.path.join(cache, "org.osbuild.files")
|
self.setup(cache, "org.osbuild.files")
|
||||||
os.makedirs(cache, exist_ok=True)
|
|
||||||
|
|
||||||
with tempfile.TemporaryDirectory(prefix=".unverified-", dir=cache) as tmpdir:
|
with tempfile.TemporaryDirectory(prefix=".unverified-", dir=cache) as tmpdir:
|
||||||
process(items, cache, tmpdir)
|
process(items, self.cache, tmpdir)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,9 @@ def download(items, cache):
|
||||||
class OSTreeSource(sources.SourceService):
|
class OSTreeSource(sources.SourceService):
|
||||||
|
|
||||||
def download(self, items, cache, _options):
|
def download(self, items, cache, _options):
|
||||||
cache = os.path.join(cache, "org.osbuild.ostree")
|
self.setup(cache, "org.osbuild.ostree")
|
||||||
os.makedirs(cache, exist_ok=True)
|
|
||||||
|
|
||||||
download(items, cache)
|
download(items, self.cache)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
|
|
@ -119,10 +119,9 @@ def download(items, cache):
|
||||||
class SkopeoSource(sources.SourceService):
|
class SkopeoSource(sources.SourceService):
|
||||||
|
|
||||||
def download(self, items, cache, _options):
|
def download(self, items, cache, _options):
|
||||||
cache = os.path.join(cache, "org.osbuild.containers")
|
self.setup(cache, "org.osbuild.containers")
|
||||||
os.makedirs(cache, exist_ok=True)
|
|
||||||
|
|
||||||
download(items, cache)
|
download(items, self.cache)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue