Exemplo n.º 1
0
 def _fetchcpioheaders(self, project, package, repo, arch):
     u = osc.core.makeurl(self.apiurl,
                          ['build', project, repo, arch, package],
                          ['view=cpioheaders'])
     try:
         r = osc.core.http_GET(u)
     except HTTPError as e:
         raise FetchError('failed to fetch header information: %s' % e)
     tmpfile = NamedTemporaryFile(prefix="cpio-", delete=False)
     for chunk in r:
         tmpfile.write(chunk)
     tmpfile.close()
     cpio = CpioRead(tmpfile.name)
     cpio.read()
     rpm_re = re.compile('(.+\.rpm)-[0-9A-Fa-f]{32}$')
     for ch in cpio:
         # ignore errors
         if ch.filename == '.errors':
             continue
         # the filehandle in the cpio archive is private so
         # open it again
         with open(tmpfile.name, 'rb') as fh:
             fh.seek(ch.dataoff, os.SEEK_SET)
             h = self.readRpmHeaderFD(fh)
             if h is None:
                 raise FetchError("failed to read rpm header for %s" %
                                  ch.filename)
             m = rpm_re.match(ch.filename.decode('utf-8'))
             if m:
                 yield m.group(1), h
     os.unlink(tmpfile.name)
Exemplo n.º 2
0
 def _fetchcpioheaders(self, project, package, repo, arch):
     u = osc.core.makeurl(self.apiurl, [ 'build', project, repo, arch, package ],
         [ 'view=cpioheaders' ])
     try:
         r = osc.core.http_GET(u)
     except HTTPError as e:
         raise FetchError('failed to fetch header information: %s'%e)
     tmpfile = NamedTemporaryFile(prefix="cpio-", delete=False)
     for chunk in r:
         tmpfile.write(chunk)
     tmpfile.close()
     cpio = CpioRead(tmpfile.name)
     cpio.read()
     rpm_re = re.compile('(.+\.rpm)-[0-9A-Fa-f]{32}$')
     for ch in cpio:
         # ignore errors
         if ch.filename == '.errors':
             continue
         # the filehandle in the cpio archive is private so
         # open it again
         with open(tmpfile.name, 'rb') as fh:
             fh.seek(ch.dataoff, os.SEEK_SET)
             h = self.readRpmHeaderFD(fh)
             if h is None:
                 raise FetchError("failed to read rpm header for %s"%ch.filename)
             m = rpm_re.match(ch.filename)
             if m:
                 yield m.group(1), h
     os.unlink(tmpfile.name)
Exemplo n.º 3
0
    def extract(self, project, package, srcinfo, repo, arch):
        # fetch cpio headers
        # check file lists for library packages
        fetchlist, liblist, debuglist = self.compute_fetchlist(
            project, package, srcinfo, repo, arch)

        if not fetchlist:
            msg = "no libraries found in %s/%s %s/%s" % (project, package,
                                                         repo, arch)
            self.logger.info(msg)
            return None, None

        # mtimes in cpio are not the original ones, so we need to fetch
        # that separately :-(
        mtimes = self._getmtimes(project, package, repo, arch)

        self.logger.debug("fetchlist %s", pformat(fetchlist))
        self.logger.debug("liblist %s", pformat(liblist))
        self.logger.debug("debuglist %s", pformat(debuglist))

        debugfiles = debuglist.values()

        # fetch binary rpms
        downloaded = self.download_files(project, package, repo, arch,
                                         fetchlist, mtimes)

        # extract binary rpms
        tmpfile = os.path.join(CACHEDIR, "cpio")
        for fn in fetchlist:
            self.logger.debug("extract %s" % fn)
            with open(tmpfile, 'wb') as tmpfd:
                if not fn in downloaded:
                    raise FetchError("%s was not downloaded!" % fn)
                self.logger.debug(downloaded[fn])
                r = subprocess.call(['rpm2cpio', downloaded[fn]],
                                    stdout=tmpfd,
                                    close_fds=True)
                if r != 0:
                    raise FetchError("failed to extract %s!" % fn)
                tmpfd.close()
                os.unlink(downloaded[fn])
                cpio = CpioRead(tmpfile)
                cpio.read()
                for ch in cpio:
                    fn = ch.filename.decode('utf-8')
                    if fn.startswith('./'):  # rpm payload is relative
                        fn = fn[1:]
                    self.logger.debug("cpio fn %s", fn)
                    if not fn in liblist and not fn in debugfiles:
                        continue
                    dst = os.path.join(UNPACKDIR, project, package, repo, arch)
                    dst += fn
                    if not os.path.exists(os.path.dirname(dst)):
                        os.makedirs(os.path.dirname(dst))
                    self.logger.debug("dst %s", dst)
                    # the filehandle in the cpio archive is private so
                    # open it again
                    with open(tmpfile, 'rb') as cpiofh:
                        cpiofh.seek(ch.dataoff, os.SEEK_SET)
                        with open(dst, 'wb') as fh:
                            while True:
                                buf = cpiofh.read(4096)
                                if buf is None or buf == b'':
                                    break
                                fh.write(buf)
        os.unlink(tmpfile)

        return liblist, debuglist
