Ejemplo n.º 1
0
    def getHeader(self, package, msgCallback=None, progressCallback=None):
        hdr = None
        # package list format
        # 0        1        3       4     5     6      7
        # name, version, release, epoch, arch, size, channel

        filename = "%s-%s-%s.%s.hdr" % (package[0], package[1], package[2],
                                        package[4])
        channel = package[6]

        filePath = "%s/%s" % (self.cfg["storageDir"], filename)
        self.s.set_progress_callback(progressCallback, rpmSource.BUFFER_SIZE)

        fd = self.s.getPackageHeader(channel, filename)

        pkgname = "%s-%s-%s" % (package[0], package[1], package[2])
        if msgCallback:
            msgCallback(filename)

        buffer = fd.read()
        open(filePath, "w+").write(buffer)
        fd.close()

        hdr = rpmUtils.readHeaderBlob(buffer)
        rpmSourceUtils.saveHeader(hdr)
        self.headerCache["%s-%s-%s.%s" % (hdr['name'], hdr['version'],
                                          hdr['release'], hdr['arch'])] = hdr
        return hdr
Ejemplo n.º 2
0
    def getHeader(self, package, msgCallback = None, progressCallback = None):
        hdr = None
        # package list format
        # 0        1        3       4     5     6      7
        # name, version, release, epoch, arch, size, channel

        filename = "%s-%s-%s.%s.hdr" % (package[0], package[1], package[2],
            package[4])
        channel = package[6]

        filePath = "%s/%s" % (self.cfg["storageDir"], filename)
        self.s.set_progress_callback(progressCallback,rpmSource.BUFFER_SIZE )
        
        fd = self.s.getPackageHeader(channel, filename)

        pkgname = "%s-%s-%s" % (package[0], package[1], package[2])
        if msgCallback:
            msgCallback(filename)

        buffer = fd.read()
        open(filePath, "w+").write(buffer)
        fd.close()

        hdr = rpmUtils.readHeaderBlob(buffer)
        rpmSourceUtils.saveHeader(hdr)
        self.headerCache["%s-%s-%s.%s" % (hdr['name'],
                                       hdr['version'],
                                       hdr['release'],
                                       hdr['arch'])] = hdr
        return hdr
Ejemplo n.º 3
0
    def getObsoletes(self, channel,
                     msgCallback = None, progressCallback = None):
        # well, we've got the headers, might as well create a proper
        # obslist at this point
        
        filePath = "%s/%s-obsoletes.%s" % (self.cfg["storageDir"],
                                           channel['label'], channel['version'])
        globPattern = "%s/%s-obsoletes.*" % (self.cfg["storageDir"],
                                             channel['label'])

        
        if msgCallback:
            msgCallback("Fetching obsoletes list for %s" % channel['url'])

        try:
            pkgList = self.pkglists[channel['label']]
        except KeyError:
            # we just hit the getObsoletes path, with no package info known
            # figure it out ourselves
            rd = repoDirector.initRepoDirector()
            pkgList = rd.listPackages(channel, msgCallback, progressCallback)
            self.pkglists[channel['label']] = pkgList

        obsList = []
        total = len(pkgList)
        count = 0
        for pkg in pkgList:
            baseFileName = "%s-%s-%s.%s.hdr" % (pkg[0], pkg[1], pkg[2], pkg[4])
            fileName = "%s/%s" % (self.cfg["storageDir"], baseFileName)
            
            if os.access(fileName, os.R_OK):
                fd = open(fileName, "r")
                try:
                    hdr = rpmUtils.readHeaderBlob(fd.read())
                except:
                    continue
                fd.close()
                if not hdr['obsoletes']:
                    continue
                obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
                if obs:
#                    print obs
                    obsList = obsList + obs

            if progressCallback:
                progressCallback(count, total)
            count = count + 1
            
        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        obsList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(obsList, filePath,globPattern) 
#        print obsList
        return obsList
