#!/usr/bin/python # # watch-repos.py - A utility to watch a set of repos for changes # and to kick off tests if the repo changes. # # Copyright (c) 2009 Red Hat # # Authors: # Jesse Keating import urlgrabber import os # list the arches we care about # These arches must be in the same order due to how we hack to find the # proper parent repo arch. archlist = ['i386', 'x86_64', 'ppc', 'ppc64', 'SRPMS'] newkeyarchlist = [arch + '.newkey' for arch in archlist] rawarchlist = ['i386', 'x86_64', 'ppc', 'ppc64', 'source'] # Define some base paths updatespath = 'http://kojipkgs.fedoraproject.org/mash/updates/%s/%s' goldpath = 'http://download.fedoraproject.org/pub/fedora/linux/releases/%s/Everything/%s/os' goldsrcpath = 'http://download.fedoraproject.org/pub/fedora/linux/releases/%s/Everything/source/SRPMS' rawhidepath = 'http://download.fedoraproject.org/pub/fedora/linux/%s/%s/os' rawhidesrcpath = 'http://download.fedoraproject.org/pub/fedora/linux/%s/source/SRPMS' # Define the repos. Repos are a dictionary that holds: # arches - a list of arches for a given repo # name - a unique name for the repo # uri - a string that can be turned into a yum compatible uri, takes name, arch # srcuri - a source uri string, takes name. # parents - a list of repos that are expected to also be available f9 = {'arches': archlist, 'name': 'f9', 'uri': goldpath, 'srcuri': goldsrcpath, 'parents': []} f9_updates = {'arches': newkeyarchlist, 'name': 'f9-updates', 'uri': updatespath, 'srcuri': updatespath % ('%s', 'SRPMS.newkey'), 'parents': [f9]} f9_updates_testing = {'arches': newkeyarchlist, 'name': 'f9-updates-testing', 'uri': updatespath, 'srcuri': updatespath % ('%s', 'SRPMS.newkey'), 'parents': [f9_updates, f9]} f10 = {'arches': archlist, 'name': 'f10', 'uri': goldpath, 'srcuri': goldsrcpath, 'parents': []} f10_updates = {'arches': archlist, 'name': 'f10-updates', 'uri': updatespath, 'srcuri': updatespath % ('%s', 'SRPMS'), 'parents': [f10]} f10_updates_testing = {'arches': archlist, 'name': 'f10-updates-testing', 'uri': updatespath, 'srcuri': updatespath % ('%s', 'SRPMS'), 'parents': [f10_updates, f10]} rawhide = {'arches': rawarchlist, 'name': 'development', 'uri': rawhidepath, 'srcuri': rawhidesrcpath, 'parents': []} # Define a list of repo paths to watch watchrepos = [f9_updates_testing, f9_updates, f10_updates_testing, f10_updates, rawhide] # Setup a cache path cachedir = '/var/cache/watch-repos' if not os.path.isdir(cachedir): os.makedirs(cachedir) # Setup an empty list of testable repos testable = [] # Cycle through our list of repo watches and determine which should be tested. for repo in watchrepos: try: cache = open(os.path.join(cachedir, repo['name'], repo['arches'][0], 'repomd.xml')).read() except IOError: # If we don't have a cache file, assign cache to blank. This will # let us still try to hit the repomd.xml and make sure the repo is # alive. cache = '' # check the first arch repomd.xml try: urlpath = os.path.join(repo['uri'] % (repo['name'], repo['arches'][0]), 'repodata', 'repomd.xml') remote = urlgrabber.urlread(urlpath) except Exception, e: print "Error from %s: %s" % (urlpath, e) continue # Now compare the remote to the cache if cmp(cache, remote): testable.append(repo) print testable # Cycle through the testable repos and update the cache and launch harness for repo in testable: for arch in repo['arches']: repolist = [] # list of repos to pass to harness cachepath = os.path.join(cachedir, repo['name'], arch) if not os.path.exists(cachepath): os.makedirs(cachepath) if arch == 'source' or arch == 'SRPMS' or arch == 'SRPMS.newkey': urlpath = os.path.join(repo['srcuri'] % repo['name'], 'repodata', 'repomd.xml') repolist.append(repo['srcuri'] % repo['name']) else: urlpath = os.path.join(repo['uri'] % (repo['name'], arch), 'repodata', 'repomd.xml') repolist.append(repo['uri'] % (repo['name'], arch)) output = os.path.join(cachepath, 'repomd.xml') urlgrabber.urlgrab(urlpath, filename=output) # Define the arch as parseable by autoqa queryarch = arch.replace('.newkey', '') # Add parent repos to the repolist for prepo in repo['parents']: if arch == 'source' or arch == 'SRPMS' or arch == 'SRPMS.newkey': repolist.append(prepo['srcuri'] % prepo['name']) queryarch = 'src' else: # HAAAAAAACK - goes away with newkey repolist.append(prepo['uri'] % (prepo['name'], prepo['arches'][repo['arches'].index(arch)])) # Call the autoqa tool for the post-repo-update harness harnesscall = ['autoqa', 'post-repo-update', queryarch] harnesscall.extend(repolist) print ' '.join(harnesscall) print "All done!"