From be117edee49d43f9832bba9406792ab6deacf349 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 23 Dec 2011 10:57:54 -0500 Subject: [PATCH] ostbuild: Port commit-artifacts to ostbuild executor --- Makefile-ostbuild.am | 4 +- src/ostbuild/ostbuild-commit-artifacts | 51 --------------- .../pyostbuild/builtin_commit_artifacts.py | 65 +++++++++++++++++++ src/ostbuild/pyostbuild/main.py | 3 +- 4 files changed, 69 insertions(+), 54 deletions(-) delete mode 100644 src/ostbuild/ostbuild-commit-artifacts create mode 100644 src/ostbuild/pyostbuild/builtin_commit_artifacts.py diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am index 96b2e376..c23cea81 100644 --- a/Makefile-ostbuild.am +++ b/Makefile-ostbuild.am @@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile bin_SCRIPTS += ostbuild bin_SCRIPTS += \ - src/ostbuild/ostbuild-commit-artifacts \ src/ostbuild/ostbuild-chroot-compile-one-impl \ src/ostbuild/ostbuild-nice-and-log-output \ $(NULL) @@ -32,8 +31,9 @@ pyostbuild_PYTHON = \ src/ostbuild/pyostbuild/main.py \ src/ostbuild/pyostbuild/ostbuildlog.py \ src/ostbuild/pyostbuild/subprocess_helpers.py \ - src/ostbuild/pyostbuild/builtin_compile_one.py \ src/ostbuild/pyostbuild/builtin_autodiscover_meta.py \ + src/ostbuild/pyostbuild/builtin_commit_artifacts.py \ + src/ostbuild/pyostbuild/builtin_compile_one.py \ $(NULL) bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot diff --git a/src/ostbuild/ostbuild-commit-artifacts b/src/ostbuild/ostbuild-commit-artifacts deleted file mode 100644 index 5fcb21d8..00000000 --- a/src/ostbuild/ostbuild-commit-artifacts +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python - -# Copyright (C) 2011 Colin Walters -# -# This library 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, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -# ostbuild-compile-one-make wraps systems that implement the GNOME build API: -# http://people.gnome.org/~walters/docs/build-api.txt - -import os,sys,subprocess,tempfile,re - -i=1 -repo=sys.argv[i] - -artifact_re = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),([^.]+)\.tar\.gz$') - -def call_ostree_sync(*args): - subprocess.check_call(['ostree', '--repo=' + repo] + list(args)) - -for arg in sys.argv[2:]: - basename = os.path.basename(arg) - match = artifact_re.match(basename) - if match is None: - print "Invalid artifact name: %s" % (arg, ) - sys.exit(1) - buildroot = match.group(1) - buildroot_version = match.group(2) - name = match.group(3) - branch = match.group(4) - version = match.group(5) - - branch_name = 'artifacts/%s/%s/%s' % (buildroot, name, branch) - - call_ostree_sync('commit', '-b', branch_name, '-s', 'Build ' + version, - '--add-metadata-string=ostree-buildroot-version=' + buildroot_version, - '--add-metadata-string=ostree-artifact-version=' + version, - '--skip-if-unchanged', '--tar-autocreate-parents', '--tree=tar=' + arg) - diff --git a/src/ostbuild/pyostbuild/builtin_commit_artifacts.py b/src/ostbuild/pyostbuild/builtin_commit_artifacts.py new file mode 100644 index 00000000..af78e71d --- /dev/null +++ b/src/ostbuild/pyostbuild/builtin_commit_artifacts.py @@ -0,0 +1,65 @@ +#!/usr/bin/python + +# Copyright (C) 2011 Colin Walters +# +# This library 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, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# ostbuild-compile-one-make wraps systems that implement the GNOME build API: +# http://people.gnome.org/~walters/docs/build-api.txt + +import os,sys,subprocess,tempfile,re +import argparse + +from . import builtins +from .ostbuildlog import log, fatal +from .subprocess_helpers import run_sync + +class OstbuildCommitArtifacts(builtins.Builtin): + name = "commit-artifacts" + short_description = "Commit artifacts to their corresponding repository branches" + + def execute(self, argv): + artifact_re = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),([^.]+)\.tar\.gz$') + + parser = argparse.ArgumentParser(self.short_description) + parser.add_argument('--repo') + parser.add_argument('artifacts', nargs='+') + + args = parser.parse_args(argv) + + if args.repo is None: + fatal("--repo must be specified") + + for arg in args.artifacts: + basename = os.path.basename(arg) + match = artifact_re.match(basename) + if match is None: + fatal("Invalid artifact name: %s" % (arg, )) + buildroot = match.group(1) + buildroot_version = match.group(2) + name = match.group(3) + branch = match.group(4) + version = match.group(5) + + branch_name = 'artifacts/%s/%s/%s' % (buildroot, name, branch) + + run_sync(['ostree', '--repo=' + args.repo, + 'commit', '-b', branch_name, '-s', 'Build ' + version, + '--add-metadata-string=ostree-buildroot-version=' + buildroot_version, + '--add-metadata-string=ostree-artifact-version=' + version, + '--skip-if-unchanged', '--tar-autocreate-parents', '--tree=tar=' + arg]) + +builtins.register(OstbuildCommitArtifacts) diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py index 5cd5587e..84f8e11e 100755 --- a/src/ostbuild/pyostbuild/main.py +++ b/src/ostbuild/pyostbuild/main.py @@ -22,8 +22,9 @@ import sys import argparse from . import builtins -from . import builtin_compile_one from . import builtin_autodiscover_meta +from . import builtin_commit_artifacts +from . import builtin_compile_one def usage(ecode): print "Builtins:"