#!/usr/bin/python # # diff-updates: diff rpms between rhel updates # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation version 2. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import sys import os import re sys.path.append('/usr/share/checksysreport') import globals globals.rhnConnector.login() basechannel="rhel-i386-as-4" """ You will have to generate a list of rpms for both updates to compare: foreach iso of a given update: mount -o loop file.iso update find update/ | sed 's/.*\///' |grep \.rpm >> listA.txt """ listA="/tmp/u4.txt" listB="/tmp/u5.txt" all_packages_cache={} def get_file(file): """ return the content of a file relative to the sysreport's root directory """ fullpath=file content=[] if(os.path.isfile(fullpath)): f=open(fullpath,'r') for c in f.readlines(): content.append(c) f.close() return content else: globals.die("No such file to open:"+fullpath) def get_all_rpm_in_channel(channel_label): """ return a list of all rpms info in a given channel """ if all_packages_cache.has_key(channel_label): return all_packages_cache[channel_label] tmp=globals.select_all_package_in_channel(channel_label) all_packages_cache[channel_label]=tmp return tmp def guess_package_id(target): """ Try to find the package_id that match for 'target' as its package_name, package_version, package_release and the channel_label. """ out=0 #print "#######################\ntarget=",target for curRpm in get_all_rpm_in_channel(target['channel_label']): #print "cur=",curRpm if curRpm['package_name']==target['package_name'] and \ str(curRpm['package_version'])==str(target['package_version']) \ and \ str(curRpm['package_release'])==str(target['package_release']): out=curRpm['package_id'] return out return None def get_rpms(file): out=[] for line in get_file(file): expr=r"^(.*)-(.*)-(.*)\.(.*?)\.rpm\n$" q=re.compile(expr) m=q.match(line) if m: tmpDic={} tmpDic['package_name']=str(m.group(1)) tmpDic['package_version']=str(m.group(2)) tmpDic['package_release']=str(m.group(3)) tmpDic['package_arch']=str(m.group(4)) tmpDic['channel_label']=basechannel id=guess_package_id(tmpDic) tmpDic['package_id']=str(id) out.append(tmpDic) else: print "The followin line in rpmlist has been ignored:",line #globals.die("cannot parse line: ",line) return out def display_changelog(changelog): dates=changelog.keys() dates.sort() for d in dates: print "-- %s --"%d print changelog[d]['changes'].encode('utf8') def display_errata(errata): for i in errata: infos=i['bug_per_errata'] for adv in infos.keys(): for bz in infos[adv]: print " BZ#%s %s"%(bz['id'],bz['desc']) rpmsA=get_rpms(listA) rpmsB=get_rpms(listB) dicA={} dicB={} for i in rpmsA: dicA[i['package_name']]=i for i in rpmsB: dicB[i['package_name']]=i for i in dicA: if i not in dicB.keys(): print "##################### %s only in dicA"%i continue if dicA[i]['package_id']!=dicB[i]['package_id']: print "##################### %s "%i print "%s-%s-%s (%s)"%(dicA[i]['package_name'],dicA[i]['package_version'],dicA[i]['package_release'],dicA[i]['package_id']) print "%s-%s-%s (%s)"%(dicB[i]['package_name'],dicB[i]['package_version'],dicB[i]['package_release'],dicB[i]['package_id']) changelogs=globals.diff_changelog(dicA[i]['package_id'],dicB[i]['package_id']) erratas=globals.get_erratas(dicA[i]['package_id'],dicB[i]['package_id'],basechannel,dicA[i]['package_name']) print "\n* Changelogs: " display_changelog(changelogs) print "\n* Bugzillas:" display_errata(erratas)