Esempio 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
Esempio 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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 channel['version'])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel['label'])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, '.')[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel['url'], channel['dist'])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(url,
                                lastModified=channelTimeStamp,
                                progressCallback=progressCallback,
                                agent="Up2date %s/Apt" %
                                up2dateUtils.version())
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel['label'])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel['label'],
                                 self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg['storageDir'],
                                        channel['label'], self.version)
        #print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr['epoch']
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append([
                hdr['name'],
                hdr['version'],
                hdr['release'],
                epoch,
                hdr['arch'],
                # we want the actual filesize, but alas...
                str(hdr['size']),
                channel['label']
            ])

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" %
                             (hdr['name'], hdr['version'], hdr['release'],
                              hdr['arch'])] = hdr

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

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList
Esempio n. 8
0
 def __saveHeader(self, hdr):
     tmp = rpmUtils.readHeaderBlob(hdr.unload())
     rpmSourceUtils.saveHeader(tmp)
Esempio n. 9
0
 def __saveHeader(self, hdr):
     tmp = rpmUtils.readHeaderBlob(hdr.unload())
     rpmSourceUtils.saveHeader(tmp)
Esempio n. 10
0
    def listPackages(self, channel, msgCallback=None, progressCallback=None):

        # TODO: implement cache invalidations, Last-Modified
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], channel["version"])

        # a glob used to find the old versions to cleanup
        globPattern = "%s/%s.*" % (self.cfg["storageDir"], channel["label"])
        oldLists = glob.glob(globPattern)
        channelTimeStamp = None
        if oldLists:
            filename = oldLists[0]
            filename = os.path.basename(filename)
            oldVersion = string.split(filename, ".")[-1]
            channelTimeStamp = time.strptime(oldVersion, "%Y%m%d%H%M%S")

        # assuming this is always bz2?
        url = "%s/base/pkglist.%s.bz2" % (channel["url"], channel["dist"])
        if msgCallback:
            msgCallback("Fetching %s" % url)

        ret = urlUtils.fetchUrl(
            url,
            lastModified=channelTimeStamp,
            progressCallback=progressCallback,
            agent="Up2date %s/Apt" % up2dateUtils.version(),
        )
        if ret:
            (buffer, lmtime) = ret
        else:
            return None

        symlinkname = "%s/link-%s" % (self.cfg["storageDir"], channel["label"])
        try:
            os.unlink(symlinkname)
        except OSError:
            # file doesnt exist, shrug
            pass

        self.version = time.strftime("%Y%m%d%H%M%S", lmtime)
        filePath = "%s/%s.%s" % (self.cfg["storageDir"], channel["label"], self.version)

        # sigh, no native bzip2 module... do it the old fashioned way
        tmpfilename = "%s/tmp-%s-%s" % (self.cfg["storageDir"], channel["label"], self.version)
        # print "timefilename: %s" % tmpfilename
        f = open("%s.bz2" % tmpfilename, "w")
        f.write(buffer)
        f.close()

        # FIXME, um, lame... once we settle on what url/http lib
        # we use, plugin in proper callbacks
        if progressCallback:
            progressCallback(1, 1)

        # well, since we dont have any knowledge about what the
        # channel version is supposed to be, I'cant really rely
        # on that (with up2date, the login tells me what channel
        # versions to look for). So we need a generic name
        # we symlink to the latest version.

        pipe = os.popen("/usr/bin/bunzip2 %s.bz2" % tmpfilename)
        tmp = pipe.read()

        os.symlink(tmpfilename, symlinkname)

        hdrList = rpm.readHeaderListFromFile(tmpfilename)
        # a list of rpm hdr's, handy!!

        pkgList = []

        for hdr in hdrList:
            epoch = hdr["epoch"]
            if epoch == None or epoch == "0" or epoch == 0:
                epoch = ""
            pkgList.append(
                [
                    hdr["name"],
                    hdr["version"],
                    hdr["release"],
                    epoch,
                    hdr["arch"],
                    # we want the actual filesize, but alas...
                    str(hdr["size"]),
                    channel["label"],
                ]
            )

            # what the hell, this is a little bit of a side effect, but
            # were already poking at headers, lets just save them while
            # were at it to same us some trouble
            rpmSourceUtils.saveHeader(hdr)
            self.headerCache["%s-%s-%s.%s" % (hdr["name"], hdr["version"], hdr["release"], hdr["arch"])] = hdr

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

        rpmSourceUtils.saveListToDisk(pkgList, filePath, globPattern)

        return pkgList