osbuild/util: create pull_local function in util/ostree

This is prep for sharing this functionality with other stages than
the ostree.pull stage.
This commit is contained in:
Dusty Mabe 2023-09-29 12:40:30 -04:00 committed by Simon de Vlieger
parent 4e99e80c4a
commit c6c9454f6f
2 changed files with 14 additions and 9 deletions

View file

@ -153,6 +153,18 @@ def show(repo: PathLike, checksum: str) -> str:
return msg
def pull_local(source_repo: PathLike, target_repo: PathLike, remote: str, ref: str):
"""Run ostree-pull local to copy commits around"""
extra_args = []
if remote:
extra_args.append(f'--remote={remote}')
cli("pull-local", source_repo, ref,
*extra_args,
repo=target_repo)
def cli(*args, _input=None, **kwargs):
"""Thin wrapper for running the ostree CLI"""
args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()]

View file

@ -54,18 +54,11 @@ def main(tree, inputs, options):
source_repo, commits = ostree.parse_input_commits(inputs["commits"])
repo = options["repo"]
remote = options.get("remote")
target = os.path.join(tree, repo.lstrip("/"))
target_repo = os.path.join(tree, repo.lstrip("/"))
for commit, data in commits.items():
ref = data.get("ref", commit)
extra_args = []
if remote:
extra_args.append(f'--remote={remote}')
ostree.cli("pull-local", source_repo, ref,
*extra_args,
repo=target)
ostree.pull_local(source_repo, target_repo, remote, ref)
if __name__ == '__main__':