mirror of
https://github.com/ostreedev/ostree-releng-scripts.git
synced 2026-02-05 09:45:02 +01:00
38 lines
1.0 KiB
Python
Executable File
38 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# Print the value of `ostree.version` from the currently booted commit.
|
|
#
|
|
# Copyright 2015 Colin Walters <walters@verbum.org>
|
|
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
|
|
|
|
from __future__ import print_function
|
|
|
|
import gi
|
|
gi.require_version('OSTree', '1.0')
|
|
from gi.repository import GLib, Gio, OSTree
|
|
import argparse
|
|
|
|
def fatal(msg):
|
|
print >>sys.stderr, msg
|
|
sys.exit(1)
|
|
|
|
parser = argparse.ArgumentParser(prog="print-current-version")
|
|
arg = parser.parse_args()
|
|
|
|
sysroot = OSTree.Sysroot.new_default()
|
|
sysroot.load(None)
|
|
|
|
_,repo = sysroot.get_repo(None)
|
|
|
|
deployment = sysroot.get_booted_deployment()
|
|
if deployment is None:
|
|
fatal("Not in a booted OSTree system!")
|
|
|
|
commitid = deployment.get_csum()
|
|
_,commit = repo.load_variant(OSTree.ObjectType.COMMIT, commitid)
|
|
meta = commit.get_child_value(0)
|
|
version = meta.lookup_value('version', GLib.VariantType.new('s'))
|
|
if version is None:
|
|
fatal("Currently booted commit {0} does not have a version".format(commitid))
|
|
print(version.get_string())
|