Example #1
0
    def get_kernel(self, raise_on_not_found=False):
        """
        Lookup kernel files and provide filename and version

        :param bool raise_on_not_found: sets the method to raise an exception
            if the kernel is not found

        :raises KiwiKernelLookupError: if raise_on_not_found flag is active
            and kernel is not found
        :return: tuple with filename, kernelname and version

        :rtype: namedtuple
        """
        for kernel_name in self.kernel_names:
            kernel_file = os.sep.join([self.root_dir, 'boot', kernel_name])
            if os.path.exists(kernel_file):
                version_match = re.match('.*?-(.*)',
                                         os.path.basename(kernel_file))
                if version_match:
                    version = version_match.group(1)
                    kernel = namedtuple('kernel',
                                        ['name', 'filename', 'version'])
                    return kernel(name=os.path.basename(
                        os.path.realpath(kernel_file)),
                                  filename=kernel_file,
                                  version=version)

        if raise_on_not_found:
            raise KiwiKernelLookupError(
                'No kernel found in {0}, searched for {1}'.format(
                    os.sep.join([self.root_dir, 'boot']),
                    ','.join(self.kernel_names)))
Example #2
0
    def get_kernel(self, raise_on_not_found=False):
        """
        Lookup kernel files and provide filename and version

        :param bool raise_on_not_found: sets the method to raise an exception
            if the kernel is not found

        :raises KiwiKernelLookupError: if raise_on_not_found flag is active
            and kernel is not found
        :return: tuple with filename, kernelname and version

        :rtype: namedtuple
        """
        for kernel_name in self.kernel_names:
            kernel_file = os.sep.join([self.root_dir, 'boot', kernel_name])
            if os.path.exists(kernel_file):
                kernel_file_for_version_check = \
                    self._get_kernel_name_for_version_lookup()
                if not kernel_file_for_version_check:
                    # The system does not provide a gzip compressed binary
                    # of the kernel. Thus we try to fetch the version from
                    # the arbitrary kernel image format. Please Note:
                    # kernel images that contains the decompressor code
                    # as part of the kernel could have been compressed by
                    # any possible compression algorithm. For such kernels
                    # the simple kversion utility will not be able to read
                    # kernel version
                    kernel_file_for_version_check = kernel_file

                version = Command.run(
                    command=['kversion', kernel_file_for_version_check],
                    raise_on_error=False).output
                if not version:
                    version = 'no-version-found'
                version = version.rstrip('\n')
                kernel = namedtuple('kernel', ['name', 'filename', 'version'])
                return kernel(name=os.path.basename(
                    os.path.realpath(kernel_file)),
                              filename=kernel_file,
                              version=version)

        if raise_on_not_found:
            raise KiwiKernelLookupError(
                'No kernel found in {0}, searched for {1}'.format(
                    os.sep.join([self.root_dir, 'boot']),
                    ','.join(self.kernel_names)))
Example #3
0
File: kernel.py Project: agraf/kiwi
    def get_kernel(self, raise_on_not_found=False):
        """
        Lookup kernel files and provide filename and version

        :return: tuple with filename, kernelname and version
        :rtype: namedtuple
        """
        for kernel_name in self.kernel_names:
            kernel_file = self.root_dir + '/boot/' + kernel_name
            if os.path.exists(kernel_file):
                kernel_file_to_check = kernel_file
                if 'zImage' in kernel_file_to_check:
                    # kernels build as zImage contains the decompressor code
                    # as part of the kernel image and could be therefore
                    # compressed by any possible compression algorithm.
                    # In this case we assume/hope that there is also a
                    # standard gz compressed vmlinux version of the kernel
                    # available and check this one instead of the zImage
                    # variant
                    kernel_file_to_check = kernel_file_to_check.replace(
                        'zImage', 'vmlinux'
                    ) + '.gz'
                version = Command.run(
                    command=['kversion', kernel_file_to_check],
                    raise_on_error=False
                ).output
                if not version:
                    version = 'no-version-found'
                version = version.rstrip('\n')
                kernel = namedtuple(
                    'kernel', ['name', 'filename', 'version']
                )
                return kernel(
                    name=os.path.basename(os.path.realpath(kernel_file)),
                    filename=kernel_file,
                    version=version
                )

        if raise_on_not_found:
            raise KiwiKernelLookupError(
                'No kernel found in {0}, searched for {1}'.format(
                    os.sep.join([self.root_dir, 'boot']),
                    ','.join(self.kernel_names)
                )
            )