Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
''')
firmware = FirmWare(self.xml_state)
if Defaults.is_x86_arch(
Defaults.get_platform_name()
) and not firmware.efi_mode():
image_builds_iso = False
build_type = self.xml_state.get_build_type_name()
if build_type == 'iso':
image_builds_iso = True
elif build_type == 'oem':
install_iso = self.xml_state.build_type.get_installiso()
install_stick = self.xml_state.build_type.get_installstick()
if install_iso or install_stick:
image_builds_iso = True
if image_builds_iso:
syslinux_check_file = Path.which(
'isohdpfx.bin', Defaults.get_syslinux_search_paths()
)
if not syslinux_check_file:
raise KiwiRuntimeError(message)
def _get_shim_install(self):
return Path.which(
filename='shim-install', root_dir=self.boot_dir
)
def _get_boot_image_output_file_format_from_dracut_code(self):
dracut_tool = Path.which(
'dracut', root_dir=self.boot_root_directory, access_mode=os.X_OK
)
if dracut_tool:
outfile_expression = r'outfile="/boot/(init.*\$kernel.*)"'
with open(dracut_tool) as dracut:
matches = re.findall(outfile_expression, dracut.read())
if matches:
return matches[0].replace('$kernel', '{kernel_version}')
def create_image_format(self):
"""
Create ova disk format using ovftool from
https://www.vmware.com/support/developer/ovf
"""
# Check for required ovftool
ovftool = Path.which(filename='ovftool', access_mode=os.X_OK)
if not ovftool:
tool_not_found_message = dedent('''\n
Required tool {0} not found in PATH on the build host
Building OVA images requires VMware's {0} tool which
can be installed from the following location
https://www.vmware.com/support/developer/ovf
''')
raise KiwiCommandNotFound(
tool_not_found_message.format(ovftool)
)
# Create the vmdk disk image and vmx config
self.vmdk.create_image_format()
[
'cp', result_file.filename, bundle_file
]
)
if result_file.compress:
log.info('--> XZ compressing')
compress = Compress(bundle_file)
compress.xz(self.runtime_config.get_xz_options())
bundle_file = compress.compressed_filename
if self.command_args['--zsync-source'] and result_file.shasum:
# Files with a checksum are considered to be image files
# and are therefore eligible to be provided via the
# requested Partial/differential file download based on
# zsync
zsyncmake = Path.which('zsyncmake', access_mode=os.X_OK)
if zsyncmake:
log.info('--> Creating zsync control file')
Command.run(
[
zsyncmake, '-e', '-u', os.sep.join(
[
self.command_args['--zsync-source'],
os.path.basename(bundle_file)
]
), '-o', bundle_file + '.zsync', bundle_file
]
)
else:
log.warning(
'--> zsyncmake missing, zsync setup skipped'
)
def setup_plymouth_splash(self):
"""
Setup the KIWI configured splash theme as default
The method uses the plymouth-set-default-theme tool to setup the
theme for the plymouth splash system. Only in case the tool could
be found in the image root, it is assumed plymouth splash is in
use and the tool is called in a chroot operation
"""
theme_setup = 'plymouth-set-default-theme'
if Path.which(filename=theme_setup, root_dir=self.root_dir):
for preferences in self.xml_state.get_preferences_sections():
splash_section_content = preferences.get_bootsplash_theme()
if splash_section_content:
splash_theme = splash_section_content[0]
Command.run(
['chroot', self.root_dir, theme_setup, splash_theme]
)
def get_grub_boot_directory_name(lookup_path):
"""
Provides grub2 data directory name in boot/ directory
Depending on the distribution the grub2 boot path could be
either boot/grub2 or boot/grub. The method will decide for
the correct base directory name according to the name pattern
of the installed grub2 tools
:return: directory basename
:rtype: str
"""
if Path.which(filename='grub2-install', root_dir=lookup_path):
# the presence of grub2-install is an indicator to put all
# grub2 data below boot/grub2
return 'grub2'
else:
# in any other case the assumption is made that all grub
# boot data should live below boot/grub
return 'grub'
def check_mediacheck_installed(self):
"""
If the image description enables the mediacheck attribute
the required tools to run this check must be installed
on the image build host
"""
message_tool_not_found = dedent('''\n
Required tool {name} not found in caller environment
The attribute 'mediacheck' is set to 'true' which requires
the above tool to be installed on the build system
''')
if self.xml_state.build_type.get_mediacheck() is True:
tool = 'tagmedia'
if not Path.which(filename=tool, access_mode=os.X_OK):
raise KiwiRuntimeError(
message_tool_not_found.format(name=tool)
)
def _get_isoinfo_tool(self):
"""
There are tools by J.Schilling and tools from the community
This method searches in all paths which could provide an
isoinfo tool. The first match makes the decision
:raises KiwiIsoToolError: if no isoinfo tool found
:return: the isoinfo tool to use
:rtype: str
"""
alternative_lookup_paths = ['/usr/lib/genisoimage']
isoinfo = Path.which('isoinfo', alternative_lookup_paths)
if isoinfo:
return isoinfo
raise KiwiIsoToolError(
'No isoinfo tool found, searched in PATH: %s and %s' %
(os.environ.get('PATH'), alternative_lookup_paths)
)