Beispiel #1
0
    def _import_custom_archives(self):
        """
        Import custom tar archive files
        """
        archive_list = []
        system_archives = self.xml_state.get_system_archives()
        bootstrap_archives = self.xml_state.get_bootstrap_archives()
        if system_archives:
            archive_list += system_archives
        if bootstrap_archives:
            archive_list += bootstrap_archives

        description_target = self.root_dir + '/image/'

        for archive in archive_list:
            archive_is_absolute = archive.startswith('/')
            if archive_is_absolute:
                archive_file = archive
            else:
                archive_file = self.description_dir + '/' + archive

            archive_exists = os.path.exists(archive_file)

            if not archive_exists:
                if self.derived_description_dir and not archive_is_absolute:
                    archive_file = self.derived_description_dir + '/' + archive
                    archive_exists = os.path.exists(archive_file)

            if archive_exists:
                log.info('--> Importing %s archive as %s', archive_file,
                         'image/' + archive)
                Command.run(['cp', archive_file, description_target])
            else:
                raise KiwiImportDescriptionError(
                    'Specified archive %s does not exist' % archive_file)
Beispiel #2
0
    def _import_custom_scripts(self):
        """
        Import custom scripts
        """
        # custom_scripts defines a dictionary with all script hooks
        # for each script name a the filepath and additional flags
        # are defined. the filepath could be either a relative or
        # absolute information. If filepath is set to None this indicates
        # the script hook is not used. The raise_if_not_exists flag
        # causes kiwi to raise an exception if a specified script
        # filepath does not exist
        script_type = namedtuple('script_type',
                                 ['filepath', 'raise_if_not_exists'])
        custom_scripts = {
            'config.sh':
            script_type(filepath='config.sh', raise_if_not_exists=False),
            'images.sh':
            script_type(filepath='images.sh', raise_if_not_exists=False),
            'edit_boot_config.sh':
            script_type(
                filepath=self.xml_state.build_type.get_editbootconfig(),
                raise_if_not_exists=True),
            'edit_boot_install.sh':
            script_type(
                filepath=self.xml_state.build_type.get_editbootinstall(),
                raise_if_not_exists=True)
        }
        sorted_custom_scripts = OrderedDict(sorted(custom_scripts.items()))

        description_target = self.root_dir + '/image/'
        need_script_helper_functions = False

        for name, script in list(sorted_custom_scripts.items()):
            if script.filepath:
                if script.filepath.startswith('/'):
                    script_file = script.filepath
                else:
                    script_file = self.description_dir + '/' + script.filepath
                if os.path.exists(script_file):
                    log.info('--> Importing %s script as %s', script.filepath,
                             'image/' + name)
                    Command.run(['cp', script_file, description_target + name])
                    need_script_helper_functions = True
                elif script.raise_if_not_exists:
                    raise KiwiImportDescriptionError(
                        'Specified script %s does not exist' % script_file)

        if need_script_helper_functions:
            log.info('--> Importing script helper functions')
            Command.run([
                'cp',
                Defaults.get_common_functions_file(),
                self.root_dir + '/.kconfig'
            ])
Beispiel #3
0
    def _import_custom_archives(self):
        """
        Import custom tar archive files
        """
        archive_list = []
        system_archives = self.xml_state.get_system_archives()
        bootstrap_archives = self.xml_state.get_bootstrap_archives()
        if system_archives:
            archive_list += system_archives
        if bootstrap_archives:
            archive_list += bootstrap_archives

        archive_target_dir = os.path.join(
            self.root_dir, defaults.IMAGE_METADATA_DIR
        ) + os.sep

        for archive in archive_list:
            archive_is_absolute = archive.startswith(os.sep)
            if archive_is_absolute:
                archive_file = archive
            else:
                archive_file = os.path.join(self.description_dir, archive)

            archive_exists = os.path.exists(archive_file)

            if not archive_exists:
                if self.derived_description_dir and not archive_is_absolute:
                    archive_file = self.derived_description_dir + '/' + archive
                    archive_exists = os.path.exists(archive_file)

            if archive_exists:
                log.info(
                    '--> Importing {0} archive to {1}'.format(
                        archive_file, archive_target_dir
                    )
                )
                Command.run(
                    ['cp', archive_file, archive_target_dir]
                )
            else:
                raise KiwiImportDescriptionError(
                    'Specified archive {0} does not exist'.format(archive_file)
                )
Beispiel #4
0
    def _import_custom_scripts(self):
        """
        Import custom scripts
        """
        # custom_scripts defines a dictionary with all script hooks
        # for each script name a the filepath and additional flags
        # are defined. the filepath could be either a relative or
        # absolute information. If filepath is set to None this indicates
        # the script hook is not used. The raise_if_not_exists flag
        # causes kiwi to raise an exception if a specified script
        # filepath does not exist
        script_type = namedtuple('script_type',
                                 ['filepath', 'raise_if_not_exists'])
        custom_scripts = {
            defaults.POST_PREPARE_SCRIPT:
            script_type(filepath=defaults.POST_PREPARE_SCRIPT,
                        raise_if_not_exists=False),
            defaults.PRE_CREATE_SCRIPT:
            script_type(filepath=defaults.PRE_CREATE_SCRIPT,
                        raise_if_not_exists=False),
            defaults.POST_DISK_SYNC_SCRIPT:
            script_type(filepath=defaults.POST_DISK_SYNC_SCRIPT,
                        raise_if_not_exists=False),
            defaults.EDIT_BOOT_CONFIG_SCRIPT:
            script_type(
                filepath=self.xml_state.build_type.get_editbootconfig(),
                raise_if_not_exists=True),
            defaults.EDIT_BOOT_INSTALL_SCRIPT:
            script_type(
                filepath=self.xml_state.build_type.get_editbootinstall(),
                raise_if_not_exists=True)
        }
        sorted_custom_scripts = OrderedDict(sorted(custom_scripts.items()))

        script_target_dir = os.path.join(self.root_dir,
                                         defaults.IMAGE_METADATA_DIR)
        need_script_helper_functions = False

        for name, script in list(sorted_custom_scripts.items()):
            if script.filepath:
                if script.filepath.startswith('/'):
                    script_file = script.filepath
                else:
                    script_file = os.path.join(self.description_dir,
                                               script.filepath)
                if os.path.exists(script_file):
                    script_target_file = os.path.join(script_target_dir, name)
                    log.info('--> Importing {0} script to {1}'.format(
                        script.filepath, script_target_file))
                    Command.run(['cp', script_file, script_target_file])
                    need_script_helper_functions = True
                elif script.raise_if_not_exists:
                    raise KiwiImportDescriptionError(
                        'Specified script {0} does not exist'.format(
                            script_file))

        if need_script_helper_functions:
            log.info('--> Importing script helper functions')
            Command.run([
                'cp',
                Defaults.get_common_functions_file(),
                self.root_dir + '/.kconfig'
            ])