[oe-commits] org.oe.dev qa/checksum: Add python code to verify a sha256, md5sum

freyther commit openembedded-commits at lists.openembedded.org
Sat Mar 31 21:02:54 UTC 2007


qa/checksum: Add python code to verify a sha256,md5sum

    Store md5 and sha256 sums in a ini file and verify
    it with a local file. This code has been tested (manually)
    on OSX and should be integrated into either OE or BitBake

Author: freyther at openembedded.org
Branch: org.openembedded.dev
Revision: a73ca61dee044168d70737f0c38567b825b10fb9
ViewMTN: http://monotone.openembedded.org/revision.psp?id=a73ca61dee044168d70737f0c38567b825b10fb9
Files:
1
contrib/qa/checksum
contrib/qa/checksum/checksum.py
contrib/qa/checksum/sample.conf
contrib/qa/checksum/test.file
Diffs:

#
# mt diff -rce45c8e871ba93b79b522e7311f813a4c79bb08e -ra73ca61dee044168d70737f0c38567b825b10fb9
#
# 
# 
# add_dir "contrib/qa/checksum"
# 
# add_file "contrib/qa/checksum/checksum.py"
#  content [46d071fb702aa4bb9dcaa78d9999fac83ceee07f]
# 
# add_file "contrib/qa/checksum/sample.conf"
#  content [13a752e2d5bde73cb7e3e58aaee3b83539a66114]
# 
# add_file "contrib/qa/checksum/test.file"
#  content [da39a3ee5e6b4b0d3255bfef95601890afd80709]
# 
============================================================
--- contrib/qa/checksum/checksum.py	46d071fb702aa4bb9dcaa78d9999fac83ceee07f
+++ contrib/qa/checksum/checksum.py	46d071fb702aa4bb9dcaa78d9999fac83ceee07f
@@ -0,0 +1,74 @@
+#
+# Helper utilitiy to verify checksums of SRC_URI's
+#
+#  To ease parsing I will use INI files to contain the
+#  checksums, at least they will force some kind of structure. This allows
+#  to easily add and replace new sums
+#
+#
+#  Example:
+#  [PN-PV-filename]
+#  md5=THESUM
+#  sha256=OTHERSUM
+#
+#  [PN-filename]
+#  md5=THESUM
+#  sha256=OTHERSUM
+
+
+def verify_file(config_path, pn, pv, src_uri, localpath):
+    """
+    Verify using the INI file at config_path and check that
+    the localpath matches the one specified by the PN-PV-SRCURI
+    inside the ini file
+    """
+    import ConfigParser, os
+    parser = ConfigParser.ConfigParser()
+    if not len(parser.read(config_path)) == 1:
+        raise Exception("Can not open the '%s'" % config_path)
+
+    # Try PN-PV-SRC_URI first and then try PN-SRC_URI
+    # we rely on the get method to create errors
+    pn_pv_src = "%s-%s-%s" % (pn,pv,src_uri)
+    pn_src    = "%s-%s" % (pn,src_uri)
+    if parser.has_section(pn_pv_src):
+        md5    = parser.get(pn_pv_src, "md5")
+        sha256 = parser.get(pn_pv_src, "sha256")
+    elif parser.has_section(pn_src):
+        md5    = parser.get(pn_src, "md5")
+        sha256 = parser.get(pn_src, "sha256")
+    else:
+        raise Exception("Can not find a section for '%s' '%s' and '%s'" % (pn,pv,src_uri))
+
+    # md5 and sha256 should be valid now
+    if not os.path.exists(localpath):
+        raise Exception("The path does not exist '%s'" % localpath)
+
+
+    # call md5(sum) and shasum
+    try:
+        md5pipe = os.popen('md5sum ' + localpath)
+        md5data = (md5pipe.readline().split() or [ "" ])[0]
+        md5pipe.close()
+    except OSError:
+        raise Exception("Executing md5sum failed")
+
+    try:
+        shapipe = os.popen('shasum -a256 -p ' + localpath)
+        shadata = (shapipe.readline().split() or [ "" ])[0]
+        shapipe.close()
+    except OSError:
+        raise Exception("Executing shasum failed")
+
+    if not md5 == md5data:
+        raise Exception("MD5 Sums do not match. Wanted: '%s' Got: '%s'" % (md5, md5data))
+
+    if not sha256 == shadata:
+        raise Exception("SHA256 Sums do not match. Wanted: '%s' Got: '%s'" % (sha256, shadata))
+
+
+    return True
+
+
+# Test it
+verify_file("sample.conf", "qtopia-core", "4.3.0", "ftp://ftp.trolltech.com/qt/source/qtopia-core-opensource-4.2.3.tar.gz", "test.file")
============================================================
--- contrib/qa/checksum/sample.conf	13a752e2d5bde73cb7e3e58aaee3b83539a66114
+++ contrib/qa/checksum/sample.conf	13a752e2d5bde73cb7e3e58aaee3b83539a66114
@@ -0,0 +1,9 @@
+[qtopia-core-4.3-ftp://ftp.trolltech.com/qt/source/qtopia-core-opensource-4.3.0beta.tar.gz]
+md5=123
+sha256=1000
+
+[qtopia-core-ftp://ftp.trolltech.com/qt/source/qtopia-core-opensource-4.2.3.tar.gz]
+md5=d41d8cd98f00b204e9800998ecf8427e
+sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+
+# Test commets and such
============================================================
--- contrib/qa/checksum/test.file	da39a3ee5e6b4b0d3255bfef95601890afd80709
+++ contrib/qa/checksum/test.file	da39a3ee5e6b4b0d3255bfef95601890afd80709






More information about the Openembedded-commits mailing list