Patchworkβ [oe] base.bbclass: use bb.utils.*_sum instead of calling md5/sha sum commands

login
register
about
Submitter Christopher Larson
Date 2010-01-15 18:30:33
Message ID <1263580233-3494-1-git-send-email-clarson@mvista.com>
Download mbox | patch
Permalink /patch/1471/
State Accepted
Delegated to: Christopher Larson
Headers show

Comments

Christopher Larson - 2010-01-15 18:30:33
From: Ross Burton <ross@openedhand.com>

Patch courtesy the Poky project.

Signed-off-by: Chris Larson <clarson@mvista.com>
---
 classes/base.bbclass |   27 +++++++++++++++------------
 1 files changed, 15 insertions(+), 12 deletions(-)
Marcin Juszkiewicz - 2010-01-26 15:50:08
Dnia piątek, 15 stycznia 2010 o 19:30:33 Chris Larson napisał(a):
> From: Ross Burton <ross@openedhand.com>
> 
> Patch courtesy the Poky project.
> 
> Signed-off-by: Chris Larson <clarson@mvista.com>
> 

Acked-by: Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>


Regards,
Tom Rini - 2010-02-25 18:35:29
On Fri, 2010-01-15 at 08:30 +0000, Christopher Larson wrote:
> From: Ross Burton <ross@openedhand.com>
> 
> Patch courtesy the Poky project.
> 
> Signed-off-by: Chris Larson <clarson@mvista.com>
> Acked-by: Marcin Juszkiewicz <marcin@juszkiewicz.com.pl>

Acked-by: Tom Rini <tom_rini@mentor.com>

> 
> ---
> classes/base.bbclass |   27 +++++++++++++++------------
>  1 files changed, 15 insertions(+), 12 deletions(-)
> 
> diff --git a/classes/base.bbclass b/classes/base.bbclass
> index 96164d4..dc56282 100644
> --- a/classes/base.bbclass
> +++ b/classes/base.bbclass
> @@ -122,23 +122,26 @@ def base_chk_file_vars(parser, localpath, params, data):
>          raise Exception("The path does not exist '%s'" % localpath)
>  
>      if want_md5sum:
> -        try:
> -	    md5pipe = os.popen('PATH=%s md5sum %s' % (bb.data.getVar('PATH', data, True), localpath))
> -            md5data = (md5pipe.readline().split() or [ "" ])[0]
> -            md5pipe.close()
> -        except OSError, e:
> -            raise Exception("Executing md5sum failed")
> +        md5data = bb.utils.md5_file(localpath)
> +
>          if want_md5sum != md5data:
>              bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (want_md5sum, md5data))
>              raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (want_md5sum, md5data))
>  
>      if want_sha256sum:
> -        try:
> -            shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
> -            sha256data = (shapipe.readline().split() or [ "" ])[0]
> -            shapipe.close()
> -        except OSError, e:
> -            raise Exception("Executing shasum failed")
> +        shadata = bb.utils.sha256_file(localpath)
> +
> +        # sha256_file() can return None if we are running on Python 2.4 (hashlib is
> +        # 2.5 onwards, sha in 2.4 is 160-bit only), so check for this and call the
> +        # standalone shasum binary if required.
> +        if shadata is None:
> +            try:
> +                shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
> +                shadata = (shapipe.readline().split() or [ "" ])[0]
> +                shapipe.close()
> +            except OSError:
> +                raise Exception("Executing shasum failed, please build shasum-native")
> +
>          if want_sha256sum != sha256data:
>              bb.note("The SHA256Sums did not match. Wanted: '%s' and Got: '%s'" % (want_sha256sum, sha256data))
>              raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (want_sha256sum, sha256data))

Patch

diff --git a/classes/base.bbclass b/classes/base.bbclass
index 96164d4..dc56282 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -122,23 +122,26 @@  def base_chk_file_vars(parser, localpath, params, data):
         raise Exception("The path does not exist '%s'" % localpath)
 
     if want_md5sum:
-        try:
-	    md5pipe = os.popen('PATH=%s md5sum %s' % (bb.data.getVar('PATH', data, True), localpath))
-            md5data = (md5pipe.readline().split() or [ "" ])[0]
-            md5pipe.close()
-        except OSError, e:
-            raise Exception("Executing md5sum failed")
+        md5data = bb.utils.md5_file(localpath)
+
         if want_md5sum != md5data:
             bb.note("The MD5Sums did not match. Wanted: '%s' and Got: '%s'" % (want_md5sum, md5data))
             raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (want_md5sum, md5data))
 
     if want_sha256sum:
-        try:
-            shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
-            sha256data = (shapipe.readline().split() or [ "" ])[0]
-            shapipe.close()
-        except OSError, e:
-            raise Exception("Executing shasum failed")
+        shadata = bb.utils.sha256_file(localpath)
+
+        # sha256_file() can return None if we are running on Python 2.4 (hashlib is
+        # 2.5 onwards, sha in 2.4 is 160-bit only), so check for this and call the
+        # standalone shasum binary if required.
+        if shadata is None:
+            try:
+                shapipe = os.popen('PATH=%s oe_sha256sum %s' % (bb.data.getVar('PATH', data, True), localpath))
+                shadata = (shapipe.readline().split() or [ "" ])[0]
+                shapipe.close()
+            except OSError:
+                raise Exception("Executing shasum failed, please build shasum-native")
+
         if want_sha256sum != sha256data:
             bb.note("The SHA256Sums did not match. Wanted: '%s' and Got: '%s'" % (want_sha256sum, sha256data))
             raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (want_sha256sum, sha256data))