Exemplo n.º 4
0
    def extract(self, project, package, srcinfo, repo, arch):
            # fetch cpio headers
            # check file lists for library packages
            fetchlist, liblist = self.compute_fetchlist(project, package, srcinfo, repo, arch)

            if not fetchlist:
                msg = "no libraries found in %s/%s %s/%s"%(project, package, repo, arch)
                self.logger.info(msg)
                return None

            # mtimes in cpio are not the original ones, so we need to fetch
            # that separately :-(
            mtimes= self._getmtimes(project, package, repo, arch)

            self.logger.debug("fetchlist %s", pformat(fetchlist))
            self.logger.debug("liblist %s", pformat(liblist))

            debugfiles = set(['/usr/lib/debug%s.debug'%f for f in liblist])

            # fetch binary rpms
            downloaded = self.download_files(project, package, repo, arch, fetchlist, mtimes)

            # extract binary rpms
            tmpfile = os.path.join(CACHEDIR, "cpio")
            for fn in fetchlist:
                self.logger.debug("extract %s"%fn)
                with open(tmpfile, 'wb') as tmpfd:
                    if not fn in downloaded:
                        raise FetchError("%s was not downloaded!"%fn)
                    self.logger.debug(downloaded[fn])
                    r = subprocess.call(['rpm2cpio', downloaded[fn]], stdout=tmpfd, close_fds=True)
                    if r != 0:
                        raise FetchError("failed to extract %s!"%fn)
                    tmpfd.close()
                    cpio = CpioRead(tmpfile)
                    cpio.read()
                    for ch in cpio:
                        fn = ch.filename
                        if fn.startswith('./'): # rpm payload is relative
                            fn = fn[1:]
                        self.logger.debug("cpio fn %s", fn)
                        if not fn in liblist and not fn in debugfiles:
                            continue
                        dst = os.path.join(UNPACKDIR, project, package, repo, arch)
                        dst += fn
                        if not os.path.exists(os.path.dirname(dst)):
                            os.makedirs(os.path.dirname(dst))
                        self.logger.debug("dst %s", dst)
                        # the filehandle in the cpio archive is private so
                        # open it again
                        with open(tmpfile, 'rb') as cpiofh:
                            cpiofh.seek(ch.dataoff, os.SEEK_SET)
                            with open(dst, 'wb') as fh:
                                while True:
                                    buf = cpiofh.read(4096)
                                    if buf is None or buf == '':
                                        break
                                    fh.write(buf)
            os.unlink(tmpfile)

            return liblist
Exemplo n.º 5
0
                print str(e)
            h = None
        return h

    def _fetchcpioheaders(self, project, package, repo, arch):
        u = osc.core.makeurl(self.apiurl, [ 'build', project, repo, arch, package ],
            [ 'view=cpioheaders' ])
        try:
            r = osc.core.http_GET(u)
        except urllib2.HTTPError, e:
            raise FetchError('failed to fetch header information: %s'%e)
        tmpfile = NamedTemporaryFile(prefix="cpio-", delete=False)
        for chunk in r:
            tmpfile.write(chunk)
        tmpfile.close()
        cpio = CpioRead(tmpfile.name)
        cpio.read()
        rpm_re = re.compile('(.+\.rpm)-[0-9A-Fa-f]{32}$')
        for ch in cpio:
            # ignore errors
            if ch.filename == '.errors':
                continue
            # the filehandle in the cpio archive is private so
            # open it again
            with open(tmpfile.name, 'rb') as fh:
                fh.seek(ch.dataoff, os.SEEK_SET)
                h = self.readRpmHeaderFD(fh)
                if h is None:
                    raise FetchError("failed to read rpm header for %s"%ch.filename)
                m = rpm_re.match(ch.filename)
                if m: