diff mbox series

[meta-swupdate,3/3] swupdate_class: use shell function to create swupdate file

Message ID 20180507121251.13088-3-raphael.freudiger@siemens.com
State Changes Requested
Headers show
Series [meta-swupdate,1/3] swupdate_class: split out a base class | expand

Commit Message

Raphael Freudiger May 7, 2018, 12:12 p.m. UTC
Having a separate shell function is better readable and maintainable
than the string passed to os.system.

Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com>
---
 classes/swupdate-base.bbclass | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

Comments

Stefano Babic May 16, 2018, 10:19 a.m. UTC | #1
Hi Raphael,

On 07/05/2018 14:12, Raphael Freudiger wrote:
> Having a separate shell function is better readable and maintainable
> than the string passed to os.system.
> 

But if we have a python function to build the SWU and we want to move
some code outside, why not still a python function instead of a shell
function ?

> Signed-off-by: Raphael Freudiger <raphael.freudiger@siemens.com>
> ---
>  classes/swupdate-base.bbclass | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/classes/swupdate-base.bbclass b/classes/swupdate-base.bbclass
> index 29cfe5f..46e87a4 100644
> --- a/classes/swupdate-base.bbclass
> +++ b/classes/swupdate-base.bbclass
> @@ -164,9 +164,16 @@ python do_swuimage () {
>          else:
>              bb.fatal("Unrecognized SWUPDATE_SIGNING mechanism.");
>  
> -    line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(swupdate_dir,d.getVar('IMAGE_NAME', True) + '.swu')
> -    os.system("cd " + s + ";" + line)
> +    d.setVar("LIST_FOR_CPIO", ' '.join(list_for_cpio))
> +    bb.build.exec_func("create_swu", d)
> +}
> +
> +create_swu() {
> +    cd ${S}
> +    for i in ${LIST_FOR_CPIO}
> +    do
> +        echo $i
> +    done | cpio -ov -H crc > ${SWUPDATE_DIR}/${IMAGE_NAME}.swu
>  
> -    line = 'ln -sf ' + d.getVar('IMAGE_NAME', True) + '.swu ' + d.getVar('IMAGE_LINK_NAME', True) + '.swu'
> -    os.system("cd " + swupdate_dir + "; " + line)
> +    ln -sf ${IMAGE_NAME}.swu ${SWUPDATE_DIR}/${IMAGE_LINK_NAME}.swu
>  }
> 

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/classes/swupdate-base.bbclass b/classes/swupdate-base.bbclass
index 29cfe5f..46e87a4 100644
--- a/classes/swupdate-base.bbclass
+++ b/classes/swupdate-base.bbclass
@@ -164,9 +164,16 @@  python do_swuimage () {
         else:
             bb.fatal("Unrecognized SWUPDATE_SIGNING mechanism.");
 
-    line = 'for i in ' + ' '.join(list_for_cpio) + '; do echo $i;done | cpio -ov -H crc >' + os.path.join(swupdate_dir,d.getVar('IMAGE_NAME', True) + '.swu')
-    os.system("cd " + s + ";" + line)
+    d.setVar("LIST_FOR_CPIO", ' '.join(list_for_cpio))
+    bb.build.exec_func("create_swu", d)
+}
+
+create_swu() {
+    cd ${S}
+    for i in ${LIST_FOR_CPIO}
+    do
+        echo $i
+    done | cpio -ov -H crc > ${SWUPDATE_DIR}/${IMAGE_NAME}.swu
 
-    line = 'ln -sf ' + d.getVar('IMAGE_NAME', True) + '.swu ' + d.getVar('IMAGE_LINK_NAME', True) + '.swu'
-    os.system("cd " + swupdate_dir + "; " + line)
+    ln -sf ${IMAGE_NAME}.swu ${SWUPDATE_DIR}/${IMAGE_LINK_NAME}.swu
 }