Ejemplo n.º 4
0
    def getObsoletes(self, channel, msgCallback=None, progressCallback=None):
        # well, we've got the headers, might as well create a proper
        # obslist at this point

        filePath = "%s/%s-obsoletes.%s" % (
            self.cfg["storageDir"], channel['label'], channel['version'])
        globPattern = "%s/%s-obsoletes.*" % (self.cfg["storageDir"],
                                             channel['label'])

        if msgCallback:
            msgCallback("Fetching obsoletes list for %s" % channel['url'])

        try:
            pkgList = self.pkglists[channel['label']]
        except KeyError:
            # we just hit the getObsoletes path, with no package info known
            # figure it out ourselves
            rd = repoDirector.initRepoDirector()
            pkgList = rd.listPackages(channel, msgCallback, progressCallback)
            self.pkglists[channel['label']] = pkgList

        obsList = []
        total = len(pkgList)
        count = 0
        for pkg in pkgList:
            baseFileName = "%s-%s-%s.%s.hdr" % (pkg[0], pkg[1], pkg[2], pkg[4])
            fileName = "%s/%s" % (self.cfg["storageDir"], baseFileName)

            if os.access(fileName, os.R_OK):
                fd = open(fileName, "r")
                try:
                    hdr = rpmUtils.readHeaderBlob(fd.read())
                except:
                    continue
                fd.close()
                if not hdr['obsoletes']:
                    continue
                obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
                if obs:
                    #                    print obs
                    obsList = obsList + obs

            if progressCallback:
                progressCallback(count, total)
            count = count + 1

        # now we have the package list, convert it to xmlrpc style
        # presentation and dump it
        obsList.sort(lambda a, b: cmp(a[0], b[0]))

        rpmSourceUtils.saveListToDisk(obsList, filePath, globPattern)
        #        print obsList
        return obsList
Ejemplo n.º 5
0
    def getHeader(self, package, msgCallback = None, progressCallback = None):
        # yum adds the epoch into the filename of the header, so create the
        # approriate remotename, handling epoch=0 crap as well
        if package[3] == "":
            remoteFilename = "%s-%s-%s-%s.%s.hdr" % (package[0], "0", package[1], package[2],
                                        package[4])
        else:
            remoteFilename = "%s-%s-%s-%s.%s.hdr" % (package[0], package[3], package[1], package[2],
                                        package[4])

        if msgCallback:
            msgCallback(remoteFilename)

        channels = rhnChannel.getChannels()
        channel = channels.getByLabel(package[6])
        url = "%s/headers/%s" % (channel['url'],remoteFilename )
	if msgCallback:
		msgCallback("Fetching %s" % url)
        # heck, maybe even borrow the one from yum

        
        nohdr = 1
        count = 0
        while ((nohdr) and (count < 5)):
            count = count + 1 
            try:
                # fix this to use fetchUrl and stringIO's for gzip
                (fn, h) = urllib.urlretrieve(url)
                
                #        print fn
                # the yum headers are gzip'ped
                fh = gzip.open(fn, "r")
                
                hdrBuf = fh.read()
                
                # FIXME: lame, need real callbacks
                if progressCallback:
                    progressCallback(1,1)
            
                hdr = rpmUtils.readHeaderBlob(hdrBuf)
                rpmSourceUtils.saveHeader(hdr)
                self.headerCache["%s-%s-%s" % (hdr['name'],
                                               hdr['version'],
                                               hdr['release'])] = hdr
                nohdr = 0
            except:
                print "There was an error downloading:", "%s"  % url
                nohdr = 1

        return hdr
