From 4c07da0ffdb3c3e6217cba29ba081e0f301aad0c Mon Sep 17 00:00:00 2001 From: lxnay Date: Sun, 15 Mar 2009 17:13:54 +0000 Subject: [PATCH] Molecule: - generate ISO md5 file automatically git-svn-id: http://svn.sabayonlinux.org/projects/molecule/trunk@3190 cd1c1023-2f26-0410-ae45-c471fc1f0318 --- molecule/handlers.py | 11 +++++++++++ molecule/utils.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/molecule/handlers.py b/molecule/handlers.py index a3b1b51..ec9e6c4 100644 --- a/molecule/handlers.py +++ b/molecule/handlers.py @@ -509,6 +509,17 @@ class IsoHandler(GenericHandlerInterface): _("built ISO image"),self.dest_iso, ) ) + if os.path.isfile(self.dest_iso) and os.access(self.dest_iso,os.R_OK): + self.Output.updateProgress("[%s|%s] %s: %s" % ( + blue("IsoHandler"),darkred(self.spec_name), + _("generating md5 for"),self.dest_iso, + ) + ) + digest = molecule.utils.md5sum(self.dest_iso) + md5file = self.dest_iso+".md5" + with open(md5file,"w") as f: + f.write("%s %s\n" % (os.path.basename(self.dest_iso),digest,)) + f.flush() return 0 diff --git a/molecule/utils.py b/molecule/utils.py index 728407a..4c4c380 100644 --- a/molecule/utils.py +++ b/molecule/utils.py @@ -85,3 +85,14 @@ def remove_path_sandbox(path, sandbox_env): def get_random_number(): return abs(hash(os.urandom(2)))%99999 + +def md5sum(filepath): + import hashlib + m = hashlib.md5() + readfile = open(filepath) + block = readfile.read(1024) + while block: + m.update(block) + block = readfile.read(1024) + readfile.close() + return m.hexdigest()