[yum-git] verifytree.py
Seth Vidal
skvidal at linux.duke.edu
Mon Aug 4 20:42:22 UTC 2008
verifytree.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
New commits:
commit f711eca0b834bbf3ad68b1109e0d8789e51d05d6
Author: Seth Vidal <skvidal at fedoraproject.org>
Date: Mon Aug 4 16:39:31 2008 -0400
add optional .treeinfo [checksums] parsing
diff --git a/verifytree.py b/verifytree.py
index cebb039..7021813 100755
--- a/verifytree.py
+++ b/verifytree.py
@@ -21,6 +21,7 @@ from yum.misc import getCacheDir, checksum
import urlparse
from yum import Errors
from optparse import OptionParser
+import ConfigParser
####
# take a file path to a repo as an option, verify all the metadata vs repomd.xml
@@ -69,7 +70,43 @@ def checkfileurl(pkg):
return True
+def treeinfo_checksum(treeinfo):
+ # read treeinfo file into cp
+ # take checksums section
+ cp = ConfigParser.ConfigParser()
+ try:
+ cp.read(treeinfo)
+ except ConfigParser.MissingSectionHeaderError:
+ # Generally this means we failed to access the file
+ print " could not find sections in treeinfo file %s" % treeinfo
+ return
+ except ConfigParser.Error:
+ print " could not parse treeinfo file %s" % treeinfo
+ return
+
+ if not cp.has_section('checksums'):
+ print " no checksums section in treeinfo file %s" % treeinfo
+ return
+
+ dir_path = os.path.dirname(treeinfo)
+ for opt in cp.options('checksums'):
+ fnpath = dir_path + '/%s' % opt
+ fnpath = os.path.normpath(fnpath)
+ csuminfo = cp.get('checksums', opt).split(':')
+ if len(csuminfo) < 2:
+ print " checksum information doesn't make any sense for %s." % opt
+ continue
+
+ if not os.path.exists(fnpath):
+ print " cannot find file %s listed in treeinfo" % fnpath
+ continue
+
+ csum = checksum(csuminfo[0], fnpath)
+ if csum != csuminfo[1]:
+ print " file %s %s does not match:\n ondisk %s vs treeinfo: %s" % (opt, csuminfo[0], csum, csuminfo[1])
+ continue
+
def main():
parser = OptionParser()
parser.usage = """
@@ -81,6 +118,8 @@ def main():
help="Check all packages in the repo")
parser.add_option("-t","--testopia",action="store",type="int",
help="Report results to the given testopia run number")
+ parser.add_option("-r","--treeinfo", action="store_true", default=False,
+ help="check the checksums of listed files in a .treeinfo file, if available")
opts, args = parser.parse_args()
if not args:
print "Must provide a file url to the repo"
@@ -199,6 +238,12 @@ def main():
else:
report('COMPS','PASSED')
+ # if we've got a .treeinfo file and we are told to check it, then do so
+ tr_path = basedir + '/.treeinfo'
+ if opts.treeinfo and os.path.exists(tr_path):
+ print "Checking checksums of files in .treeinfo"
+ treeinfo_checksum(tr_path)
+
sack = []
packages_ok = True
if opts.checkall:
More information about the Yum-cvs-commits
mailing list