#! /usr/bin/python -tt import yum import optparse version = "1.0.0" vers_txt = "Yum checksum API command %s" % version usage_txt = "%prog filename" parser = optparse.OptionParser(usage = usage_txt, version = vers_txt) if True: parser.add_option("-s", "--size", help="set the expected size of the checksumed data") parser.add_option("--md5sum", help="set the expected md5sum of the checksumed data") parser.add_option("--sha1sum", help="set the expected sha1sum of the checksumed data") parser.add_option("--sha256sum", help="set the expected sha256sum of the checksumed data") (opts, args) = parser.parse_args() if len(args) < 1: parser.print_help() sys.exit(1) if not opts.md5sum and not opts.sha1sum and not opts.sha256sum: sumtype = 'sha1' sumret = None elif opts.sha256sum: sumtype = 'sha256' sumret = opts.sha256sum elif opts.sha1sum: sumtype = 'sha1' sumret = opts.sha1sum elif opts.md5sum: sumtype = 'md5' sumret = opts.md5sum datasize = None if opts.size: datasize = int(opts.size) ret = yum.misc.checksum(sumtype, args[0], datasize=datasize) if sumret is not None: if sumret == ret: print "Matched" else: print " ** Not Matched!" print ret