utils/ostree: add rev_parse helper function
Add a simple helper function that wraps `ostree rev-parse` to make it easy to resolve an OSTree reference given a repository.
This commit is contained in:
parent
368d0a5c18
commit
dc201d45fd
1 changed files with 21 additions and 0 deletions
|
|
@ -1,11 +1,14 @@
|
|||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import typing
|
||||
|
||||
from typing import List
|
||||
|
||||
from .types import PathLike
|
||||
|
||||
|
||||
class Param:
|
||||
"""rpm-ostree Treefile parameter"""
|
||||
|
|
@ -104,3 +107,21 @@ class Treefile:
|
|||
finally:
|
||||
if name:
|
||||
os.unlink(name)
|
||||
|
||||
|
||||
def rev_parse(repo: PathLike, ref: str) -> str:
|
||||
"""Resolve an OSTree reference `ref` in the repository at `repo`"""
|
||||
|
||||
repo = os.fspath(repo)
|
||||
|
||||
r = subprocess.run(["ostree", "rev-parse", ref, f"--repo={repo}"],
|
||||
encoding="utf-8",
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False)
|
||||
|
||||
msg = r.stdout.strip()
|
||||
if r.returncode != 0:
|
||||
raise RuntimeError(msg)
|
||||
|
||||
return msg
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue