Example #1
0
    def __init__(self, stream):
        self.packaging = 'deb'
        self.signatures = []
        self.is_source = 0
        self.deb = None

        try:
            self.deb = debfile.DebFile(stream.name)
        except Exception, e:
            raise InvalidPackageError(e), None, sys.exc_info()[2]
Example #2
0
class deb_Header:

    "Wrapper class for an deb header - we need to store a flag is_source"

    def __init__(self, stream):
        self.packaging = 'deb'
        self.signatures = []
        self.is_source = 0
        self.deb = None

        try:
            self.deb = debfile.DebFile(stream.name)
        except Exception, e:
            raise InvalidPackageError(e), None, sys.exc_info()[2]

        try:
            # Fill info about package
            debcontrol = self.deb.debcontrol()
            self.hdr = {
                'name': debcontrol.get_as_string('Package'),
                'arch': debcontrol.get_as_string('Architecture') + '-deb',
                'summary':
                debcontrol.get_as_string('Description').splitlines()[0],
                'vendor': debcontrol.get_as_string('Maintainer'),
                'package_group': debcontrol.get_as_string('Section'),
                'epoch': '',
                'version': 0,
                'release': 0,
                'description': debcontrol.get_as_string('Description'),
            }
            for hdr_k, deb_k in [('requires', 'Depends'),
                                 ('provides', 'Provides'),
                                 ('conflicts', 'Conflicts'),
                                 ('obsoletes', 'Replaces'),
                                 ('recommends', 'Recommends'),
                                 ('suggests', 'Suggests'),
                                 ('breaks', 'Breaks'),
                                 ('predepends', 'Pre-Depends'),
                                 ('payload_size', 'Installed-Size')]:
                if debcontrol.has_key(deb_k):
                    self.hdr[hdr_k] = debcontrol.get_as_string(deb_k)
            for k in debcontrol.keys():
                if not self.hdr.has_key(k):
                    self.hdr[k] = debcontrol.get_as_string(k)

            version = debcontrol.get_as_string('Version')
            version_tmpArr = version.split('-')
            if len(version_tmpArr) == 1:
                self.hdr['version'] = version
                self.hdr['release'] = "X"
            else:
                self.hdr['version'] = version_tmpArr[0]
                self.hdr['release'] = version_tmpArr[1]
        except Exception, e:
            raise InvalidPackageError(e), None, sys.exc_info()[2]
Example #3
0
 def read_header(self):
     arr = self._read_lead(self.input_stream)
     magic = arr[0]
     if magic != self._magic:
         raise InvalidPackageError()
     header_len, payload_len = int(arr[5]), int(arr[6])
     self.header_flags, self.payload_flags = arr[3], arr[4]
     self.file_size = 128 + header_len + payload_len
     header_data = self._read_bytes(self.input_stream, header_len)
     self._read_header(header_data, self.header_flags)
     self.checksum_type = self.header.checksum_type()
Example #4
0
    def load(self, input_stream):
        # Clean up
        self.__init__()
        self.input_stream = input_stream
        # Read the header
        self.read_header()

        payload_stream = fileutils.payload(input_stream.name, input_stream.tell())
        input_stream.seek(self.file_size)
        if self.file_size != input_stream.tell():
            raise InvalidPackageError()

        self._read_payload(payload_stream, self.payload_flags)
Example #5
0
class RPM_Package(A_Package):
    # pylint: disable=R0902
    def __init__(self, input_stream=None):
        A_Package.__init__(self, input_stream)
        self.header_data = tempfile.SpooledTemporaryFile()

    def read_header(self):
        self._get_header_byte_range()
        try:
            self.header = get_package_header(file_obj=self.header_data)
        except InvalidPackageError, e:
            raise InvalidPackageError(*e.args), None, sys.exc_info()[2]
        except error, e:
            raise InvalidPackageError(e), None, sys.exc_info()[2]
Example #6
0
    def _read_lead(self, stream):
        # Lead has the following format:
        # 16 bytes  magic
        #  1 bytes  version
        #  3 bytes  unused
        #  4 bytes  header flags
        #  4 bytes  payload flags
        #  4 bytes  header length
        #  4 bytes  payload length
        # 92 bytes  padding to 128 bytes
        lead = self._read_bytes(stream, 128)
        if len(lead) != 128:
            raise InvalidPackageError()

        arr = struct.unpack(self._lead_format, lead)
        return arr
Example #7
0
def load_rpm(stream):
    # Hmm, maybe an rpm

    try:
        import rhn_rpm
    except ImportError:
        raise InvalidPackageError, None, sys.exc_info()[2]

    # Dup the file descriptor, we don't want it to get closed before we read
    # the payload
    newfd = os.dup(stream.fileno())
    stream = os.fdopen(newfd, "r")

    stream.flush()
    stream.seek(0, 0)

    try:
        header = rhn_rpm.get_package_header(file_obj=stream)
    except InvalidPackageError, e:
        raise InvalidPackageError(*e.args), None, sys.exc_info()[2]
Example #8
0
        raise InvalidPackageError, None, sys.exc_info()[2]

    # Dup the file descriptor, we don't want it to get closed before we read
    # the payload
    newfd = os.dup(stream.fileno())
    stream = os.fdopen(newfd, "r")

    stream.flush()
    stream.seek(0, 0)

    try:
        header = rhn_rpm.get_package_header(file_obj=stream)
    except InvalidPackageError, e:
        raise InvalidPackageError(*e.args), None, sys.exc_info()[2]
    except rhn_rpm.error, e:
        raise InvalidPackageError(e), None, sys.exc_info()[2]
    except:
        raise InvalidPackageError, None, sys.exc_info()[2]
    stream.seek(0, 0)

    return header, stream


class MPM_Header:
    "Wrapper class for an mpm header - we need to store a flag is_source"

    def __init__(self, hdr):
        self.hdr = hdr
        self.is_source = hdr.get('is_source')
        self.packaging = 'mpm'
        self.signatures = []
Example #9
0
 def read_header(self):
     self._get_header_byte_range()
     try:
         self.header = get_package_header(file_obj=self.header_data)
     except InvalidPackageError, e:
         raise InvalidPackageError(*e.args), None, sys.exc_info()[2]