sources: tidy the download method
Only the "items to download" need to be passed as parameters. The rest is unpacked as attributes during the Setup step of the workflow.
This commit is contained in:
parent
92fe237f24
commit
128845da3c
5 changed files with 18 additions and 12 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue