Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:rtype: str
"""
lookup_paths = []
multipart_message = [
'"%s": ' % filename, 'exists: unknown', 'mode match: not checked'
]
system_path = os.environ.get('PATH')
if custom_env:
system_path = custom_env.get('PATH')
if system_path:
lookup_paths = system_path.split(os.pathsep)
if alternative_lookup_paths:
lookup_paths += alternative_lookup_paths
if root_dir:
lookup_paths = Path.rebase_to_root(root_dir, lookup_paths)
multipart_message[0] += 'in paths "%s"' % ':'.join(lookup_paths)
for path in lookup_paths:
location = os.path.join(path, filename)
file_exists = os.path.exists(location)
multipart_message[1] = 'exists: "%s"' % file_exists
if access_mode and file_exists:
mode_match = os.access(location, access_mode)
multipart_message[2] = 'mode match: "%s"' % mode_match
if mode_match:
return location
elif file_exists:
return location
log.debug(' '.join(multipart_message))
Exports the working container to a container image archive
:param str filename: The resulting filename
:param str transport: The archive format
:param str image_name: Name of the exported image
:param str image_tag: Tag of the exported image
:param list additional_tags: List of additional references
"""
extra_tags_opt = []
if additional_refs:
for ref in additional_refs:
extra_tags_opt.extend(['--additional-tag', ref])
# make sure the target tar file does not exist
# skopeo doesn't support force overwrite
Path.wipe(filename)
Command.run([
'skopeo', 'copy', 'oci:{0}'.format(self.working_image),
'{0}:{1}:{2}'.format(transport, filename, image_ref)
] + extra_tags_opt)
def __init__(self, data, style='standard'):
self.data = data
self.style = style
self.color_json = Path.which('pjson')
def get_tool_name(self):
"""
There are tools by J.Schilling and tools from the community
Depending on what is installed a decision needs to be made.
mkisofs is preferred over genisoimage
:raises KiwiIsoToolError: if no iso creation tool is found
:return: tool name
:rtype: str
"""
iso_creation_tools = ['mkisofs', 'genisoimage']
for tool in iso_creation_tools:
tool_found = Path.which(tool)
if tool_found:
return tool_found
raise KiwiIsoToolError(
'No iso creation tool found, searched for: {}'.format(
iso_creation_tools
)
def _get_grub2_mkconfig_tool(self):
for grub_mkconfig_tool in ['grub2-mkconfig', 'grub-mkconfig']:
grub_mkconfig_file_path = Path.which(
grub_mkconfig_tool, root_dir=self.root_dir
)
if grub_mkconfig_file_path:
return grub_mkconfig_file_path
if self.custom_args.get('efi_device'):
self.efi_mount = MountManager(
device=self.custom_args['efi_device'],
mountpoint=self.root_mount.mountpoint + '/boot/efi'
)
self.root_mount.mount()
if not self.root_mount.device == self.boot_mount.device:
self.boot_mount.mount()
if self.efi_mount:
self.efi_mount.mount()
if self.volumes:
for volume_path in Path.sort_by_hierarchy(
sorted(self.volumes.keys())
):
volume_mount = MountManager(
device=self.volumes[volume_path]['volume_device'],
mountpoint=self.root_mount.mountpoint + '/' + volume_path
)
self.volumes_mount.append(volume_mount)
volume_mount.mount(
options=[self.volumes[volume_path]['volume_options']]
)
self.device_mount = MountManager(
device='/dev',
mountpoint=self.root_mount.mountpoint + '/dev'
)
self.proc_mount = MountManager(
def _load_boot_image_instance(self):
boot_image_dump_file = self.target_dir + '/boot_image.pickledump'
if not os.path.exists(boot_image_dump_file):
raise KiwiInstallMediaError(
'No boot image instance dump %s found' % boot_image_dump_file
)
try:
with open(boot_image_dump_file, 'rb') as boot_image_dump:
boot_image = pickle.load(boot_image_dump)
Path.wipe(boot_image_dump_file)
except Exception as e:
raise KiwiInstallMediaError(
'Failed to load boot image dump: %s' % type(e).__name__
)
return boot_image
def mount_volumes(self):
"""
Mount lvm volumes
"""
for volume_mount in self.mount_list:
Path.create(volume_mount.mountpoint)
volume_mount.mount(
options=[self.mount_options]
)
self.volumes_mounted_initially = True
def _cleanup_tempdirs(self):
for directory in self.temp_directories:
Path.wipe(directory)
if efi_device:
self.efi_mount = MountManager(
device=efi_device,
mountpoint=self.root_mount.mountpoint + '/boot/efi'
)
self.root_mount.mount()
if not self.root_mount.device == self.boot_mount.device:
self.boot_mount.mount()
if efi_device:
self.efi_mount.mount()
if volumes:
for volume_path in Path.sort_by_hierarchy(
sorted(volumes.keys())
):
volume_mount = MountManager(
device=volumes[volume_path]['volume_device'],
mountpoint=self.root_mount.mountpoint + '/' + volume_path
)
self.volumes_mount.append(volume_mount)
volume_mount.mount(
options=[volumes[volume_path]['volume_options']]
)
if self.root_filesystem_is_overlay:
# In case of an overlay root system all parts of the rootfs
# are read-only by squashfs except for the extra boot partition.
# However tools like grub's mkconfig creates temporary files
# at call time and therefore /tmp needs to be writable during