[oe-commits] Chris Larson : Use the python modules for checksum generation where we can

git version control git at git.openembedded.org
Thu Apr 22 22:55:18 UTC 2010


Module: openembedded.git
Branch: org.openembedded.dev
Commit: 28a068820bc4ef6bac5a4eb1b7438fd8628cdcf7
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=28a068820bc4ef6bac5a4eb1b7438fd8628cdcf7

Author: Chris Larson <chris_larson at mentor.com>
Date:   Thu Apr 22 13:57:01 2010 -0700

Use the python modules for checksum generation where we can

Based on df32920678d15c86897b50b752b937210a01edea.

Signed-off-by: Chris Larson <chris_larson at mentor.com>
Tested-by: Khem Raj <raj.khem at gmail.com>
Acked-by: Khem Raj <raj.khem at gmail.com>

---

 classes/base.bbclass  |   10 +++++-----
 classes/utils.bbclass |   40 +++++++++++++++++++++-------------------
 2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/classes/base.bbclass b/classes/base.bbclass
index d3bfa76..b8499b9 100644
--- a/classes/base.bbclass
+++ b/classes/base.bbclass
@@ -37,11 +37,10 @@ def base_dep_prepend(d):
 	# the case where host == build == target, for now we don't work in
 	# that case though.
 	#
-	deps = "shasum-native coreutils-native"
-	if bb.data.getVar('PN', d, True) == "shasum-native" or bb.data.getVar('PN', d, True) == "stagemanager-native":
+	deps = "coreutils-native"
+	if bb.data.getVar('PN', d, True) in ("shasum-native", "stagemanager-native",
+	                                     "coreutils-native"):
 		deps = ""
-	if bb.data.getVar('PN', d, True) == "coreutils-native":
-		deps = "shasum-native"
 
 	# INHIBIT_DEFAULT_DEPS doesn't apply to the patch command.  Whether or  not
 	# we need that built is the responsibility of the patch function / class, not
@@ -76,7 +75,6 @@ addtask setscene before do_fetch
 
 addtask fetch
 do_fetch[dirs] = "${DL_DIR}"
-do_fetch[depends] = "shasum-native:do_populate_staging"
 python base_do_fetch() {
 	import sys
 
@@ -365,6 +363,8 @@ python () {
     if use_nls != None:
         bb.data.setVar('USE_NLS', use_nls, d)
 
+    setup_checksum_deps(d)
+
     # Git packages should DEPEND on git-native
     srcuri = bb.data.getVar('SRC_URI', d, 1)
     if "git://" in srcuri:
diff --git a/classes/utils.bbclass b/classes/utils.bbclass
index 1cc6d2b..0252a43 100644
--- a/classes/utils.bbclass
+++ b/classes/utils.bbclass
@@ -84,6 +84,15 @@ def base_chk_load_parser(config_paths):
 
     return parser
 
+def setup_checksum_deps(d):
+    try:
+        import hashlib
+    except ImportError:
+        if d.getVar("PN", True) != "shasum-native":
+            depends = d.getVarFlag("do_fetch", "depends") or ""
+            d.setVarFlag("do_fetch", "depends", "%s %s" %
+                         (depends, "shasum-native:do_populate_staging"))
+
 def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256sum, data):
     strict_checking =  bb.data.getVar("OE_STRICT_CHECKSUMS", data, True)
     if not os.path.exists(localpath):
@@ -91,25 +100,18 @@ def base_chk_file_checksum(localpath, src_uri, expected_md5sum, expected_sha256s
         bb.note("The localpath does not exist '%s'" % localpath)
         raise Exception("The path does not exist '%s'" % localpath)
 
-    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:
-        if strict_checking:
-            raise Exception("Executing md5sum failed")
-        else:
-            bb.note("Executing md5sum failed")
-
-    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:
-        if strict_checking:
-            raise Exception("Executing shasum failed")
-        else:
-            bb.note("Executing shasum failed")
+    md5data = bb.utils.md5_file(localpath)
+    sha256data = bb.utils.sha256_file(localpath)
+    if not sha256data:
+        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:
+            if strict_checking:
+                raise Exception("Executing shasum failed")
+            else:
+                bb.note("Executing shasum failed")
 
     if (expected_md5sum == None or expected_md5sum == None):
         from string import maketrans





More information about the Openembedded-commits mailing list