Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def link_database_to_host_path(self):
"""
Create a link from host database location to image database
location. The link is only created if both locations differ
and if the host database location does not exist.
"""
rpm_host_dbpath = self.rpmdb_host.expand_query('%_dbpath')
rpm_image_dbpath = self.rpmdb_image.expand_query('%_dbpath')
if rpm_host_dbpath != rpm_image_dbpath:
root_rpm_host_dbpath = os.path.normpath(
os.sep.join([self.root_dir, rpm_host_dbpath])
)
if not os.path.exists(root_rpm_host_dbpath):
Path.create(os.path.dirname(root_rpm_host_dbpath))
host_to_root = ''.join(
'../' for i in os.path.dirname(
rpm_host_dbpath
).lstrip(os.sep).split(os.sep)
)
Command.run(
[
'ln', '-s', os.path.normpath(
os.sep.join([host_to_root, rpm_image_dbpath])
), root_rpm_host_dbpath
]
boot_fonts_dir = os.path.normpath(
os.sep.join(
[
self.boot_dir,
self.get_boot_path(target),
self.boot_directory_name,
'fonts'
]
)
)
try:
unicode_font = Defaults.get_grub_path(
lookup_path, font_name
)
if not os.path.exists(os.sep.join([boot_fonts_dir, font_name])):
Path.create(boot_fonts_dir)
Command.run(
['cp', unicode_font, boot_fonts_dir]
)
if efi_font_dir:
Command.run(
['cp', unicode_font, efi_font_dir]
)
except Exception as issue:
raise KiwiBootLoaderGrubFontError(
'Setting up unicode font failed with {0}'.format(issue)
)
boot_theme_dir = os.sep.join(
[self.boot_dir, 'boot', self.boot_directory_name, 'themes']
)
Path.create(boot_theme_dir)
def import_description(self):
"""
Import XML descriptions, custom scripts, archives and
script helper methods
"""
log.info('Importing Image description to system tree')
description = os.path.join(
self.root_dir, defaults.image_metadata_directory, 'config.xml'
)
log.info(
'--> Importing state XML description to {0}'.format(description)
)
Path.create(
os.path.join(self.root_dir, defaults.image_metadata_directory)
)
with open(description, 'w', encoding='utf-8') as config:
config.write('')
self.xml_state.xml_data.export(outfile=config, level=0)
self._import_custom_scripts()
self._import_custom_archives()
self._import_cdroot_archive()
temp_boot_root_directory
)
data = DataSync(
self.boot_root_directory + '/',
temp_boot_root_directory
)
data.sync_data(
options=['-a']
)
boot_directory = temp_boot_root_directory + '/boot'
Path.wipe(boot_directory)
if mbrid:
log.info(
'--> Importing mbrid: %s', mbrid.get_id()
)
Path.create(boot_directory)
image_identifier = boot_directory + '/mbrid'
mbrid.write(image_identifier)
cpio = ArchiveCpio(
os.sep.join([self.target_dir, kiwi_initrd_basename])
)
# the following is a list of directories which were needed
# during the process of creating an image but not when the
# image is actually booting with this initrd
exclude_from_archive = [
'/' + Defaults.get_shared_cache_location(),
'/image', '/usr/lib/grub*'
]
# the following is a list of directories to exclude which
# are not needed inside of the initrd
exclude_from_archive += [
def _copy_grub_config_to_efi_path(self, root_path, config_file):
efi_boot_path = Defaults.get_shim_vendor_directory(
root_path
)
if not efi_boot_path:
efi_boot_path = os.path.normpath(
os.sep.join([root_path, 'EFI/BOOT'])
)
Path.create(efi_boot_path)
grub_config_file_for_efi_boot = os.sep.join(
[efi_boot_path, 'grub.cfg']
)
log.info(
'Copying {0} -> {1} to be found by EFI'.format(
config_file, grub_config_file_for_efi_boot
)
)
shutil.copy(
config_file, grub_config_file_for_efi_boot
)
)
else:
log.warning('Bypassing base image URI to OCI tools')
image_uri = self.unknown_uri
oci = OCI()
oci.import_container_image(image_uri)
oci.unpack()
oci.import_rootfs(self.root_dir)
# A copy of the uncompressed image and its checksum are
# kept inside the root_dir in order to ensure the later steps
# i.e. system create are atomic and don't need any third
# party archive.
image_copy = Defaults.get_imported_root_image(self.root_dir)
Path.create(os.path.dirname(image_copy))
oci.export_container_image(
image_copy, 'oci-archive', Defaults.get_container_base_image_tag()
)
self._make_checksum(image_copy)
def _create_zypper_runtime_environment(self):
for zypper_dir in list(self.shared_zypper_dir.values()):
Path.create(zypper_dir)
return dict(
os.environ,
LANG='C',
ZYPP_CONF=self.runtime_zypp_config_file.name
)
'Bundle directory must be different from target directory'
)
log.info(
'Bundle build results from %s', result_directory
)
result = Result.load(
result_directory + '/kiwi.result'
)
image_version = result.xml_state.get_image_version()
image_name = result.xml_state.xml_data.get_name()
ordered_results = OrderedDict(sorted(result.get_results().items()))
# hard link bundle files, compress and build checksum
if not os.path.exists(bundle_directory):
Path.create(bundle_directory)
for result_file in list(ordered_results.values()):
if result_file.use_for_bundle:
bundle_file_basename = os.path.basename(result_file.filename)
# The bundle id is only taken into account for image results
# which contains the image version appended in its file name
part_name = list(bundle_file_basename.partition(image_name))
bundle_file_basename = ''.join([
part_name[0], part_name[1],
part_name[2].replace(
image_version,
image_version + '-' + self.command_args['--id']
)
])
log.info('Creating %s', bundle_file_basename)
bundle_file = ''.join(
[bundle_directory, '/', bundle_file_basename]