Created
June 14, 2022 21:28
-
-
Save nanonyme/bdd590cbcbd7db442a659db28f816c38 to your computer and use it in GitHub Desktop.
Parse ostree summary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!/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