While debugging watch-koji-builds.py output, it was helpful to add a command-line option to limit the koji tags searched. This patch adds support for a --tag|-t option that, when provided, only schedules jobs for the provided tags. The provided tags must also exist in repoinfo.conf. --- hooks/post-koji-build/watch-koji-builds.py | 41 +++++++++++++++++++--------- lib/python/config.py | 8 +++++- lib/python/repoinfo.py | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-)
diff --git a/hooks/post-koji-build/watch-koji-builds.py b/hooks/post-koji-build/watch-koji-builds.py index eaf8ff7..9469a94 100755 --- a/hooks/post-koji-build/watch-koji-builds.py +++ b/hooks/post-koji-build/watch-koji-builds.py @@ -40,7 +40,7 @@ class KojiWatcher(object): cachedir = '/var/cache/autoqa/watch-koji-builds/' cachefile = os.path.join(cachedir, 'koji_history_prevtimes.cache')
- def __init__(self, verbose = False, dry_run = False, prevtime = None): + def __init__(self, verbose = False, dry_run = False, prevtime = None, only_tags = []): self.dry_run = dry_run self.verbose = verbose
@@ -63,11 +63,12 @@ class KojiWatcher(object): self.prevtimes = {} # if this is empty, default_prevtime is used (see list_new_builds) if self.verbose: print "Loading taglist" - self.taglist, self.master_repos, self.pending_repos = self._load_repoinfo() # returns tuple of sets + self.taglist, self.master_repos, self.pending_repos = self._load_repoinfo(only_tags) # returns tuple of sets
- def _load_repoinfo(self): + def _load_repoinfo(self, only_tags=[]): """ - Loads the tags from repoinfo.conf using autoqa.repoinfo. + Loads the tags from repoinfo.conf using autoqa.repoinfo. If only_tags + is provided, only the tags provided will be used.
returns (taglist, master_repos, pending_repos) taglist = Set of all tags found in repoinfo @@ -79,14 +80,23 @@ class KojiWatcher(object):
"""
+ def is_tag_requested(tag, only_tags): + ''' + If only_tags is non-empty, returns whether the provided tag is + a member of only_tags. + if only_tags is empty, returns True + ''' + return not only_tags or tag in only_tags + taglist = set() master_repos = set() pending_repos = set() for repo in repoinfo.repos(): # Always include the tag for the development branch (aka rawhide) if repoinfo.get(repo, "collection_name") == "devel": - taglist.add(repoinfo.get(repo, "tag")) - + tagname = repoinfo.get(repo, "tag") + if is_tag_requested(tagname, only_tags): + taglist.add(tagname) else: ''' for all the repos do: @@ -98,13 +108,15 @@ class KojiWatcher(object): NOTE: This assumes that updates are tagged in the format 'dist-fNN-updates-candidate' ''' if len(repoinfo.getparents(repo)) == 0: - reponame = repoinfo.get(repo, "tag") + "-updates-candidate" - taglist.add(reponame) - master_repos.add(repoinfo.get(repo, "tag")) #save the 'master' repo for later filtering + tagname = repoinfo.get(repo, "tag") + "-updates-candidate" + if is_tag_requested(tagname, only_tags): + taglist.add(tagname) + master_repos.add(repoinfo.get(repo, "tag")) #save the 'master' repo for later filtering else: - reponame = repoinfo.get(repo, "tag") + "-pending" - taglist.add(reponame) - pending_repos.add(reponame) + tagname = repoinfo.get(repo, "tag") + "-pending" + if is_tag_requested(tagname, only_tags): + taglist.add(tagname) + pending_repos.add(tagname)
if self.verbose: print "\ntaglist:", sorted(taglist), "\n\n", "pending_repos:", sorted(pending_repos), "\n" @@ -490,6 +502,9 @@ if __name__ == '__main__': tags for new builds and kick off tests when new builds/packages are found.') parser.add_option('--dryrun', '--dry-run', action='store_true', help='Do not actually execute commands, just show what would be done') + parser.add_option('-t', '--tag', action='append', + type='string', default=[], dest="tags", + help='Only look for builds in the specified koji tags (default: all)') parser.add_option('-p', '--prevtime', action='store', type='float', default=None, help='How far back to look for new builds (seconds since last epoch)') @@ -499,7 +514,7 @@ tags for new builds and kick off tests when new builds/packages are found.')
try: - watcher = KojiWatcher(verbose = opts.verbose, dry_run = opts.dryrun, prevtime = opts.prevtime) + watcher = KojiWatcher(verbose = opts.verbose, dry_run = opts.dryrun, prevtime = opts.prevtime, only_tags = opts.tags) exit_status = watcher.run()
except KeyboardInterrupt: