From 708e873c3c6dd3e07b67d0ebb200a8c10f9a569e Mon Sep 17 00:00:00 2001 From: Carl George Date: May 04 2020 13:15:20 +0000 Subject: Add koji-multitag script This is a script I've been using when I want to modify multiple tags on multiple builds at the same time. It's worked well for me in practice. --- diff --git a/README.md b/README.md index a8b23ef..6d87be5 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,8 @@ Supplementary tools and utilities for the Koji build system * `koji-restore-hosts` - Restore host data from a file +* `koji-multitag` - Perform multiple tag actions on multiple builds + # Development `koji-tools` is low-barrier repository of various scripts related to usage and diff --git a/src/bin/koji-multitag b/src/bin/koji-multitag new file mode 100755 index 0000000..b406c18 --- /dev/null +++ b/src/bin/koji-multitag @@ -0,0 +1,65 @@ +#!/usr/bin/python3 + +import click +import koji +import koji_cli.lib + + +@click.command() +@click.option( + '-p', '--profile', default='koji', + help='set the koji profile' +) +@click.option( + '-u', '--untag', 'untags', multiple=True, + help='tag to remove (can be used multiple times)' +) +@click.option( + '-t', '--tag', 'tags', multiple=True, + help='tag to add (can be used multiple times)' +) +@click.option( + '-r', '--retag', 'retags', multiple=True, + help='tag to remove and re-add (can be used multiple times)' +) +@click.argument('builds', required=True, nargs=-1) +def main(profile, untags, tags, retags, builds): + """ + Perform multiple tag actions on multiple builds. + """ + + # Set up koji session. + profile_module = koji.get_profile_module(profile) + session = profile_module.ClientSession(profile_module.config.server) + try: + koji_cli.lib.activate_session(session, profile_module.config) + except KeyboardInterrupt: + raise click.ClickException('aborting koji session activation') + except profile_module.ServerOffline: + raise click.ClickException('failed to activate koji session') + + # Validate builds exist. + session.multicall = True + for build in builds: + session.findBuildID(build) + for build, [build_id] in zip(builds, session.multiCall(strict=True)): + if not build_id: + click.ClickException(f'no build found matching {build}') + + # Untag, tag, and retag builds. + session.multicall = True + for untag in untags: + for build in builds: + session.untagBuild(untag, build) + for tag in tags: + for build in builds: + session.tagBuild(tag, build) + for retag in retags: + for build in builds: + session.untagBuild(retag, build) + session.tagBuild(retag, build) + session.multiCall(strict=True) + + +if __name__ == '__main__': + main()