Ejemplo n.º 6
0
    def listPackages(self, channel, msgCallback = None,
        progressCallback = None):
        pkgsDict = self._get_all_packages_dict(channel['path'],
            channel['label'])
            
        latestPkgsDict = {}
        for pkgNvre in pkgsDict.keys():
            # first version of this package, continue
            pkgName = pkgNvre[0]
            tupNvre = tuple(pkgNvre)
            if not latestPkgsDict.has_key(pkgName):
                latestPkgsDict[pkgName] = pkgsDict[tupNvre]
                continue


            ret = up2dateUtils.comparePackages(latestPkgsDict[pkgName][0],
                list(pkgNvre))
            if ret > 0:
                # don't care, we already have a better version
                continue
            if ret < 0:
                # Better version
                latestPkgsDict[pkgName] = pkgsDict[pkgNvre]
                continue
            # if it's 0, we already have it

        pkgList = self._package_list_from_dict(latestPkgsDict,
            self.cfg["storageDir"], channel['label'], "", channel['version'])

        # since were talking local file, and we are already
        # loading them up and poking at the headers, lets figure
        # out the obsoletes stuff now too while were at it
        self.obsList = []

        for pkg in pkgList:
            rpmpath = pkg[7]
            hdrBuf = self.__getHeader(rpmpath)
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())

            
            # look for header info
            if not hdr['obsoletes']:
                continue
            
            obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
            if obs:
                self.obsList = self.obsList + obs

        return pkgList
Ejemplo n.º 7
0
    def getHeader(self, package, msgCallback=None, progressCallback=None):
        # yum adds the epoch into the filename of the header, so create the
        # approriate remotename, handling epoch=0 crap as well
        if package[3] == "":
            remoteFilename = "%s-%s-%s-%s.%s.hdr" % (
                package[0], "0", package[1], package[2], package[4])
        else:
            remoteFilename = "%s-%s-%s-%s.%s.hdr" % (
                package[0], package[3], package[1], package[2], package[4])

        if msgCallback:
            msgCallback(remoteFilename)

        channels = rhnChannel.getChannels()
        channel = channels.getByLabel(package[6])
        url = "%s/headers/%s" % (channel['url'], remoteFilename)
        if msgCallback:
            msgCallback("Fetching %s" % url)
        # heck, maybe even borrow the one from yum

        nohdr = 1
        count = 0
        while ((nohdr) and (count < 5)):
            count = count + 1
            try:
                # fix this to use fetchUrl and stringIO's for gzip
                (fn, h) = urllib.urlretrieve(url)

                #        print fn
                # the yum headers are gzip'ped
                fh = gzip.open(fn, "r")

                hdrBuf = fh.read()

                # FIXME: lame, need real callbacks
                if progressCallback:
                    progressCallback(1, 1)

                hdr = rpmUtils.readHeaderBlob(hdrBuf)
                rpmSourceUtils.saveHeader(hdr)
                self.headerCache["%s-%s-%s" % (hdr['name'], hdr['version'],
                                               hdr['release'])] = hdr
                nohdr = 0
            except:
                print "There was an error downloading:", "%s" % url
                nohdr = 1

        return hdr
Ejemplo n.º 8
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):
        pkgsDict = self._get_all_packages_dict(channel['path'],
                                               channel['label'])

        latestPkgsDict = {}
        for pkgNvre in pkgsDict.keys():
            # first version of this package, continue
            pkgName = pkgNvre[0]
            tupNvre = tuple(pkgNvre)
            if not latestPkgsDict.has_key(pkgName):
                latestPkgsDict[pkgName] = pkgsDict[tupNvre]
                continue

            ret = up2dateUtils.comparePackages(latestPkgsDict[pkgName][0],
                                               list(pkgNvre))
            if ret > 0:
                # don't care, we already have a better version
                continue
            if ret < 0:
                # Better version
                latestPkgsDict[pkgName] = pkgsDict[pkgNvre]
                continue
            # if it's 0, we already have it

        pkgList = self._package_list_from_dict(latestPkgsDict,
                                               self.cfg["storageDir"],
                                               channel['label'], "",
                                               channel['version'])

        # since were talking local file, and we are already
        # loading them up and poking at the headers, lets figure
        # out the obsoletes stuff now too while were at it
        self.obsList = []

        for pkg in pkgList:
            rpmpath = pkg[7]
            hdrBuf = self.__getHeader(rpmpath)
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())

            # look for header info
            if not hdr['obsoletes']:
                continue

            obs = up2dateUtils.genObsoleteTupleFromHdr(hdr)
            if obs:
                self.obsList = self.obsList + obs

        return pkgList
