#!/usr/bin/python -tt # 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 Library 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. # copyright (c) 2008 Red Hat, Inc - written by Seth Vidal import yum import sys from yum.misc import getCacheDir, checksum import urlparse from yum import Errors from optparse import OptionParser #### # take a file path to a repo as an option, verify all the metadata vs the repomd.xml # optionally go through each package and verify it vs the checksum in the primary def checkfileurlpkg(pkg): pkg_path = pkg.remote_url pkg_path = pkg_path.replace('file://', '') (csum_type, csum) = pkg.returnIdSum() try: filesum = checksum(csum_type, pkg_path) except Errors.MiscError: return False if filesum != csum: return False return True def main(): parser = OptionParser() parser.add_option("-p", "--checkpackages", action="store_true", default=False) opts, args = parser.parse_args() if not args: print "Must provide a file url to the repo" sys.exit(1) url = args[0] if url[0] == '/': url = 'file://' + url s = urlparse.urlsplit(url)[0] h,d = urlparse.urlsplit(url)[1:3] if s != 'file': print "Must be a file:// url or you will not like this" sys.exit(1) repoid = '%s/%s' % (h, d) repoid = repoid.replace('/', '_') my = yum.YumBase() my.conf.cachedir = getCacheDir() my.repos.disableRepo('*') newrepo = yum.yumRepo.YumRepository(repoid) newrepo.name = repoid newrepo.baseurl = [url] newrepo.basecachedir = my.conf.cachedir newrepo.metadata_expire = 0 newrepo.enable_groups = 1 # add our new repo my.repos.add(newrepo) # enable that repo my.repos.enableRepo(repoid) # setup the repo dirs/etc my.doRepoSetup(thisrepo=repoid) for md_type in newrepo.repoXML.fileTypes(): try: print "downloading %s" % md_type newrepo.retrieveMD(md_type) except Errors.RepoError, e: print "%s metadata is not valid" % md_type try: b = my.comps.compscount except Errors.GroupsError, e: print 'Groups in repo is not valid' if opts.checkpackages: print "Checking Packages" for pkg in my.pkgSack: if not checkfileurlpkg(pkg): print "%s does not match checksum" % pkg print 'Done' if __name__ == "__main__": main()