From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BDF4C13800E for ; Wed, 1 Aug 2012 07:25:39 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 60135E064E; Wed, 1 Aug 2012 07:25:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 30D33E064E for ; Wed, 1 Aug 2012 07:25:32 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4A4D91B401F for ; Wed, 1 Aug 2012 07:25:31 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 0B16CE543B for ; Wed, 1 Aug 2012 07:25:30 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1343805951.057e5f51ae4cd402a9a80105aa1dcd8993055a77.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/digest.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 057e5f51ae4cd402a9a80105aa1dcd8993055a77 X-VCS-Branch: master Date: Wed, 1 Aug 2012 07:25:30 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: b1c976fa-70bf-4d30-b4f7-39ca4e69e6ff X-Archives-Hash: c10ed599a7c11ca95ea90fce9c5d0b1b commit: 057e5f51ae4cd402a9a80105aa1dcd8993055a77 Author: André Erdmann mailerd de> AuthorDate: Wed Aug 1 07:25:51 2012 +0000 Commit: André Erdmann mailerd de> CommitDate: Wed Aug 1 07:25:51 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=057e5f51 digest.py --- roverlay/digest.py | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-) diff --git a/roverlay/digest.py b/roverlay/digest.py new file mode 100644 index 0000000..4ccbca2 --- /dev/null +++ b/roverlay/digest.py @@ -0,0 +1,35 @@ +import hashlib + +def md5sum_file ( fh, binary_digest=False ): + """Returns the md5 sum for an already opened file.""" + md5 = hashlib.md5() + blocksize = 16384 + + block = fh.read ( blocksize ) + while block: + md5.update ( block ) + block = fh.read ( blocksize ) + + return md5.digest() if binary_digest else md5.hexdigest() +# --- end of md5sum_file (...) --- + + +_DIGEST_MAP = dict ( + md5 = md5sum_file, +) + +def digest_supported ( digest_type ): + """Returns True if the given digest type is supported, else False.""" + return digest_type in _DIGEST_MAP +# --- digest_supported (...) --- + +def dodigest_file ( _file, digest_type, binary_digest=False ): + ret = None + with open ( _file, mode='rb' ) as fh: + ret = _DIGEST_MAP [digest_type] ( fh, binary_digest=binary_digest ) + return ret +# --- end of dodigest_file (...) --- + +def digest_compare ( _file, digest, digest_type, binary_digest=False ): + return digest == dodigest_file ( _file, digest_type, binary_digest ) +# --- end of digest_compare (...) ---