summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolger Freyther <zecke@selfish.org>2007-03-31 19:03:56 +0000
committerHolger Freyther <zecke@selfish.org>2007-03-31 19:03:56 +0000
commited7c417090d4cc735c797e9ecfd1a49b071eb95f (patch)
tree7d9f4398dc0e5186a706bc41b8b45646915a9543
parent5d3963de4a236f1a28f4c5c0829d0492141ea505 (diff)
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
-rw-r--r--contrib/qa/checksum/.mtn2git_empty0
-rw-r--r--contrib/qa/checksum/checksum.py74
-rw-r--r--contrib/qa/checksum/sample.conf9
-rw-r--r--contrib/qa/checksum/test.file0
4 files changed, 83 insertions, 0 deletions
diff --git a/contrib/qa/checksum/.mtn2git_empty b/contrib/qa/checksum/.mtn2git_empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/contrib/qa/checksum/.mtn2git_empty
diff --git a/contrib/qa/checksum/checksum.py b/contrib/qa/checksum/checksum.py
new file mode 100644
index 0000000000..6880f045d3
--- /dev/null
+++ b/contrib/qa/checksum/checksum.py
@@ -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")
diff --git a/contrib/qa/checksum/sample.conf b/contrib/qa/checksum/sample.conf
new file mode 100644
index 0000000000..478a9a05f9
--- /dev/null
+++ b/contrib/qa/checksum/sample.conf
@@ -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
diff --git a/contrib/qa/checksum/test.file b/contrib/qa/checksum/test.file
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/contrib/qa/checksum/test.file