From: Seth Vidal Date: Thu, 17 Jan 2008 20:41:12 +0000 (-0500) Subject: re-enable --cachedir in code X-Git-Tag: upstream/0.9.9~151 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bbf7e9b26efae6c1fa222c0cc91627e542b76784;p=tools%2Fcreaterepo.git re-enable --cachedir in code fix logic issues in cachedir from 0.4.X --- diff --git a/createrepo/__init__.py b/createrepo/__init__.py index aa82f4b..74f7676 100644 --- a/createrepo/__init__.py +++ b/createrepo/__init__.py @@ -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): diff --git a/createrepo/yumbased.py b/createrepo/yumbased.py index e705f6e..816df6c 100644 --- a/createrepo/yumbased.py +++ b/createrepo/yumbased.py @@ -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\n" return msg - - - +