#!/usr/bin/python # ## # Copyright (C) 2003 by Duke University # Written by Seth Vidal # 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; either version 2 # of the License, or (at your option) any later version. # # 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 rpm import sys import os def usage(): print "Usage: \n\trpmpkgvercmp pkg1 pkg2\n" sys.exit(1) def returnHdr(ts, package): """hand back the rpm header or raise an Error if the pkg is fubar""" try: fdno = os.open(package, os.O_RDONLY) except OSError, e: print "Error opening file: %s" % package sys.exit(1) ts.setVSFlags(~(rpm.RPMVSF_NOMD5|rpm.RPMVSF_NEEDPAYLOAD)) try: hdr = ts.hdrFromFdno(fdno) except rpm.error, e: print "Error opening package: %s" % package sys.exit(1) if type(hdr) != rpm.hdr: print "Error opening package: %s" % package sys.exit(1) ts.setVSFlags(0) os.close(fdno) return hdr def main(args): if len(args) != 2: usage() ts = rpm.TransactionSet() pkg1 = args[0] pkg2 = args[1] hdr1 = returnHdr(ts, pkg1) hdr2 = returnHdr(ts, pkg2) rc = rpm.versionCompare(hdr1, hdr2) if rc == 0: print "%s and %s have the same rpm epoch-version-release" % (pkg1, pkg2) sys.exit(200) elif rc < 0: print "%s is newer than %s" % (pkg2, pkg1) sys.exit(100) elif rc > 0: print "%s is newer than %s" % (pkg1, pkg2) sys.exit(300) if __name__ == "__main__": main(sys.argv[1:])