All the watchers have standardized --help and --dry-run now. This will ease the development of your own tests. Koji watcher was modified not to save any information in dry run (in compliance with other watchers). --- hooks/post-koji-build/watch-koji-builds.py | 30 ++++++++++++++++++--------- hooks/post-repo-update/watch-repos.py | 10 +++++++- hooks/post-tree-compose/watch-composes.py | 10 +++++++- 3 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/hooks/post-koji-build/watch-koji-builds.py b/hooks/post-koji-build/watch-koji-builds.py index 6a27aee..19b6a60 100755 --- a/hooks/post-koji-build/watch-koji-builds.py +++ b/hooks/post-koji-build/watch-koji-builds.py @@ -16,6 +16,7 @@ import time import pickle import xmlrpclib import subprocess +import optparse from autoqa import koji_utils
# Directory where we cache info between runs @@ -60,7 +61,7 @@ def save_list(pkglist): pickle.dump(pkglist, out) out.close()
-def new_tagged_builds_since(session, taglist, prevtime): +def new_builds_since(session, taglist, prevtime): untagged_builds = [] tagged_builds = {} for tag in taglist: @@ -78,19 +79,25 @@ def new_tagged_builds_since(session, taglist, prevtime): untagged_builds.append(nvr) #print "untagged: %s" % " ".join(untagged_builds) #print "tagged: %s" % " ".join(tagged_builds) - save_list(untagged_builds) - return tagged_builds + return (tagged_builds, untagged_builds)
if __name__ == '__main__': - # TODO: optparse for verbose/prevtime/dryrun - verbose = ('--verbose' in sys.argv) - dryrun = ('--dryrun' in sys.argv) + # Set up the option parser + # TODO: optparse for prevtime + parser = optparse.OptionParser(description='Script to watch a set of koji \ +tags for new builds and kick off tests when new builds/packages are found.') + parser.add_option('--dry-run', action='store_true', dest='dryrun', + help='Do not actually execute commands, just show what would be done') + parser.add_option('--verbose', action='store_true', + help='Print extra information') + (opts, args) = parser.parse_args() + # load prevtime from some saved timestamp prevtime = get_prevtime() if not prevtime: print "No previous run - checking builds in the past 3 hours" prevtime = time.time() - 10800 - if verbose: + if opts.verbose: print "Looking up builds since %s" % time.ctime(prevtime) # Set up the koji connection kojiopts = {} # Possible items: user, password, debug_xmlrpc, debug.. @@ -99,8 +106,11 @@ if __name__ == '__main__': tagged_builds = [] try: session.ensure_connection() - new_builds = new_tagged_builds_since(session, taglist, prevtime) - for tag, builds in new_builds.items(): + (tagged_builds, untagged_builds) = new_builds_since(session, + taglist, prevtime) + if not opts.dryrun: + save_list(untagged_builds) + for tag, builds in tagged_builds.items(): for b in builds: # Get a list of all package arches in this build arches = [r['arch'] for r in session.listRPMs(b['build_id'])] @@ -116,7 +126,7 @@ if __name__ == '__main__': for arch in testarches: harnesscall += ['--arch', arch] harnesscall.append(b['nvr']) - if dryrun: + if opts.dryrun: print " ".join(harnesscall) continue subprocess.call(harnesscall) diff --git a/hooks/post-repo-update/watch-repos.py b/hooks/post-repo-update/watch-repos.py index 7f96264..3de5083 100755 --- a/hooks/post-repo-update/watch-repos.py +++ b/hooks/post-repo-update/watch-repos.py @@ -13,8 +13,14 @@ import os import sys import subprocess from autoqa.repoinfo import repoinfo +import optparse
-dryrun = ('--dryrun' in sys.argv) +# Set up the option parser +parser = optparse.OptionParser(description='A utility to watch a set of repos \ +for changes and to kick off tests if the repo changes.') +parser.add_option('--dry-run', action='store_true', dest='dryrun', + help='Do not actually execute commands, just show what would be done') +(opts, args) = parser.parse_args()
# Set the default arch to our placeholder, '%a' repoinfo.setarch('%%a') # two %% because of ConfigParser interpolation @@ -69,7 +75,7 @@ for reponame, arches in testable.items(): harnesscall += ['--parent', repoinfo.get(preponame,'url')] harnesscall.append(repo['url'])
- if dryrun: + if opts.dryrun: print ' '.join(harnesscall) continue
diff --git a/hooks/post-tree-compose/watch-composes.py b/hooks/post-tree-compose/watch-composes.py index 868cd71..6fc3632 100755 --- a/hooks/post-tree-compose/watch-composes.py +++ b/hooks/post-tree-compose/watch-composes.py @@ -13,8 +13,14 @@ import os import sys import subprocess from autoqa.repoinfo import repoinfo +import optparse
-dryrun = ('--dryrun' in sys.argv) +# Set up the option parser +parser = optparse.OptionParser(description='A utility to watch a set of \ +compose trees for changes and to kick off tests if the compose changes.') +parser.add_option('--dry-run', action='store_true', dest='dryrun', + help='Do not actually execute commands, just show what would be done') +(opts, args) = parser.parse_args()
# Set the default arch to our placeholder, '%a' repoinfo.setarch('%%a') # two %% because of ConfigParser interpolation @@ -70,7 +76,7 @@ for reponame, arches in testable.items(): for arch in arches: harnesscall += ['--arch', arch] harnesscall.append(repo['url']) - if dryrun: + if opts.dryrun: print ' '.join(harnesscall) continue
On Fri, 2009-11-27 at 10:50 +0100, Kamil Páral wrote:
All the watchers have standardized --help and --dry-run now. This will ease the development of your own tests. Koji watcher was modified not to save any information in dry run (in compliance with other watchers).
I'm a big fan of optparse for processing cmdline arguments, so no objections from me.
Thanks, James
autoqa-devel@lists.fedorahosted.org