Closes #196.
Signed-off-by: Richard Marko <rmarko(a)redhat.com>
---
bin/Makefile.am | 1 +
bin/faf-koji-update-tags | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
faf.spec.in | 1 +
3 files changed, 91 insertions(+)
create mode 100755 bin/faf-koji-update-tags
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 0bac9dd..463a23a 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -32,6 +32,7 @@ bin_SCRIPTS = \
faf-koji \
faf-koji-pull-builds \
faf-koji-pull-tags \
+ faf-koji-update-tags \
faf-llvm-build \
faf-llvm-build-all \
faf-mail \
diff --git a/bin/faf-koji-update-tags b/bin/faf-koji-update-tags
new file mode 100755
index 0000000..5771de3
--- /dev/null
+++ b/bin/faf-koji-update-tags
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+# Copyright (C) 2013 Red Hat, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <
http://www.gnu.org/licenses/>.
+import sys
+import logging
+
+import koji
+import pyfaf
+
+from pyfaf.storage.opsys import (Tag,
+ OpSys,
+ Build,
+ BuildTag,
+ BuildSystem,
+ OpSysComponent)
+
+# Command line argument processing
+cmdline_parser = pyfaf.argparse.ArgumentParser(
+ description="Update builds with currently assigned tags.")
+cmdline_parser.add_argument("opsys", help="Operating system")
+cmdline = cmdline_parser.parse_args()
+
+db = pyfaf.storage.Database(debug=cmdline.verbose > 2)
+
+buildsys = (db.session.query(BuildSystem)
+ .join(OpSys)
+ .filter(OpSys.name == cmdline.opsys)
+ .first())
+
+if not buildsys:
+ logging.error("No buildsystem found for
'{0}'".format(cmdline.opsys))
+ sys.exit(1)
+
+logging.info("Syncing tags for {0}.".format(cmdline.opsys))
+logging.debug("Using {0} as XML-RPC URL.".format(buildsys.xmlrpc_url))
+
+koji_client = koji.ClientSession(buildsys.xmlrpc_url)
+
+db_tags = {}
+for tag in db.session.query(Tag):
+ db_tags[tag.name] = tag
+
+builds = (db.session.query(Build)
+ .join(OpSysComponent)
+ .join(OpSys)
+ .filter(OpSys.name == cmdline.opsys))
+
+result = {}
+for build in builds:
+ nvr = build.nvr()
+
+ remote_tags = set(t['name'] for t in
+ koji_client.listTags(build.secondary_id))
+
+ local_tags = set(t.name for t in build.tags)
+
+ for tag in remote_tags - local_tags:
+ logging.info("Adding tag '{0}' to build
'{1}'".format(tag, nvr))
+
+ new = BuildTag()
+ new.build_id = build.id
+ new.tag_id = db_tags[tag].id
+
+ db.session.add(new)
+
+ for tag in local_tags - remote_tags:
+ logging.info("Removing tag '{0}' from build
'{1}'".format(tag, nvr))
+
+ build_tag = (db.session.query(BuildTag)
+ .join(Tag)
+ .filter(BuildTag.build_id == build.id)
+ .filter(Tag.name == tag)
+ .one())
+
+ db.session.delete(build_tag)
+
+ db.session.flush()
diff --git a/faf.spec.in b/faf.spec.in
index 5b732ba..cf21ce3 100644
--- a/faf.spec.in
+++ b/faf.spec.in
@@ -267,6 +267,7 @@ fi
%{_bindir}/faf-koji
%{_bindir}/faf-koji-pull-builds
%{_bindir}/faf-koji-pull-tags
+%{_bindir}/faf-koji-update-tags
%{_bindir}/faf-llvm-build
%{_bindir}/faf-llvm-build-all
%{_bindir}/faf-mail
--
1.8.1.4