Ejemplo n.º 9
0
    def getHeader(self, pkg, msgCallback=None, progressCallback=None):
        channels = rhnChannel.getChannels()
        channel = channels.getByName(pkg[6])

        #filename = "%s/%s-%s-%s.%s.rpm" % (channel['path'],  pkg[0], pkg[1],
        #                                   pkg[2], pkg[4])
        filename = pkg[7]

        # package doesnt exist
        if not os.access(filename, os.R_OK):
            return None
        hdrBuf = self.__getHeader(filename)
        try:
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())
        except:
            return None
        rpmSourceUtils.saveHeader(hdr)
        self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr
        self.__saveHeader(hdr)
        return hdr
Ejemplo n.º 10
0
    def getHeader(self, pkg, msgCallback = None, progressCallback = None):
        channels = rhnChannel.getChannels()
        channel = channels.getByName(pkg[6])
        
        #filename = "%s/%s-%s-%s.%s.rpm" % (channel['path'],  pkg[0], pkg[1],
        #                                   pkg[2], pkg[4])
        filename = pkg[7]

        # package doesnt exist
        if not os.access(filename, os.R_OK):
            return None
        hdrBuf = self.__getHeader(filename)
        try:
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())
        except:
            return None
        rpmSourceUtils.saveHeader(hdr)
        self.headerCache[up2dateUtils.pkgToStringArch(pkg)] = hdr
        self.__saveHeader(hdr)
        return hdr
Ejemplo n.º 11
0
    def _get_all_packages_dict(self, path, label):
        rpmpaths = walk(path, recurse=0, pattern="*.rpm", return_folders=0)

        pkgsDict = {}
        for rpmpath in rpmpaths:
            filename = os.path.basename(rpmpath)
            bits = string.split(filename, ".")
            arch = bits[-2]

            if not self._is_compatible_arch(arch):
                continue

            # might as well collect the filesize
            hdrBuf = self.__getHeader(rpmpath)
            # busted package of some sort, skip it
            if hdrBuf == None:
                continue
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())
            size = os.stat(rpmpath)[6]

            epoch = hdr['epoch']
            if epoch == None:
                epoch = ""
            else:
                epoch = str(epoch)

            pkg = [
                hdr['name'], hdr['version'], hdr['release'], epoch,
                hdr['arch'], size, label, rpmpath
            ]

            # group packages by nvre and store the different arches in a list
            pkgNvre = tuple(pkg[:4])
            if not pkgsDict.has_key(pkgNvre):
                pkgsDict[pkgNvre] = []
            pkgsDict[pkgNvre].append(pkg)

        return pkgsDict
Ejemplo n.º 12
0
    def _get_all_packages_dict(self, path, label):
        rpmpaths = walk(path, recurse=0, pattern="*.rpm", return_folders=0)

        pkgsDict = {}
        for rpmpath in rpmpaths:
            filename = os.path.basename(rpmpath)
            bits = string.split(filename, ".")
            arch = bits[-2]
           
            if not self._is_compatible_arch(arch):
                continue

            # might as well collect the filesize 
            hdrBuf = self.__getHeader(rpmpath)
            # busted package of some sort, skip it
            if hdrBuf == None:
                continue
            hdr = rpmUtils.readHeaderBlob(hdrBuf.unload())
            size = os.stat(rpmpath)[6]
            
            epoch = hdr['epoch']
            if epoch == None:
                epoch = ""
            else:
                epoch = str(epoch)
            
            pkg = [hdr['name'], hdr['version'], hdr['release'], epoch,
                hdr['arch'], size, label, rpmpath]

            # group packages by nvre and store the different arches in a list
            pkgNvre = tuple(pkg[:4])
            if not pkgsDict.has_key(pkgNvre):
                pkgsDict[pkgNvre] = []
            pkgsDict[pkgNvre].append(pkg)

        return pkgsDict
Ejemplo n.º 13
0
 def __saveHeader(self, hdr):
     tmp = rpmUtils.readHeaderBlob(hdr.unload())
     rpmSourceUtils.saveHeader(tmp)
Ejemplo n.º 14
0
 def __saveHeader(self, hdr):
     tmp = rpmUtils.readHeaderBlob(hdr.unload())
     rpmSourceUtils.saveHeader(tmp)