From a6e79a93f66296c231d339b160704b0165a3c2e3 Mon Sep 17 00:00:00 2001 From: Holger Freyther Date: Sat, 14 Apr 2007 22:54:34 +0000 Subject: modules/chksum_checker/chksum.py: Generate a checksum.ini from already downloaded files This code generates a sorted checksums.ini file from the files already downloaded and stored in the DL_DIR of the test. Only http, https and ftp protocols will be used as protocols and the checksums.ini will be saved in the current working dir --- modules/chksum_checker/chksum.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/modules/chksum_checker/chksum.py b/modules/chksum_checker/chksum.py index 236a14a67d..7080c8922c 100644 --- a/modules/chksum_checker/chksum.py +++ b/modules/chksum_checker/chksum.py @@ -34,6 +34,8 @@ from bittest import TestItem +import bb, os + class TestCase: """ A simple test case @@ -45,12 +47,18 @@ class TestCase: """ def setup(self, config): - print "Create" - pass + self.checksum_tuple_dict = {} def finish(self, config): - print "Finish" - pass + f = file("checksums.ini", "w+") + keys = self.checksum_tuple_dict.keys() + keys.sort() + for fi in keys: + (md5,sha) = self.checksum_tuple_dict[fi] + print >> f, "[%s]" % fi + print >> f, "md5=%s" % md5 + print >> f, "sha256=%s" % sha + print >> f, "" def test(self,file_name, file_data): """ @@ -58,7 +66,21 @@ class TestCase: You can use whatever you want """ - return TestItem(file_name,False,"The Test Failed") + uris = (bb.data.getVar("SRC_URI", file_data, True) or "").split() + bb.fetch.init(uris, file_data) + for uri in uris: + localpath = bb.fetch.localpath(uri, file_data) + (type,host,path,_,_,_) = bb.decodeurl(uri) + uri = "%s://%s%s" % (type,host,path) + + if not type in ["http", "ftp", "https"]: + continue + if not uri in self.checksum_tuple_dict and os.path.exists(localpath): + md5sum = os.popen("md5sum %s" % localpath).read().split()[0] + shasum = os.popen("sha256sum %s" % localpath).read().split()[0] + self.checksum_tuple_dict[uri] = (md5sum,shasum) + + return TestItem(file_name,True, "Psst, we did not test at all") def test_name(self): """ -- cgit 1.2.3-korg