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' ])
def run_common_function(self, name, parameters): """ Run a function implemented in config/functions.sh :param str name: function name :param list parameters: function arguments """ Command.run([ 'bash', '-c', 'source ' + Defaults.get_common_functions_file() + '; ' + name + ' ' + ' '.join(parameters) ])
def run_common_function(name: str, parameters: List[str]) -> None: """ Run a function implemented in config/functions.sh :param str name: function name :param list parameters: function arguments """ Command.run([ 'bash', '-c', 'source ' + ''.join([ Defaults.get_common_functions_file(), '; ', name, ' ', ' '.join(parameters) ]) ])
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' ])
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' ] )