def load(): repomdpath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data", "repodata", "repomd.xml") rmdo = repoMDObject.RepoMD("rawhide", repomdpath) plocation = rmdo.repoData["primary"].location[1] plocation = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data", plocation) parser = MDParser(plocation) for pkg in parser: database[pkg["name"]] = dict(pkg) print 'read: %s packages (%s suggested)' % (parser.count, parser.total)
def sanity_check_repodata(myurl): """ Sanity check the repodata for a given repository. Initial implementation by Seth Vidal. """ myurl = str(myurl) tempdir = tempfile.mkdtemp() errorstrings = [] if myurl[-1] != '/': myurl += '/' baseurl = myurl if not myurl.endswith('repodata/'): myurl += 'repodata/' else: baseurl = baseurl.replace('repodata/', '/') rf = myurl + 'repomd.xml' try: rm = urlgrabber.urlopen(rf) repomd = repoMDObject.RepoMD('foo', rm) for t in repomd.fileTypes(): data = repomd.getData(t) base, href = data.location if base: loc = base + '/' + href else: loc = baseurl + href destfn = tempdir + '/' + os.path.basename(href) dest = urlgrabber.urlgrab(loc, destfn) ctype, known_csum = data.checksum csum = checksum(ctype, dest) if csum != known_csum: errorstrings.append("checksum: %s" % t) if href.find('xml') != -1: decompressed = decompress(dest) retcode = subprocess.call( ['/usr/bin/xmllint', '--noout', decompressed]) if retcode != 0: errorstrings.append("failed xml read: %s" % t) except urlgrabber.grabber.URLGrabError, e: errorstrings.append('Error accessing repository %s' % e)