ostree: show commit metadata

This new API call allows one to check (among other things) if a commit
exists in a repo. It'll throw a RuntimeException if the commit is
missing.
This commit is contained in:
Thomas Lavocat 2022-05-10 15:30:09 +02:00 committed by Thomas Lavocat
parent 1de74ce2c9
commit 441e67a6f6
3 changed files with 27 additions and 1 deletions

View file

@ -129,6 +129,24 @@ def rev_parse(repo: PathLike, ref: str) -> str:
return msg
def show(repo: PathLike, checksum: str) -> str:
"""Show the metada of an OSTree object pointed by `checksum` in the repository at `repo`"""
repo = os.fspath(repo)
r = subprocess.run(["ostree", "show", f"--repo={repo}", checksum],
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False)
msg = r.stdout.strip()
if r.returncode != 0:
raise RuntimeError(msg)
return msg
def deployment_path(root: PathLike, osname: str, ref: str, serial: int):
"""Return the path to a deployment given the parameters"""