fa3c5aff63
Added new option '--version' to pungi-make-ostree, and this can be enabled in ostree settings with 'version'. The version string will be added as versioning metadata if this is specified. Signed-off-by: Qixiang Wan <qwan@redhat.com>
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
This module contains functions required by pungi-make-ostree.
|
|
It is expected to be runnable in Koji runroot.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
from kobo import shortcuts
|
|
import errno
|
|
|
|
|
|
def ensure_dir(path):
|
|
try:
|
|
os.makedirs(path)
|
|
except OSError as err:
|
|
if err.errno != errno.EEXIST:
|
|
raise
|
|
return path
|
|
|
|
|
|
def make_log_file(log_dir, filename):
|
|
"""Return path to log file with given name, if log_dir is set."""
|
|
if not log_dir:
|
|
return None
|
|
ensure_dir(log_dir)
|
|
return os.path.join(log_dir, '%s.log' % filename)
|
|
|
|
|
|
def init_ostree_repo(repo, log_dir=None):
|
|
"""If the ostree repo does not exist, initialize it."""
|
|
log_file = make_log_file(log_dir, 'init-ostree-repo')
|
|
if not os.path.isdir(repo) or not os.listdir(repo):
|
|
ensure_dir(repo)
|
|
shortcuts.run(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'],
|
|
show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
def make_ostree_repo(repo, config, version=None, log_dir=None):
|
|
log_file = make_log_file(log_dir, 'create-ostree-repo')
|
|
cmd = ['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
|
|
'--write-commitid-to=%s' % make_log_file(log_dir, 'commitid')]
|
|
if version:
|
|
# Add versioning metadata
|
|
cmd.append('--add-metadata-string=version=%s' % version)
|
|
cmd.append(config)
|
|
|
|
shortcuts.run(cmd, show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
def update_ostree_summary(repo, log_dir=None):
|
|
log_file = make_log_file(log_dir, 'ostree-summary')
|
|
shortcuts.run(['ostree', 'summary', '-u', '--repo=%s' % repo],
|
|
show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
def run(opts):
|
|
init_ostree_repo(opts.ostree_repo, log_dir=opts.log_dir)
|
|
make_ostree_repo(opts.ostree_repo, opts.treefile, version=opts.version, log_dir=opts.log_dir)
|
|
if opts.update_summary:
|
|
update_ostree_summary(opts.ostree_repo, log_dir=opts.log_dir)
|
|
|
|
|
|
def main(args=None):
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--log-dir',
|
|
help='where to log output')
|
|
|
|
parser.add_argument('ostree_repo', metavar='OSTREE_REPO',
|
|
help='where to put the ostree repo')
|
|
parser.add_argument('--treefile', required=True,
|
|
help='treefile for rpm-ostree')
|
|
parser.add_argument('--version',
|
|
help='version string to be added as versioning metadata')
|
|
parser.add_argument('--update-summary', action='store_true',
|
|
help='update summary metadata')
|
|
|
|
opts = parser.parse_args(args)
|
|
|
|
run(opts)
|