From e4a038d00c26ca2a7064e0428a9d318e02dce1a5 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Wed, 13 Aug 2008 12:25:16 -0400 Subject: [PATCH] remove most of the yumbased code, disable database-only for now --- createrepo/__init__.py | 18 +-- createrepo/yumbased.py | 336 +---------------------------------------- genpkgmetadata.py | 5 +- 3 files changed, 15 insertions(+), 344 deletions(-) diff --git a/createrepo/__init__.py b/createrepo/__init__.py index bebea27..e9f1e08 100644 --- a/createrepo/__init__.py +++ b/createrepo/__init__.py @@ -403,13 +403,11 @@ class MetaDataGenerator: po = yumbased.CreateRepoPackage(self.ts, rpmfile) except Errors.MiscError, e: raise MDError, "Unable to open package: %s" % e - # if we're going to add anything in from outside, here is where - # you can do it - po.crp_changelog_limit = self.conf.changelog_limit - po.crp_cachedir = self.conf.cachedir - po.crp_baseurl = baseurl - po.crp_reldir = reldir - po.crp_packagenumber = self.current_pkg + # external info we need + po._cachedir = self.conf.cachedir + po._baseurl = baseurl + po._reldir = reldir + po._packagenumber = self.current_pkg for r in po.requires_print: if r.startswith('rpmlib('): self.rpmlib_reqs[r] = 1 @@ -466,11 +464,13 @@ class MetaDataGenerator: po = pkg if self.conf.database_only: - po.do_sqlite_dump(self.md_sqlite) + pass # disabled right now for sanity reasons (mine) + #po.do_sqlite_dump(self.md_sqlite) else: self.primaryfile.write(po.xml_dump_primary_metadata()) self.flfile.write(po.xml_dump_filelists_metadata()) - self.otherfile.write(po.xml_dump_other_metadata()) + self.otherfile.write(po.xml_dump_other_metadata( + clog_limit=self.conf.changelog_limit)) else: if self.conf.verbose: self.callback.log(_("Using data from old metadata for %s") % pkg) diff --git a/createrepo/yumbased.py b/createrepo/yumbased.py index 09f7a8c..adb6017 100644 --- a/createrepo/yumbased.py +++ b/createrepo/yumbased.py @@ -16,11 +16,9 @@ import os -import struct import rpm import types import re -import xml.sax.saxutils import md5 from yum.packages import YumLocalPackage @@ -29,50 +27,11 @@ from yum import misc from yum.sqlutils import executeSQL from rpmUtils.transaction import initReadOnlyTransaction from rpmUtils.miscutils import flagToString, stringToVersion -import libxml2 import utils - - -#FIXME - merge into class with config stuff -fileglobs = ['.*bin\/.*', '^\/etc\/.*', '^\/usr\/lib\/sendmail$'] -file_re = [] -for glob in fileglobs: - file_re.append(re.compile(glob)) - -dirglobs = ['.*bin\/.*', '^\/etc\/.*'] -dir_re = [] -for glob in dirglobs: - dir_re.append(re.compile(glob)) - - class CreateRepoPackage(YumLocalPackage): def __init__(self, ts, package): YumLocalPackage.__init__(self, ts, package) - self._checksum = None - self._stat = os.stat(package) - self.filetime = str(self._stat[-2]) - self.packagesize = str(self._stat[6]) - self._hdrstart = None - self._hdrend = None - self.xml_node = libxml2.newDoc("1.0") - self.arch = self.isSrpm() - self.crp_cachedir = None - self.crp_reldir = None - self.crp_baseurl = "" - self.crp_packagenumber = 1 - self.checksum_type = 'sha' - - 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) - item = item.rstrip() - return xml.sax.saxutils.escape(item) def _do_checksum(self): """return a checksum for a package: @@ -87,7 +46,7 @@ class CreateRepoPackage(YumLocalPackage): return self._checksum # not using the cachedir - if not self.crp_cachedir: + if not self._cachedir: self._checksum = misc.checksum(self.checksum_type, self.localpath) return self._checksum @@ -104,7 +63,7 @@ class CreateRepoPackage(YumLocalPackage): csumtag = '%s-%s-%s-%s' % (os.path.basename(self.localpath), key, self.size, self.filetime) - csumfile = '%s/%s' % (self.crp_cachedir, csumtag) + csumfile = '%s/%s' % (self._cachedir, csumtag) if os.path.exists(csumfile) and float(self.filetime) <= float(os.stat(csumfile)[-2]): csumo = open(csumfile, 'r') @@ -120,297 +79,8 @@ class CreateRepoPackage(YumLocalPackage): self._checksum = checksum return self._checksum - - checksum = property(fget=lambda self: self._do_checksum()) - - def _get_header_byte_range(self): - """takes an rpm file or fileobject and returns byteranges for location of the header""" - if self._hdrstart and self._hdrend: - return (self._hdrstart, self._hdrend) - - - fo = open(self.localpath, 'r') - #read in past lead and first 8 bytes of sig header - fo.seek(104) - # 104 bytes in - binindex = fo.read(4) - # 108 bytes in - (sigindex, ) = struct.unpack('>I', binindex) - bindata = fo.read(4) - # 112 bytes in - (sigdata, ) = struct.unpack('>I', bindata) - # each index is 4 32bit segments - so each is 16 bytes - sigindexsize = sigindex * 16 - sigsize = sigdata + sigindexsize - # we have to round off to the next 8 byte boundary - disttoboundary = (sigsize % 8) - if disttoboundary != 0: - disttoboundary = 8 - disttoboundary - # 112 bytes - 96 == lead, 8 = magic and reserved, 8 == sig header data - hdrstart = 112 + sigsize + disttoboundary - - fo.seek(hdrstart) # go to the start of the header - fo.seek(8,1) # read past the magic number and reserved bytes - - binindex = fo.read(4) - (hdrindex, ) = struct.unpack('>I', binindex) - bindata = fo.read(4) - (hdrdata, ) = struct.unpack('>I', bindata) - - # each index is 4 32bit segments - so each is 16 bytes - hdrindexsize = hdrindex * 16 - # add 16 to the hdrsize to account for the 16 bytes of misc data b/t the - # end of the sig and the header. - hdrsize = hdrdata + hdrindexsize + 16 - - # header end is hdrstart + hdrsize - hdrend = hdrstart + hdrsize - fo.close() - self._hdrstart = hdrstart - self._hdrend = hdrend - - return (hdrstart, hdrend) - - hdrend = property(fget=lambda self: self._get_header_byte_range()[1]) - hdrstart = property(fget=lambda self: self._get_header_byte_range()[0]) - def _dump_base_items(self): - - # if we start seeing fullpaths in the location tag - this is the culprit - if self.crp_reldir and self.localpath.startswith(self.crp_reldir): - relpath = self.localpath.replace(self.crp_reldir, '') - if relpath[0] == '/': relpath = relpath[1:] - else: - relpath = self.localpath - - packager = url = '' - if self.packager: - packager = self._xml(self.packager) - - if self.url: - url = self._xml(self.url) - - msg = """ - %s - %s - - %s - %s - %s - %s - %s -