aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-03-12 15:12:37 +0100
committerMichał Górny <mgorny@gentoo.org>2017-03-13 22:46:29 +0100
commit121e8a21abfad35f1a571bdbf228c3400e1e8f00 (patch)
tree58e1a34a4485db4bdf5d7bfdd3c68760de040c63
parentportage.checksum: Remove python-fchksum support (diff)
downloadportage-121e8a21abfad35f1a571bdbf228c3400e1e8f00.tar.gz
portage-121e8a21abfad35f1a571bdbf228c3400e1e8f00.tar.bz2
portage-121e8a21abfad35f1a571bdbf228c3400e1e8f00.zip
portage.checksum: create explicit checksum_file() method
Make the file checksum generation code use an explicit checksum_file() method rather than implicit __call__. This should be more readable, and make it cleanly possible to add more methods.
-rw-r--r--pym/portage/checksum.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index 9f88f7e65..67d6a544f 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -59,7 +59,7 @@ class _generate_hash_function(object):
hashfunc_map[hashtype] = self
hashorigin_map[hashtype] = origin
- def __call__(self, filename):
+ def checksum_file(self, filename):
"""
Run a checksum against a file.
@@ -186,11 +186,14 @@ if "WHIRLPOOL" not in hashfunc_map:
from portage.util.whirlpool import new as _new_whirlpool
whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled")
+
# There is only one implementation for size
-def getsize(filename):
- size = os.stat(filename).st_size
- return (size, size)
-hashfunc_map["size"] = getsize
+class SizeHash(object):
+ def checksum_file(self, filename):
+ size = os.stat(filename).st_size
+ return (size, size)
+
+hashfunc_map["size"] = SizeHash()
# end actual hash functions
@@ -420,7 +423,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0):
if hashname not in hashfunc_map:
raise portage.exception.DigestException(hashname + \
" hash function not available (needs dev-python/pycrypto)")
- myhash, mysize = hashfunc_map[hashname](myfilename)
+ myhash, mysize = hashfunc_map[hashname].checksum_file(myfilename)
except (OSError, IOError) as e:
if e.errno in (errno.ENOENT, errno.ESTALE):
raise portage.exception.FileNotFound(myfilename)