Skip to content

Instantly share code, notes, and snippets.

@nanonyme
Created June 14, 2022 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanonyme/bdd590cbcbd7db442a659db28f816c38 to your computer and use it in GitHub Desktop.
Save nanonyme/bdd590cbcbd7db442a659db28f816c38 to your computer and use it in GitHub Desktop.
Parse ostree summary
!/usr/bin/python3
import subprocess
import enum
class State(enum.Enum):
ignore = enum.auto()
section = enum.auto()
commit = enum.auto()
output = subprocess.check_output(
["ostree", "remote", "summary", "fedora"],
text=True,
)
state = State.ignore
commits = {}
for line in output.splitlines():
if line.startswith("*"):
key = line[1:].strip()
state = State.section
elif not line.strip():
state = State.ignore
elif state == State.section:
if line.strip().startswith("Latest Commit"):
state = State.commit
elif state == state.commit:
commits[key] = line.strip()
state = State.ignore
for key, value in commits.items():
print (key, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment