#44 Add koji-multitag script
Merged 5 years ago by tkopecek. Opened 5 years ago by carlwgeorge.
carlwgeorge/koji-tools multitag  into  master

file modified
+2
@@ -66,6 +66,8 @@ 

  

  * `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

@@ -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()

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.

I'm curious about untagging+retagging - what does that do for you?

That's an alternate solution to the "hidden" problem. koji-find-hidden-packages gives you the option to untag all but the latest build, but retagging the latest build also fixes the problem.

rebased onto 708e873

5 years ago

Commit 6bcaa0f fixes this pull-request

Pull-Request has been merged by tkopecek

5 years ago

Pull-Request has been merged by tkopecek

5 years ago
Metadata