#!/usr/bin/python __version__ = { 'Rev': '$Rev$', 'Date': '$Date$', 'Author': '$Author$', 'URL': '$URL$', 'Id': '$Id$' } import sys import os import os.path import re fname_re = re.compile('^(.*)-([^-]*-[^-]*)\.[^.]+\.rpm$') rpmsec_re = re.compile('^(.*)-([^-]*-[^-]*)$') arches = sys.argv[2:] rpmlocs = {} for arch in arches: for fname in os.listdir(arch): match = fname_re.match(fname) if match: base = match.group(1) version = match.group(2) if not rpmlocs.has_key(base): rpmlocs[base] = {} vdict = rpmlocs[base] if not vdict.has_key(version): vdict[version] = os.path.join(arch, fname) #for btuple in rpmlocs.items(): # for vtuple in btuple[1].items(): # print "%s %s -> %s" % ( btuple[0], vtuple[0], vtuple[1] ) replacelist = [] for line in file(sys.argv[1], 'r').xreadlines(): match = rpmsec_re.match(line) base = match.group(1) version = match.group(2)[:-1] vdict = rpmlocs.get(base) if vdict: replacelist.append( (base, version, vdict) ) #print replacelist for reptuple in replacelist: if reptuple[2].has_key(reptuple[1]): del reptuple[2][reptuple[1]] replacelist = filter(lambda x: len(x[2]) > 0, replacelist) for reptuple in replacelist: for vtuple in reptuple[2].items(): print "%s %s %s %s" % (reptuple[0], reptuple[1], vtuple[0], vtuple[1])