mirror of
https://github.com/ostreedev/ostree-releng-scripts.git
synced 2026-02-05 09:45:02 +01:00
97 lines
3.7 KiB
Python
Executable File
97 lines
3.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# Ensure that the specified refs match a releases.yml file
|
|
# that is stored in git.
|
|
#
|
|
# Copyright 2016 Colin Walters <walters@verbum.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2 of the License, or (at your option) any later version.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import gi
|
|
gi.require_version('OSTree', '1.0')
|
|
from gi.repository import GLib, Gio, OSTree
|
|
import argparse
|
|
import yaml
|
|
import sys
|
|
|
|
def fatal(msg):
|
|
print >>sys.stderr, msg
|
|
sys.exit(1)
|
|
|
|
parser = argparse.ArgumentParser(prog=sys.argv[0])
|
|
parser.add_argument("--autocreate", help="Create refs that don't already exist",
|
|
action='store_true')
|
|
parser.add_argument("--ignore-no-previous-promotion", help="Releases file",
|
|
action='store_true')
|
|
parser.add_argument("--repo", help="Repo path",
|
|
action='store', required=True)
|
|
parser.add_argument("--releases", help="Releases file",
|
|
action='store', required=True)
|
|
|
|
args = parser.parse_args()
|
|
|
|
r = OSTree.Repo.new(Gio.File.new_for_path(args.repo))
|
|
r.open(None)
|
|
|
|
releasedata = yaml.load(open(args.releases))
|
|
baseref = releasedata['baseref']
|
|
changed = False
|
|
for (name,newcommit) in releasedata['releases'].iteritems():
|
|
ref = baseref + name
|
|
[_, current] = r.resolve_rev(ref, True)
|
|
if current is None:
|
|
if args.autocreate:
|
|
print("Creating new ref {}.".format(ref))
|
|
newparent = None
|
|
else:
|
|
fatal("error: Ref {} does not currently exist".format(ref))
|
|
else:
|
|
_,currentcommitdata,_ = r.load_commit(current)
|
|
currentcommitmeta = currentcommitdata.get_child_value(0)
|
|
currentpromotedv = currentcommitmeta.lookup_value("promotion-of", GLib.VariantType.new("s"))
|
|
if currentpromotedv is None:
|
|
msg = "Missing promotion-of metadata key in {}".format(current)
|
|
if args.ignore_no_previous_promotion:
|
|
print("warning: " + msg)
|
|
currentpromoted = '(missing)'
|
|
newparent = None
|
|
else:
|
|
fatal(msg)
|
|
else:
|
|
currentpromoted = currentpromotedv.get_string()
|
|
newparent = current
|
|
if currentpromoted == newcommit:
|
|
print("No changes in {} = {}, promoted from {}".format(ref, current, currentpromoted))
|
|
continue
|
|
print("Previously: {} = {}, promoted from {}".format(ref, current, currentpromoted))
|
|
_,newcommitdata,_ = r.load_commit(newcommit)
|
|
_,newcommitroot,_ = r.read_commit(newcommit, None)
|
|
newcommitmeta = newcommitdata.get_child_value(0)
|
|
versionv = newcommitmeta.lookup_value("version", GLib.VariantType.new("s"))
|
|
if versionv:
|
|
version = versionv.get_string()
|
|
|
|
promotedmetadict = GLib.VariantDict.new(newcommitmeta)
|
|
promotedmetadict.insert_value("promotion-of", GLib.Variant.new_string(newcommit))
|
|
body = 'PromotionOf: {}'.format(newcommit)
|
|
|
|
mtree = OSTree.MutableTree.new()
|
|
_,promotedcommit = r.write_commit(newparent, '', body, promotedmetadict.end(), newcommitroot, None)
|
|
r.set_ref_immediate(None, ref, promotedcommit)
|
|
if version:
|
|
print "Promoted commit {} (version {}) => {}".format(newcommit, version, promotedcommit)
|
|
changed = True
|
|
if not changed:
|
|
print("Processed {}: No changes".format(args.releases))
|