Пример #1
0
    def _fileFeatures(filePath):
        """ From a filepath, construct a dictionary of file features. """
        # pylint: disable=W0702
        log_debug(3, filePath)
        if not filePath:
            raise rhnFault(
                17,
                "While looking for file: `%s'" % os.path.basename(filePath))
        try:
            s = os.stat(filePath)
        except:
            s = None
        if not s:
            l = 0
            lastModified = 0
        else:
            l = s[stat.ST_SIZE]
            lastModified = s[stat.ST_MTIME]
        del s

        # Build the result hash
        result = {}
        result['name'] = os.path.basename(filePath)
        result['length'] = l
        result['path'] = filePath
        if lastModified:
            result['lastModified'] = rfc822time(lastModified)
        else:
            result['lastModified'] = None
        return result
Пример #2
0
    def _fileFeatures(filePath):
        """ From a filepath, construct a dictionary of file features. """
        # pylint: disable=W0702
        log_debug(3, filePath)
        if not filePath:
            raise rhnFault(17, "While looking for file: `%s'"
                               % os.path.basename(filePath))
        try:
            s = os.stat(filePath)
        except:
            s = None
        if not s:
            l = 0
            lastModified = 0
        else:
            l = s[stat.ST_SIZE]
            lastModified = s[stat.ST_MTIME]
        del s

        # Build the result hash
        result = {}
        result['name'] = os.path.basename(filePath)
        result['length'] = l
        result['path'] = filePath
        if lastModified:
            result['lastModified'] = rfc822time(lastModified)
        else:
            result['lastModified'] = None
        return result
Пример #3
0
    def _getHeaderFromFile(self, filePath, stat_info=None):
        """ Utility function to extract a header from an rpm.
            If stat_info was already passed, don't re-stat the file
        """
        log_debug(3, filePath)
        if stat_info:
            s = stat_info
        else:
            s = None
            try:
                s = os.stat(filePath)
            except:
                raise rhnFault(
                    17, "Unable to read package %s" %
                    os.path.basename(filePath)), None, sys.exc_info()[2]

        lastModified = s[stat.ST_MTIME]
        del s  # XXX: not neccessary?

        # Get the package header from the file
        # since we stat()ed the file, we know it's there already
        fd = os.open(filePath, os.O_RDONLY)
        h = rhn_rpm.get_package_header(fd=fd)
        os.close(fd)
        if h is None:
            raise rhnFault(17, "Invalid RPM %s" % os.path.basename(filePath))
        stringIO = cStringIO.StringIO()
        # Put the result in stringIO
        stringIO.write(h.unload())
        del h  # XXX: not neccessary?

        pkgFilename = os.path.basename(filePath)
        pkg = pkgFilename.split('.')
        # Replace .rpm with .hdr
        pkg[-1] = "hdr"
        pkgFilename = ".".join(pkg)
        extra_headers = {
            'X-RHN-Package-Header': pkgFilename,
        }
        self._set_last_modified(lastModified, extra_headers=extra_headers)
        rhnFlags.set("AlreadyEncoded", 1)
        return stringIO.getvalue()
Пример #4
0
    def _getHeaderFromFile(self, filePath, stat_info=None):
        """ Utility function to extract a header from an rpm.
            If stat_info was already passed, don't re-stat the file
        """
        log_debug(3, filePath)
        if stat_info:
            s = stat_info
        else:
            s = None
            try:
                s = os.stat(filePath)
            except:
                raise rhnFault(17, "Unable to read package %s"
                                   % os.path.basename(filePath)), None, sys.exc_info()[2]

        lastModified = s[stat.ST_MTIME]
        del s # XXX: not neccessary?

        # Get the package header from the file
        # since we stat()ed the file, we know it's there already
        fd = os.open(filePath, os.O_RDONLY)
        h = rhn_rpm.get_package_header(fd=fd)
        os.close(fd)
        if h is None:
            raise rhnFault(17, "Invalid RPM %s" % os.path.basename(filePath))
        stringIO = cStringIO.StringIO()
        # Put the result in stringIO
        stringIO.write(h.unload())
        del h # XXX: not neccessary?

        pkgFilename = os.path.basename(filePath)
        pkg = pkgFilename.split('.')
        # Replace .rpm with .hdr
        pkg[-1] = "hdr"
        pkgFilename = ".".join(pkg)
        extra_headers = {
            'X-RHN-Package-Header' : pkgFilename,
        }
        self._set_last_modified(lastModified, extra_headers=extra_headers)
        rhnFlags.set("AlreadyEncoded", 1)
        return stringIO.getvalue()
Пример #5
0
    def getPackageHeader(self, pkgFilename):
        """ Get rpm header.
            XXX: stock 8.0 clients could not compress headers, we need to either
            change the function name, or version the protocol
        """
        log_debug(3, pkgFilename)
        pkg = pkgFilename.split('.')
        # Basic sanity checks:
        if pkg[-1] not in ["hdr", 'rpm']:
            raise rhnFault(21, "'%s' not a valid RPM header name" % pkgFilename)

        pkgFilename = ".".join(pkg[:-1]) + '.rpm'
        filePath = self.getPackagePath(pkgFilename)
        data = self._getHeaderFromFile(filePath)
        # XXX: Interesting. Found that if returned just data, this
        #      function works fine. Investigate later.
        return rpclib.transports.File(cStringIO.StringIO(data), len(data))
Пример #6
0
    def getPackageHeader(self, pkgFilename):
        """ Get rpm header.
            XXX: stock 8.0 clients could not compress headers, we need to either
            change the function name, or version the protocol
        """
        log_debug(3, pkgFilename)
        pkg = pkgFilename.split('.')
        # Basic sanity checks:
        if pkg[-1] not in ["hdr", 'rpm']:
            raise rhnFault(21,
                           "'%s' not a valid RPM header name" % pkgFilename)

        pkgFilename = ".".join(pkg[:-1]) + '.rpm'
        filePath = self.getPackagePath(pkgFilename)
        data = self._getHeaderFromFile(filePath)
        # XXX: Interesting. Found that if returned just data, this
        #      function works fine. Investigate later.
        return rpclib.transports.File(cStringIO.StringIO(data), len(data))