I have 4 branches which might be worth putting in for 3.2.18, everyone
may or maynot have looked at them before and they aren't "obviously
simple/wonderful" enough I've just committed them, so I'll just list
them and you can tell me what you think...

   _quickWhatProvides
   group_pc
   repo-sacks
*  repomd-checksums

  repomd-checksums

 This adds a checksums dict and a length member to the RepoMD object,
this is mainly for new style mirror lists. I know Seth had some
reservations about having "length" be calculated as a checksum ... but I
can't see another easy way to do it.


commit c528461b1acab1aa383de94f4024c62e5f1ccdda
Author: James Antill <[EMAIL PROTECTED]>
Date:   Tue Jul 15 17:45:33 2008 -0400

    Add length/checksums to the RepoMD object

diff --git a/yum/repoMDObject.py b/yum/repoMDObject.py
index d1d8cfb..aac35e8 100644
--- a/yum/repoMDObject.py
+++ b/yum/repoMDObject.py
@@ -22,6 +22,7 @@ iterparse = cElementTree.iterparse
 from Errors import RepoMDError
 
 import sys
+import sha
 
 def ns_cleanup(qn):
     if qn.find('}') == -1: return qn 
@@ -63,15 +64,47 @@ class RepoData:
             elif child_name == 'database_version':
                 self.dbversion = child.text
         
+class _AutoChecksumFile:
+    """ Checksum data from a file, as we read it. """
+
+    def __init__(self, fo, checksum):
+        self._fo       = fo
+        self._checksum = checksum
+
+    def __getattr__(self, attr):
+        return getattr(self._fo, attr)
+
+    def read(self, size=-1):
+        ret = self._fo.read(size)
+        self._checksum.update(ret)
+        return ret
+
+    def hexdigest(self):
+        return self._checksum.hexdigest()
+
+class _LenChecksum:
+    """ Produce the length, works like md5/sha* checksums. """
+
+    def __init__(self):
+        self._len = 0
+
+    def update(self, data):
+        self._len += len(data)
+
+    def hexdigest(self):
+        return self._len
+
 class RepoMD:
     """represents the repomd xml file"""
     
     def __init__(self, repoid, srcfile):
         """takes a repoid and a filename for the repomd.xml"""
         
-        self.timestamp = 0
         self.repoid = repoid
         self.repoData = {}
+        self.timestamp = 0
+        self.checksums = {}
+        self.length    = 0
         
         if type(srcfile) == type('str'):
             # srcfile is a filename string
@@ -79,7 +112,13 @@ class RepoMD:
         else:
             # srcfile is a file object
             infile = srcfile
-        
+
+        # More can be added: sha256/sha512/etc.
+        infile = _AutoChecksumFile(infile, _LenChecksum())
+        len_infile  = infile
+        infile = _AutoChecksumFile(infile, sha.new())
+        sha1_infile = infile
+
         parser = iterparse(infile)
         
         try:
@@ -95,6 +134,8 @@ class RepoMD:
                             self.timestamp = nts
                     except:
                         pass
+            self.checksums['sha1'] = sha1_infile.hexdigest()
+            self.length            = len_infile.hexdigest()
         except SyntaxError, e:
             raise RepoMDError, "Damaged repomd.xml file"
             
@@ -112,6 +153,9 @@ class RepoMD:
         """dump fun output"""
 
         print "file timestamp: %s" % self.timestamp
+        print "file length   : %s" % self.length
+        for csum in sorted(self.checksums):
+            print "file checksum : %s/%s" % (csum, self.checksums[csum])
         for ft in sorted(self.fileTypes()):
             thisdata = self.repoData[ft]
             print '  datatype: %s' % thisdata.type

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel

Reply via email to