forked from ostreedev/ostree-releng-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-current-version
executable file
·35 lines (27 loc) · 1 KB
/
print-current-version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
#
# Print the value of `ostree.version` from the currently booted commit.
#
# Copyright 2015 Colin Walters <[email protected]>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
from __future__ import print_function
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())