Message ID | 20240904064223.869919-1-srinuvasan.a@siemens.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [isar-cip-core] scripts/lib/wic/plugins/source: Use F-string instead of traditional .format() method | expand |
Hi, On 9/4/24 8:42 AM, Srinuvasan A via lists.cip-project.org wrote: > From: srinuvasan <srinuvasan.a@siemens.com> > > Use f string for string interpolation and formatting instead of traditional .format() > method. > > f-strings are generally preferred due to their readability,simplicity and efficiency, > and moreover there is no functional changes apart from the optimization. > > Signed-off-by: srinuvasan <srinuvasan.a@siemens.com> > --- > .../wic/plugins/source/efibootguard-boot.py | 31 +++++-------------- > .../wic/plugins/source/efibootguard-efi.py | 17 +++------- > 2 files changed, 12 insertions(+), 36 deletions(-) > > diff --git a/scripts/lib/wic/plugins/source/efibootguard-boot.py b/scripts/lib/wic/plugins/source/efibootguard-boot.py > index 2b06fd1..ad749fb 100644 > --- a/scripts/lib/wic/plugins/source/efibootguard-boot.py > +++ b/scripts/lib/wic/plugins/source/efibootguard-boot.py > @@ -170,29 +170,16 @@ class EfibootguardBootPlugin(SourcePlugin): > msger.error("Bitbake variable 'EFI_LIB_ARCH' not set, exiting\n") > exit(1) > > - efistub = "{rootfs_path}/usr/lib/{libpath}/efibootguard/kernel-stub{efiarch}.efi"\ > - .format(rootfs_path=rootfs_path, > - libpath=libarch, > - efiarch=efiarch) > + efistub = f'{rootfs_path}/usr/lib/{libarch}/efibootguard/kernel-stub{efiarch}.efi' > uefi_kernel_name = "linux.efi" > - uefi_kernel_file = "{deploy_dir}/{uefi_kernel_name}"\ > - .format(deploy_dir=deploy_dir, uefi_kernel_name=uefi_kernel_name) > - kernel = "{deploy_dir}/{kernel_image}"\ > - .format(deploy_dir=deploy_dir, kernel_image=kernel_image) > - initrd = "{deploy_dir}/{initrd_image}"\ > - .format(deploy_dir=deploy_dir, initrd_image=initrd_image) > - cmd = 'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} \ > - -c "{cmdline}" -i {initrd}'.format( > - cmdline=cmdline, > - kernel=kernel, > - initrd=initrd, > - efistub=efistub, > - uefi_kernel_file=uefi_kernel_file) > + uefi_kernel_file = f'{deploy_dir}/{uefi_kernel_name}' > + kernel = f'{deploy_dir}/{kernel_image}' > + initrd = f'{deploy_dir}/{initrd_image}' > + cmd = f'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} -c "{cmdline}" -i {initrd}' > if dtb_files: > for dtb in dtb_files: > - cmd += ' -d {deploy_dir}/{dtb_file}'.format( > - deploy_dir=deploy_dir, > - dtb_file=os.path.basename(dtb)) > + dtb_file=os.path.basename(dtb) > + cmd += f' -d {deploy_dir}/{dtb_files}' > exec_cmd(cmd, as_shell=True) > > cls._sign_file(signee=uefi_kernel_file, source_params=source_params) > @@ -206,9 +193,7 @@ class EfibootguardBootPlugin(SourcePlugin): > msger.info("sign with script %s", sign_script) > orig_signee = signee + ".unsigned" > os.rename(signee, orig_signee) > - sign_cmd = "{sign_script} {orig_signee} {signee}"\ > - .format(sign_script=sign_script, orig_signee=orig_signee, > - signee=signee) > + sign_cmd = f'{sign_script} {orig_signee} {signee}' > exec_cmd(sign_cmd) > elif sign_script and not os.path.exists(sign_script): > msger.error("Could not find script %s", sign_script) > diff --git a/scripts/lib/wic/plugins/source/efibootguard-efi.py b/scripts/lib/wic/plugins/source/efibootguard-efi.py > index 48f7523..c443d14 100644 > --- a/scripts/lib/wic/plugins/source/efibootguard-efi.py > +++ b/scripts/lib/wic/plugins/source/efibootguard-efi.py > @@ -73,16 +73,14 @@ class EfibootguardEFIPlugin(SourcePlugin): > creator.deploy_dir = deploy_dir > > distro_arch = get_bitbake_var("DISTRO_ARCH") > - bootloader = "/usr/lib/{libpath}/efibootguard/efibootguard{efiarch}.efi".format( > - libpath=libarch, > - efiarch=efiarch) > + bootloader = f'/usr/lib/{libarch}/efibootguard/efibootguard{efiarch}.efi' > part_rootfs_dir = "%s/disk/%s.%s" % (cr_workdir, > part.label, > part.lineno) Why did you not replace the old string format in this patch? I see only the str.format calls replaced. Quirin > create_dir_cmd = "install -d %s/EFI/BOOT" % part_rootfs_dir > exec_cmd(create_dir_cmd) > > - name = "boot{}.efi".format(efiarch) > + name = f'boot{efiarch}.efi' > > signed_bootloader = cls._sign_file(name, > bootloader, > @@ -116,11 +114,7 @@ class EfibootguardEFIPlugin(SourcePlugin): > sign_script = source_params.get("signwith") > if sign_script and os.path.exists(sign_script): > work_name = name.replace(".efi", ".signed.efi") > - sign_cmd = "{sign_script} {signee} \ > - {cr_workdir}/{work_name}".format(sign_script=sign_script, > - signee=signee, > - cr_workdir=cr_workdir, > - work_name=work_name) > + sign_cmd = f'{sign_script} {signee} {cr_workdir}/{work_name}' > exec_cmd(sign_cmd) > elif sign_script and not os.path.exists(sign_script): > msger.error("Could not find script %s", sign_script) > @@ -128,9 +122,6 @@ class EfibootguardEFIPlugin(SourcePlugin): > else: > # if we do nothing copy the signee to the work directory > work_name = name > - cp_cmd = "cp {signee} {cr_workdir}/{work_name}".format( > - signee=signee, > - cr_workdir=cr_workdir, > - work_name=work_name) > + cp_cmd = f'cp {signee} {cr_workdir}/{work_name}' > exec_cmd(cp_cmd) > return work_name > > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#16844): https://lists.cip-project.org/g/cip-dev/message/16844 > Mute This Topic: https://lists.cip-project.org/mt/108260811/1753640 > Group Owner: cip-dev+owner@lists.cip-project.org > Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129121/1753640/1405269326/xyzzy [quirin.gylstorff@siemens.com] > -=-=-=-=-=-=-=-=-=-=-=- >
Let me check and replace that as well, thanks for the suggestion. Many thanks, Srinu -----Original Message----- From: Gylstorff, Quirin (T CED OES-DE) <quirin.gylstorff@siemens.com> Sent: 04 September 2024 18:52 To: cip-dev@lists.cip-project.org Cc: Kiszka, Jan (T CED) <jan.kiszka@siemens.com>; Arjunan, Srinu (DI CTO FDS CES LX PBU 2) <srinuvasan.a@siemens.com> Subject: Re: [cip-dev] [PATCH][isar-cip-core] scripts/lib/wic/plugins/source: Use F-string instead of traditional .format() method Hi, On 9/4/24 8:42 AM, Srinuvasan A via lists.cip-project.org wrote: > From: srinuvasan <srinuvasan.a@siemens.com> > > Use f string for string interpolation and formatting instead of > traditional .format() method. > > f-strings are generally preferred due to their readability,simplicity > and efficiency, and moreover there is no functional changes apart from the optimization. > > Signed-off-by: srinuvasan <srinuvasan.a@siemens.com> > --- > .../wic/plugins/source/efibootguard-boot.py | 31 +++++-------------- > .../wic/plugins/source/efibootguard-efi.py | 17 +++------- > 2 files changed, 12 insertions(+), 36 deletions(-) > > diff --git a/scripts/lib/wic/plugins/source/efibootguard-boot.py > b/scripts/lib/wic/plugins/source/efibootguard-boot.py > index 2b06fd1..ad749fb 100644 > --- a/scripts/lib/wic/plugins/source/efibootguard-boot.py > +++ b/scripts/lib/wic/plugins/source/efibootguard-boot.py > @@ -170,29 +170,16 @@ class EfibootguardBootPlugin(SourcePlugin): > msger.error("Bitbake variable 'EFI_LIB_ARCH' not set, exiting\n") > exit(1) > > - efistub = "{rootfs_path}/usr/lib/{libpath}/efibootguard/kernel-stub{efiarch}.efi"\ > - .format(rootfs_path=rootfs_path, > - libpath=libarch, > - efiarch=efiarch) > + efistub = f'{rootfs_path}/usr/lib/{libarch}/efibootguard/kernel-stub{efiarch}.efi' > uefi_kernel_name = "linux.efi" > - uefi_kernel_file = "{deploy_dir}/{uefi_kernel_name}"\ > - .format(deploy_dir=deploy_dir, uefi_kernel_name=uefi_kernel_name) > - kernel = "{deploy_dir}/{kernel_image}"\ > - .format(deploy_dir=deploy_dir, kernel_image=kernel_image) > - initrd = "{deploy_dir}/{initrd_image}"\ > - .format(deploy_dir=deploy_dir, initrd_image=initrd_image) > - cmd = 'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} \ > - -c "{cmdline}" -i {initrd}'.format( > - cmdline=cmdline, > - kernel=kernel, > - initrd=initrd, > - efistub=efistub, > - uefi_kernel_file=uefi_kernel_file) > + uefi_kernel_file = f'{deploy_dir}/{uefi_kernel_name}' > + kernel = f'{deploy_dir}/{kernel_image}' > + initrd = f'{deploy_dir}/{initrd_image}' > + cmd = f'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} -c "{cmdline}" -i {initrd}' > if dtb_files: > for dtb in dtb_files: > - cmd += ' -d {deploy_dir}/{dtb_file}'.format( > - deploy_dir=deploy_dir, > - dtb_file=os.path.basename(dtb)) > + dtb_file=os.path.basename(dtb) > + cmd += f' -d {deploy_dir}/{dtb_files}' > exec_cmd(cmd, as_shell=True) > > cls._sign_file(signee=uefi_kernel_file, > source_params=source_params) @@ -206,9 +193,7 @@ class EfibootguardBootPlugin(SourcePlugin): > msger.info("sign with script %s", sign_script) > orig_signee = signee + ".unsigned" > os.rename(signee, orig_signee) > - sign_cmd = "{sign_script} {orig_signee} {signee}"\ > - .format(sign_script=sign_script, orig_signee=orig_signee, > - signee=signee) > + sign_cmd = f'{sign_script} {orig_signee} {signee}' > exec_cmd(sign_cmd) > elif sign_script and not os.path.exists(sign_script): > msger.error("Could not find script %s", sign_script) > diff --git a/scripts/lib/wic/plugins/source/efibootguard-efi.py > b/scripts/lib/wic/plugins/source/efibootguard-efi.py > index 48f7523..c443d14 100644 > --- a/scripts/lib/wic/plugins/source/efibootguard-efi.py > +++ b/scripts/lib/wic/plugins/source/efibootguard-efi.py > @@ -73,16 +73,14 @@ class EfibootguardEFIPlugin(SourcePlugin): > creator.deploy_dir = deploy_dir > > distro_arch = get_bitbake_var("DISTRO_ARCH") > - bootloader = "/usr/lib/{libpath}/efibootguard/efibootguard{efiarch}.efi".format( > - libpath=libarch, > - efiarch=efiarch) > + bootloader = f'/usr/lib/{libarch}/efibootguard/efibootguard{efiarch}.efi' > part_rootfs_dir = "%s/disk/%s.%s" % (cr_workdir, > part.label, > part.lineno) Why did you not replace the old string format in this patch? I see only the str.format calls replaced. Quirin > create_dir_cmd = "install -d %s/EFI/BOOT" % part_rootfs_dir > exec_cmd(create_dir_cmd) > > - name = "boot{}.efi".format(efiarch) > + name = f'boot{efiarch}.efi' > > signed_bootloader = cls._sign_file(name, > bootloader, @@ -116,11 > +114,7 @@ class EfibootguardEFIPlugin(SourcePlugin): > sign_script = source_params.get("signwith") > if sign_script and os.path.exists(sign_script): > work_name = name.replace(".efi", ".signed.efi") > - sign_cmd = "{sign_script} {signee} \ > - {cr_workdir}/{work_name}".format(sign_script=sign_script, > - signee=signee, > - cr_workdir=cr_workdir, > - work_name=work_name) > + sign_cmd = f'{sign_script} {signee} {cr_workdir}/{work_name}' > exec_cmd(sign_cmd) > elif sign_script and not os.path.exists(sign_script): > msger.error("Could not find script %s", sign_script) @@ > -128,9 +122,6 @@ class EfibootguardEFIPlugin(SourcePlugin): > else: > # if we do nothing copy the signee to the work directory > work_name = name > - cp_cmd = "cp {signee} {cr_workdir}/{work_name}".format( > - signee=signee, > - cr_workdir=cr_workdir, > - work_name=work_name) > + cp_cmd = f'cp {signee} {cr_workdir}/{work_name}' > exec_cmd(cp_cmd) > return work_name > > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#16844): > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist > s.cip-project.org%2Fg%2Fcip-dev%2Fmessage%2F16844&data=05%7C02%7Csrinu > vasan.a%40siemens.com%7C2b791d8d80fb409a588808dccce49fee%7C38ae3bcd957 > 94fd4addab42e1495d55a%7C1%7C0%7C638610529547457682%7CUnknown%7CTWFpbGZ > sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3 > D%7C0%7C%7C%7C&sdata=w0S9%2Fzn3oLOjcZuru1osrrlqdvroI3bXwRK%2Fi7B0ers%3 > D&reserved=0 Mute This Topic: > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist > s.cip-project.org%2Fmt%2F108260811%2F1753640&data=05%7C02%7Csrinuvasan > .a%40siemens.com%7C2b791d8d80fb409a588808dccce49fee%7C38ae3bcd95794fd4 > addab42e1495d55a%7C1%7C0%7C638610529547465838%7CUnknown%7CTWFpbGZsb3d8 > eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0 > %7C%7C%7C&sdata=wHajkf9omQfI%2BQ9s80G1KD2vT7kZaBdotW28aXQh0zQ%3D&reser > ved=0 Group Owner: cip-dev+owner@lists.cip-project.org > Unsubscribe: > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist > s.cip-project.org%2Fg%2Fcip-dev%2Fleave%2F8129121%2F1753640%2F14052693 > 26%2Fxyzzy&data=05%7C02%7Csrinuvasan.a%40siemens.com%7C2b791d8d80fb409 > a588808dccce49fee%7C38ae3bcd95794fd4addab42e1495d55a%7C1%7C0%7C6386105 > 29547471543%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMz > IiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=yUF8iqhVghchVMDdKf > zKlJ5J1eAfvomgFH3ty%2FSNVJg%3D&reserved=0 > [quirin.gylstorff@siemens.com] > -=-=-=-=-=-=-=-=-=-=-=- >
diff --git a/scripts/lib/wic/plugins/source/efibootguard-boot.py b/scripts/lib/wic/plugins/source/efibootguard-boot.py index 2b06fd1..ad749fb 100644 --- a/scripts/lib/wic/plugins/source/efibootguard-boot.py +++ b/scripts/lib/wic/plugins/source/efibootguard-boot.py @@ -170,29 +170,16 @@ class EfibootguardBootPlugin(SourcePlugin): msger.error("Bitbake variable 'EFI_LIB_ARCH' not set, exiting\n") exit(1) - efistub = "{rootfs_path}/usr/lib/{libpath}/efibootguard/kernel-stub{efiarch}.efi"\ - .format(rootfs_path=rootfs_path, - libpath=libarch, - efiarch=efiarch) + efistub = f'{rootfs_path}/usr/lib/{libarch}/efibootguard/kernel-stub{efiarch}.efi' uefi_kernel_name = "linux.efi" - uefi_kernel_file = "{deploy_dir}/{uefi_kernel_name}"\ - .format(deploy_dir=deploy_dir, uefi_kernel_name=uefi_kernel_name) - kernel = "{deploy_dir}/{kernel_image}"\ - .format(deploy_dir=deploy_dir, kernel_image=kernel_image) - initrd = "{deploy_dir}/{initrd_image}"\ - .format(deploy_dir=deploy_dir, initrd_image=initrd_image) - cmd = 'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} \ - -c "{cmdline}" -i {initrd}'.format( - cmdline=cmdline, - kernel=kernel, - initrd=initrd, - efistub=efistub, - uefi_kernel_file=uefi_kernel_file) + uefi_kernel_file = f'{deploy_dir}/{uefi_kernel_name}' + kernel = f'{deploy_dir}/{kernel_image}' + initrd = f'{deploy_dir}/{initrd_image}' + cmd = f'bg_gen_unified_kernel {efistub} {kernel} {uefi_kernel_file} -c "{cmdline}" -i {initrd}' if dtb_files: for dtb in dtb_files: - cmd += ' -d {deploy_dir}/{dtb_file}'.format( - deploy_dir=deploy_dir, - dtb_file=os.path.basename(dtb)) + dtb_file=os.path.basename(dtb) + cmd += f' -d {deploy_dir}/{dtb_files}' exec_cmd(cmd, as_shell=True) cls._sign_file(signee=uefi_kernel_file, source_params=source_params) @@ -206,9 +193,7 @@ class EfibootguardBootPlugin(SourcePlugin): msger.info("sign with script %s", sign_script) orig_signee = signee + ".unsigned" os.rename(signee, orig_signee) - sign_cmd = "{sign_script} {orig_signee} {signee}"\ - .format(sign_script=sign_script, orig_signee=orig_signee, - signee=signee) + sign_cmd = f'{sign_script} {orig_signee} {signee}' exec_cmd(sign_cmd) elif sign_script and not os.path.exists(sign_script): msger.error("Could not find script %s", sign_script) diff --git a/scripts/lib/wic/plugins/source/efibootguard-efi.py b/scripts/lib/wic/plugins/source/efibootguard-efi.py index 48f7523..c443d14 100644 --- a/scripts/lib/wic/plugins/source/efibootguard-efi.py +++ b/scripts/lib/wic/plugins/source/efibootguard-efi.py @@ -73,16 +73,14 @@ class EfibootguardEFIPlugin(SourcePlugin): creator.deploy_dir = deploy_dir distro_arch = get_bitbake_var("DISTRO_ARCH") - bootloader = "/usr/lib/{libpath}/efibootguard/efibootguard{efiarch}.efi".format( - libpath=libarch, - efiarch=efiarch) + bootloader = f'/usr/lib/{libarch}/efibootguard/efibootguard{efiarch}.efi' part_rootfs_dir = "%s/disk/%s.%s" % (cr_workdir, part.label, part.lineno) create_dir_cmd = "install -d %s/EFI/BOOT" % part_rootfs_dir exec_cmd(create_dir_cmd) - name = "boot{}.efi".format(efiarch) + name = f'boot{efiarch}.efi' signed_bootloader = cls._sign_file(name, bootloader, @@ -116,11 +114,7 @@ class EfibootguardEFIPlugin(SourcePlugin): sign_script = source_params.get("signwith") if sign_script and os.path.exists(sign_script): work_name = name.replace(".efi", ".signed.efi") - sign_cmd = "{sign_script} {signee} \ - {cr_workdir}/{work_name}".format(sign_script=sign_script, - signee=signee, - cr_workdir=cr_workdir, - work_name=work_name) + sign_cmd = f'{sign_script} {signee} {cr_workdir}/{work_name}' exec_cmd(sign_cmd) elif sign_script and not os.path.exists(sign_script): msger.error("Could not find script %s", sign_script) @@ -128,9 +122,6 @@ class EfibootguardEFIPlugin(SourcePlugin): else: # if we do nothing copy the signee to the work directory work_name = name - cp_cmd = "cp {signee} {cr_workdir}/{work_name}".format( - signee=signee, - cr_workdir=cr_workdir, - work_name=work_name) + cp_cmd = f'cp {signee} {cr_workdir}/{work_name}' exec_cmd(cp_cmd) return work_name