Skip to content

Commit b4389ac

Browse files
authored
Merge pull request #2829 from dirkmueller/fstrings
Use f-strings where feasible
2 parents f4b569c + 28ed67e commit b4389ac

File tree

35 files changed

+705
-720
lines changed

35 files changed

+705
-720
lines changed

kiwi/boot/image/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484

8585
if not os.path.exists(target_dir):
8686
raise KiwiTargetDirectoryNotFound(
87-
'target directory %s not found' % target_dir
87+
f'target directory {target_dir} not found'
8888
)
8989

9090
self.initrd_base_name = ''.join(
@@ -223,8 +223,7 @@ def get_boot_names(self) -> boot_names_type:
223223
kernel_version='none', kernel_filename='none'
224224
)
225225
raise KiwiDiskBootImageError(
226-
'No kernel in boot image tree %s found' %
227-
self.boot_root_directory
226+
f'No kernel in boot image tree {self.boot_root_directory} found'
228227
)
229228
dracut_output_format = self._get_boot_image_output_file_format(
230229
kernel_info.version
@@ -294,8 +293,7 @@ def load_boot_xml_description(self) -> None:
294293
boot_config_file = boot_description_directory + '/config.xml'
295294
if not os.path.exists(boot_config_file):
296295
raise KiwiConfigFileNotFound(
297-
'no Boot XML description found in %s' %
298-
boot_description_directory
296+
f'no Boot XML description found in {boot_description_directory}'
299297
)
300298
boot_description = XMLDescription(
301299
description=boot_config_file,

kiwi/bootloader/config/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def get_boot_path(self, target='disk'):
381381
"""
382382
if target != 'disk' and target != 'iso':
383383
raise KiwiBootLoaderTargetError(
384-
'Invalid boot loader target %s' % target
384+
f'Invalid boot loader target {target}'
385385
)
386386
bootpath = '/boot'
387387
need_boot_partition = False

kiwi/bootloader/config/grub2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def post_init(self, custom_args):
104104
self.arch = arch
105105
else:
106106
raise KiwiBootLoaderGrubPlatformError(
107-
'host architecture %s not supported for grub2 setup' % arch
107+
f'host architecture {arch} not supported for grub2 setup'
108108
)
109109

110110
if self.custom_args and 'grub_directory_name' in self.custom_args:
@@ -417,7 +417,7 @@ def setup_install_image_config(
417417
self.config = template.substitute(parameters)
418418
except Exception as e:
419419
raise KiwiTemplateError(
420-
'%s: %s' % (type(e).__name__, format(e))
420+
f'{type(e).__name__}: {format(e)}'
421421
)
422422
if self.firmware.efi_mode() and self.early_boot_script_efi:
423423
self._copy_grub_config_to_efi_path(
@@ -488,7 +488,7 @@ def setup_live_image_config(
488488
self.config = template.substitute(parameters)
489489
except Exception as e:
490490
raise KiwiTemplateError(
491-
'%s: %s' % (type(e).__name__, format(e))
491+
f'{type(e).__name__}: {format(e)}'
492492
)
493493
if self.firmware.efi_mode() and self.early_boot_script_efi:
494494
self._copy_grub_config_to_efi_path(
@@ -1511,7 +1511,7 @@ def _copy_modules_to_boot_directory_from(self, module_path):
15111511
)
15121512
except Exception as e:
15131513
raise KiwiBootLoaderGrubModulesError(
1514-
'Module synchronisation failed with: %s' % format(e)
1514+
f'Module synchronisation failed with: {format(e)}'
15151515
)
15161516

15171517
def _get_shim_install(self):
@@ -1656,7 +1656,7 @@ def _get_partition_start(self, disk_device):
16561656
start_track = int(fdasd_output.split(' ')[2].lstrip())
16571657
except Exception:
16581658
raise KiwiDiskGeometryError(
1659-
'unknown partition format: %s' % fdasd_output
1659+
f'unknown partition format: {fdasd_output}'
16601660
)
16611661
return '{0}'.format(start_track * blocks)
16621662
else:
@@ -1699,7 +1699,7 @@ def _get_dasd_disk_geometry_element(self, disk_device, search):
16991699
return int(fdasd_output.split(':')[1].lstrip())
17001700
except Exception:
17011701
raise KiwiDiskGeometryError(
1702-
'unknown format for disk geometry: %s' % fdasd_output
1702+
f'unknown format for disk geometry: {fdasd_output}'
17031703
)
17041704

17051705
def _create_loopback_config(self, filename):
@@ -1720,6 +1720,6 @@ def _get_custom_template(self) -> str:
17201720
template_path = os.path.join(os.path.abspath(self.xml_state.xml_data.description_dir),
17211721
self.xml_state.build_type.bootloader[0].get_grub_template())
17221722
if not os.path.exists(template_path):
1723-
raise KiwiFileNotFound('failed to locate custom GRUB template %s' % template_file)
1723+
raise KiwiFileNotFound(f'failed to locate custom GRUB template {template_file}')
17241724

17251725
return template_path

kiwi/bootloader/install/grub2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def install(self):
176176
self.install_arguments.append('--no-nvram')
177177
else:
178178
raise KiwiBootLoaderGrubPlatformError(
179-
'host architecture %s not supported for grub2 installation' %
180-
self.arch
179+
f'host architecture {self.arch} not supported for grub2 installation'
181180
)
182181

183182
with ExitStack() as stack:

kiwi/builder/archive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def create(self) -> Result:
8181
supported_archives = Defaults.get_archive_image_types()
8282
if self.requested_archive_type not in supported_archives:
8383
raise KiwiArchiveSetupError(
84-
'Unknown archive type: %s' % self.requested_archive_type
84+
f'Unknown archive type: {self.requested_archive_type}'
8585
)
8686

8787
if self.requested_archive_type == 'tbz':

kiwi/builder/disk.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,8 +1714,8 @@ def _sync_system_to_image(
17141714
Command.run(
17151715
[
17161716
'dd',
1717-
'if=%s' % squashed_root_file.name,
1718-
'of=%s' % readonly_target
1717+
f'if={squashed_root_file.name}',
1718+
f'of={readonly_target}'
17191719
]
17201720
)
17211721
if self.root_filesystem_embed_verity_metadata:
@@ -1779,8 +1779,8 @@ def _sync_system_to_image(
17791779
Command.run(
17801780
[
17811781
'dd',
1782-
'if=%s' % verity_root_file.name,
1783-
'of=%s' % root_target
1782+
f'if={verity_root_file.name}',
1783+
f'of={root_target}'
17841784
]
17851785
)
17861786
if self.root_filesystem_embed_verity_metadata:

kiwi/builder/filesystem.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def __init__(
6363
self.requested_filesystem = self.requested_image_type
6464
if not self.requested_filesystem:
6565
raise KiwiFileSystemSetupError(
66-
'No filesystem configured in %s type' %
67-
self.requested_image_type
66+
f'No filesystem configured in {self.requested_image_type} type'
6867
)
6968
self.filesystem_custom_parameters = {
7069
'mount_options': xml_state.get_fs_mount_option_list(),
@@ -120,7 +119,7 @@ def create(self) -> Result:
120119
supported_filesystems = Defaults.get_filesystem_image_types()
121120
if self.requested_filesystem not in supported_filesystems:
122121
raise KiwiFileSystemSetupError(
123-
'Unknown filesystem: %s' % self.requested_filesystem
122+
f'Unknown filesystem: {self.requested_filesystem}'
124123
)
125124
if self.requested_filesystem not in self.filesystems_no_device_node:
126125
self._operate_on_loop()

kiwi/builder/install.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def create_install_pxe_archive(self) -> None:
339339
if custom_cmdline:
340340
cmdline += ' ' + custom_cmdline
341341
with open(append_filename, 'w') as append:
342-
append.write('%s\n' % cmdline)
342+
append.write(f'{cmdline}\n')
343343

344344
# create initrd for pxe install
345345
log.info('Creating pxe install boot image')
@@ -496,10 +496,10 @@ def _copy_system_image_initrd_to_iso_image(self) -> None:
496496
def _write_install_image_info_to_iso_image(self) -> None:
497497
iso_trigger = self.media_dir.name + '/config.isoclient'
498498
with open(iso_trigger, 'w') as iso_system:
499-
iso_system.write('IMAGE="%s"\n' % self.squashed_diskname)
499+
iso_system.write(f'IMAGE="{self.squashed_diskname}\"\n')
500500

501501
def _write_install_image_info_to_boot_image(self) -> None:
502502
initrd_trigger = \
503503
self.boot_image_task.boot_root_directory + '/config.vmxsystem'
504504
with open(initrd_trigger, 'w') as vmx_system:
505-
vmx_system.write('IMAGE="%s"\n' % self.squashed_diskname)
505+
vmx_system.write(f'IMAGE="{self.squashed_diskname}\"\n')

kiwi/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,5 +297,5 @@ def _load_command_args(self):
297297
return docopt(self.command_loaded.__doc__, argv=argv)
298298
except Exception:
299299
raise KiwiCommandNotLoaded(
300-
'%s command not loaded' % self.get_command()
300+
f'{self.get_command()} command not loaded'
301301
)

kiwi/command.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def run(
127127
)
128128

129129
if not cmd_abspath:
130-
message = 'Command "%s" not found in the environment' % command[0]
130+
message = f'Command "{command[0]}" not found in the environment'
131131
if raise_on_command_not_found:
132132
raise KiwiCommandNotFound(message)
133133
log.debug('EXEC: %s', message)
@@ -143,7 +143,7 @@ def run(
143143
)
144144
except (OSError, subprocess.SubprocessError) as e:
145145
raise KiwiCommandError(
146-
'%s: %s: %s' % (command[0], type(e).__name__, format(e))
146+
f'{command[0]}: {type(e).__name__}: {format(e)}'
147147
) from e
148148

149149
output, error = process.communicate()
@@ -209,7 +209,7 @@ def call(
209209
command[0], custom_env=environment, access_mode=os.X_OK
210210
):
211211
raise KiwiCommandNotFound(
212-
'Command "%s" not found in the environment' % command[0]
212+
f'Command "{command[0]}" not found in the environment'
213213
)
214214
try:
215215
process = subprocess.Popen(
@@ -220,7 +220,7 @@ def call(
220220
)
221221
except Exception as e:
222222
raise KiwiCommandError(
223-
'%s: %s' % (type(e).__name__, format(e))
223+
f'{type(e).__name__}: {format(e)}'
224224
) from e
225225

226226
# guaranteed to be true as stdout & stderr equal subprocess.PIPE

0 commit comments

Comments
 (0)