re-enable --cachedir in code
authorSeth Vidal <skvidal@fedoraproject.org>
Thu, 17 Jan 2008 20:41:12 +0000 (15:41 -0500)
committerSeth Vidal <skvidal@fedoraproject.org>
Thu, 17 Jan 2008 20:41:12 +0000 (15:41 -0500)
fix logic issues in cachedir from 0.4.X

createrepo/__init__.py
createrepo/yumbased.py

index aa82f4b2c09f71a8d2eca1eb96d042912e247d0b..74f767671f0feedf9aad9fb63240f7aa255ab32e 100644 (file)
@@ -203,7 +203,7 @@ class MetaDataGenerator:
 
             self.conf.groupfile = a
 
-      if self.conf.cachedir:
+        if self.conf.cachedir:
             a = self.conf.cachedir
             if not os.path.isabs(a):
                 a = os.path.join(self.conf.outputdir ,a)
@@ -310,7 +310,7 @@ class MetaDataGenerator:
     def doPkgMetadata(self):
         """all the heavy lifting for the package metadata"""
         if self.conf.update:
-        self._setup_old_metadata_lookup()        
+            self._setup_old_metadata_lookup()        
         # rpms we're going to be dealing with
         if self.conf.pkglist:
             packages = self.conf.pkglist
@@ -367,6 +367,7 @@ class MetaDataGenerator:
             po = yumbased.CreateRepoPackage(self.ts, rpmfile)
         except Errors.MiscError, e:
             raise MDError, "Unable to open package: %s" % e
+        po.crp_cachedir = self.conf.cachedir
         return po
 
     def writeMetadataDocs(self, pkglist=[], pkgpath=None, current=0):
index e705f6e5e43ebba2d49e49b8809f134a2b2f5b31..816df6c0c7e908eebb319e39db94046097d1c6d3 100644 (file)
@@ -22,6 +22,7 @@ import rpm
 import types
 import re
 import xml.sax.saxutils
+import md5
 
 from yum.packages import YumLocalPackage
 from yum.Errors import *
@@ -54,13 +55,13 @@ class CreateRepoPackage(YumLocalPackage):
         self._hdrend = None
         self.xml_node = libxml2.newDoc("1.0")
         self.arch = self.isSrpm()
-        
+        self.crp_cachedir = None
+                
     def isSrpm(self):
         if self.tagByName('sourcepackage') == 1 or not self.tagByName('sourcerpm'):
             return 'src'
         else:
             return self.tagByName('arch')
-
         
     def _xml(self, item):
         item = utils.utf8String(item)
@@ -68,8 +69,57 @@ class CreateRepoPackage(YumLocalPackage):
         return xml.sax.saxutils.escape(item)
         
     def _do_checksum(self):
-        if not self._checksum:
+        """return a checksum for a package:
+           - check if the checksum cache is enabled
+              if not - return the checksum
+              if so - check to see if it has a cache file
+                if so, open it and return the first line's contents
+                if not, grab the checksum and write it to a file for this pkg
+         """
+        # already got it
+        if self._checksum:
+            return self._checksum
+
+        # not using the cachedir
+        if not self.crp_cachedir:
             self._checksum = misc.checksum('sha', self.localpath)
+            return self._checksum
+
+
+        t = []
+        if type(self.hdr[rpm.RPMTAG_SIGGPG]) is not types.NoneType:
+            t.append("".join(self.hdr[rpm.RPMTAG_SIGGPG]))   
+        if type(self.hdr[rpm.RPMTAG_SIGPGP]) is not types.NoneType:
+            t.append("".join(self.hdr[rpm.RPMTAG_SIGPGP]))
+        if type(self.hdr[rpm.RPMTAG_HDRID]) is not types.NoneType:
+            t.append("".join(self.hdr[rpm.RPMTAG_HDRID]))
+
+        key = md5.new("".join(t)).hexdigest()
+                                                
+        csumtag = '%s-%s-%s-%s' % (os.path.basename(self.localpath),
+                                   key, self.size, self.filetime)
+        csumfile = '%s/%s' % (self.crp_cachedir, csumtag)
+
+        if os.path.exists(csumfile) and float(self.filetime) <= float(os.stat(csumfile)[-2]):
+            csumo = open(csumfile, 'r')
+            checksum = csumo.readline()
+            csumo.close()
+             
+        else:
+            checksum = misc.checksum('sha', self.localpath)
+            csumo = open(csumfile, 'w')
+            csumo.write(checksum)
+            csumo.close()
+        
+        self._checksum = checksum
+
+        return self._checksum
+       
+        
+           
+
+           
+
             
         return self._checksum
     checksum = property(fget=lambda self: self._do_checksum())
@@ -355,7 +405,5 @@ class CreateRepoPackage(YumLocalPackage):
         msg += self._dump_changelog()
         msg += "\n</package>\n"
         return msg
-       
-        
-           
+