#!/usr/bin/python # # check-upgrade-paths.py - A utility to examine a set of tags to verify upgrade # paths for all the packages. # # Copyright (c) 2008 Red Hat # # Authors: # Jesse Keating import koji import rpm import sys def usage(): print """ check-upgrade-paths.py tag1 tag2 [tag3 tag4] """ def compare(pkgA, pkgB): pkgdictA = koji.parse_NVR(pkgA) pkgdictB = koji.parse_NVR(pkgB) rc = rpm.labelCompare((pkgdictA['epoch'], pkgdictA['version'], pkgdictA['release']), (pkgdictB['epoch'], pkgdictB['version'], pkgdictB['release'])) return rc def buildToNvr(build): if build['epoch']: return '%s:%s' % (build['epoch'], build['nvr']) else: return build['nvr'] def printBuild(build): pkgdict = koji.parse_NVR(build) return '%s-%s-%s' % (pkgdict['name'], pkgdict['version'], pkgdict['release']) if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help', '-help', '--usage']: usage() sys.exit(0) elif len(sys.argv) < 3: usage() sys.exit(1) else: tags = sys.argv[1:] kojisession = koji.ClientSession('http://koji.fedoraproject.org/kojihub') tagdict = {} pkgdict = {} kojisession.multicall = True for tag in tags: kojisession.listTagged(tag, latest=True, inherit=True) results = kojisession.multiCall() for tag, result in zip(tags, results): tagdict[tag] = result[0] for tag in tags: for pkg in tagdict[tag]: if not pkgdict.has_key(pkg['name']): pkgdict[pkg['name']] = {} pkgdict[pkg['name']][tag] = buildToNvr(pkg) for pkg in pkgdict: for tag in tags[:-1]: if pkgdict[pkg].has_key(tag): nexttag = tags[tags.index(tag) +1] if pkgdict[pkg].has_key(nexttag): rc = compare(pkgdict[pkg][tag], pkgdict[pkg][nexttag]) if rc <= 0: continue if rc > 0: # We've got something broken here. print "%s from %s is has no upgrade path to %s from %s" % (pkgdict[pkg][tag], tag, pkgdict[pkg][nexttag], nexttag)