本文整理汇总了Python中kiwi.path.Path.which方法的典型用法代码示例。如果您正苦于以下问题:Python Path.which方法的具体用法?Python Path.which怎么用?Python Path.which使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kiwi.path.Path
的用法示例。
在下文中一共展示了Path.which方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_shim_install
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _get_shim_install(self):
chroot_env = {
'PATH': os.sep.join([self.root_dir, 'usr', 'sbin'])
}
return Path.which(
filename='shim-install', custom_env=chroot_env
)
示例2: _get_dracut_output_file_format
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _get_dracut_output_file_format(self):
"""
Unfortunately the dracut initrd output file format varies between
the different Linux distributions. Tools like lsinitrd, and also
grub2 rely on the initrd output file to be in that format.
Thus when kiwi uses dracut the same file format should be used
all over the place in order to stay compatible with what the
distribution does
"""
default_outfile_format = 'initramfs-{kernel_version}.img'
dracut_search_env = {
'PATH': os.sep.join([self.boot_root_directory, 'usr', 'bin'])
}
dracut_tool = Path.which(
'dracut', custom_env=dracut_search_env, access_mode=os.X_OK
)
if dracut_tool:
outfile_expression = r'outfile="/boot/(init.*\$kernel.*)"'
with open(dracut_tool) as dracut:
outfile = re.findall(outfile_expression, dracut.read())[0]
if outfile:
return outfile.replace('$kernel', '{kernel_version}')
log.warning('Could not detect dracut output file format')
log.warning('Using default initrd file name format {0}'.format(
default_outfile_format
))
return default_outfile_format
示例3: test_which_not_found_log
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def test_which_not_found_log(
self, mock_log, mock_exists, mock_env, mock_access
):
mock_env.return_value = '/usr/local/bin:/usr/bin:/bin'
mock_exists.return_value = False
assert Path.which('file') is None
mock_log.assert_called_once_with(
'"file": in paths "%s" exists: "False" mode match: not checked' %
mock_env.return_value
)
示例4: test_which_not_found_for_mode_log
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def test_which_not_found_for_mode_log(
self, mock_log, mock_exists, mock_env, mock_access
):
mock_env.return_value = '/usr/local/bin:/usr/bin:/bin'
mock_exists.return_value = True
mock_access.return_value = False
assert Path.which('file', access_mode=os.X_OK) is None
mock_log.assert_called_once_with(
'"file": in paths "%s" exists: "True" mode match: "False"' %
mock_env.return_value
)
示例5: _get_tool_name
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _get_tool_name(
self, root_path, lookup_list, fallback_on_not_found=True
):
chroot_env = {'PATH': os.sep.join([root_path, 'usr', 'sbin'])}
for tool in lookup_list:
if Path.which(filename=tool, custom_env=chroot_env):
return tool
if fallback_on_not_found:
# no tool from the list was found, we intentionally don't
# raise here but return the default tool name and raise
# an exception at invocation time in order to log the
# expected call and its arguments
return lookup_list[0]
示例6: init_iso_creation_parameters
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def init_iso_creation_parameters(self, custom_args=None):
"""
Create a set of standard parameters
:param list custom_args: custom ISO meta data
"""
if custom_args:
if 'mbr_id' in custom_args:
self.iso_parameters += [
'-application_id', custom_args['mbr_id']
]
if 'publisher' in custom_args:
self.iso_parameters += [
'-publisher', custom_args['publisher']
]
if 'preparer' in custom_args:
self.iso_parameters += [
'-preparer_id', custom_args['preparer']
]
if 'volume_id' in custom_args:
self.iso_parameters += [
'-volid', custom_args['volume_id']
]
catalog_file = self.boot_path + '/boot.catalog'
self.iso_parameters += [
'-joliet', 'on', '-padding', '0'
]
loader_file = self.boot_path + '/loader/isolinux.bin'
syslinux_lookup_paths = [
'/usr/share/syslinux', '/usr/lib/syslinux/modules/bios'
]
mbr_file = Path.which('isohdpfx.bin', syslinux_lookup_paths)
if not mbr_file:
raise KiwiIsoToolError(
'isohdpfx.bin not found in {0}'.format(syslinux_lookup_paths)
)
self.iso_loaders += [
'-boot_image', 'any', 'partition_offset=16',
'-boot_image', 'isolinux', 'bin_path={0}'.format(loader_file),
'-boot_image', 'isolinux', 'system_area={0}'.format(mbr_file),
'-boot_image', 'isolinux', 'partition_table=on',
'-boot_image', 'any', 'cat_path={0}'.format(catalog_file),
'-boot_image', 'any', 'cat_hidden=on',
'-boot_image', 'any', 'boot_info_table=on',
'-boot_image', 'any', 'platform_id=0x00',
'-boot_image', 'any', 'emul_type=no_emulation',
'-boot_image', 'any', 'load_size=2048'
]
示例7: get_tool_name
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def get_tool_name(self):
"""
Lookup xorriso in search path
:raises KiwiIsoToolError: if xorriso tool is not found
:return: xorriso tool path
:rtype: str
"""
xorriso = Path.which('xorriso')
if xorriso:
return xorriso
raise KiwiIsoToolError('xorriso tool not found')
示例8: _find_iso_creation_tool
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _find_iso_creation_tool(self):
"""
There are tools by J.Schilling and tools from the community
Depending on what is installed a decision needs to be made
"""
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: %s' %
iso_creation_tools
)
示例9: create_image_format
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
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
super(DiskFormatOva, self).create_image_format()
# Convert to ova using ovftool
vmx = self.get_target_file_path_for_format('vmx')
ova = self.get_target_file_path_for_format('ova')
try:
os.unlink(ova)
except OSError:
pass
ovftool_options = []
if CommandCapabilities.has_option_in_help(
ovftool, '--shaAlgorithm', raise_on_error=False
):
ovftool_options.append('--shaAlgorithm=SHA1')
Command.run(
[ovftool] + ovftool_options + [vmx, ova]
)
# ovftool ignores the umask and creates files with 0600
# apply file permission bits set in the vmx file to the
# ova file
st = os.stat(vmx)
os.chmod(ova, stat.S_IMODE(st.st_mode))
示例10: _get_yum_binary_name
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _get_yum_binary_name(self, root=None):
"""
Identify whether yum is 'yum' or 'yum-deprecated'
:param string root: lookup binary name below this root directory
:return: name of yum command
"""
yum_binary = 'yum'
yum_search_env = {
'PATH': os.sep.join([root, 'usr', 'bin'])
} if root else None
if Path.which(
filename='yum-deprecated',
custom_env=yum_search_env,
access_mode=os.X_OK
):
yum_binary = 'yum-deprecated'
return yum_binary
示例11: _get_isoinfo_tool
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
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)
)
示例12: setup_plymouth_splash
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
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
"""
chroot_env = {
'PATH': os.sep.join([self.root_dir, 'usr', 'sbin'])
}
theme_setup = 'plymouth-set-default-theme'
if Path.which(filename=theme_setup, custom_env=chroot_env):
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]
)
示例13: get_tool_name
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
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: %s'.format(
iso_creation_tools
)
)
示例14: _create_efi_image
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def _create_efi_image(self, uuid=None, mbrid=None, lookup_path=None):
early_boot_script = self.efi_boot_path + '/earlyboot.cfg'
if uuid:
self._create_early_boot_script_for_uuid_search(
early_boot_script, uuid
)
else:
self._create_early_boot_script_for_mbrid_search(
early_boot_script, mbrid
)
for grub_mkimage_tool in ['grub2-mkimage', 'grub-mkimage']:
if Path.which(grub_mkimage_tool):
break
Command.run(
[
grub_mkimage_tool,
'-O', Defaults.get_efi_module_directory_name(self.arch),
'-o', self._get_efi_image_name(),
'-c', early_boot_script,
'-p', self.get_boot_path() + '/' + self.boot_directory_name,
'-d', self._get_efi_modules_path(lookup_path)
] + Defaults.get_grub_efi_modules(multiboot=self.xen_guest)
)
示例15: test_which
# 需要导入模块: from kiwi.path import Path [as 别名]
# 或者: from kiwi.path.Path import which [as 别名]
def test_which(self, mock_exists, mock_env, mock_access):
mock_env.return_value = '/usr/local/bin:/usr/bin:/bin'
mock_exists.return_value = True
assert Path.which('some-file') == '/usr/local/bin/some-file'
mock_exists.return_value = False
assert Path.which('some-file') is None
mock_env.return_value = None
mock_exists.return_value = True
assert Path.which('some-file', ['alternative']) == \
'alternative/some-file'
mock_access.return_value = False
mock_env.return_value = '/usr/local/bin:/usr/bin:/bin'
assert Path.which('some-file', access_mode=os.X_OK) is None
mock_access.return_value = True
assert Path.which('some-file', access_mode=os.X_OK) == \
'/usr/local/bin/some-file'
assert Path.which('some-file', custom_env={'PATH': 'custom_path'}) == \
'custom_path/some-file'