#!/usr/bin/python -tt import os import sys import struct import rpm import types import re import xml.sax.saxutils from yum.packages import YumLocalPackage from yum.Errors import * from yum import misc from rpmUtils.transaction import initReadOnlyTransaction from rpmUtils.miscutils import flagToString, stringToVersion 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[-1]) self.packagesize = str(self._stat[6]) self._hdrstart = None self._hdrend = None def _xml(self, item): return xml.sax.saxutils.escape(item) def _do_checksum(self): if not self._checksum: self._checksum = misc.checksum('sha', self.localpath) 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): msg = """ %s %s %s %s %s %s %s