1 |
Make the file checksum generation code use an explicit checksum_file() |
2 |
method rather than implicit __call__. This should be more readable, |
3 |
and make it cleanly possible to add more methods. |
4 |
--- |
5 |
pym/portage/checksum.py | 15 +++++++++------ |
6 |
1 file changed, 9 insertions(+), 6 deletions(-) |
7 |
|
8 |
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py |
9 |
index 9f88f7e65..67d6a544f 100644 |
10 |
--- a/pym/portage/checksum.py |
11 |
+++ b/pym/portage/checksum.py |
12 |
@@ -59,7 +59,7 @@ class _generate_hash_function(object): |
13 |
hashfunc_map[hashtype] = self |
14 |
hashorigin_map[hashtype] = origin |
15 |
|
16 |
- def __call__(self, filename): |
17 |
+ def checksum_file(self, filename): |
18 |
""" |
19 |
Run a checksum against a file. |
20 |
|
21 |
@@ -186,11 +186,14 @@ if "WHIRLPOOL" not in hashfunc_map: |
22 |
from portage.util.whirlpool import new as _new_whirlpool |
23 |
whirlpoolhash = _generate_hash_function("WHIRLPOOL", _new_whirlpool, origin="bundled") |
24 |
|
25 |
+ |
26 |
# There is only one implementation for size |
27 |
-def getsize(filename): |
28 |
- size = os.stat(filename).st_size |
29 |
- return (size, size) |
30 |
-hashfunc_map["size"] = getsize |
31 |
+class SizeHash(object): |
32 |
+ def checksum_file(self, filename): |
33 |
+ size = os.stat(filename).st_size |
34 |
+ return (size, size) |
35 |
+ |
36 |
+hashfunc_map["size"] = SizeHash() |
37 |
|
38 |
# end actual hash functions |
39 |
|
40 |
@@ -420,7 +423,7 @@ def perform_checksum(filename, hashname="MD5", calc_prelink=0): |
41 |
if hashname not in hashfunc_map: |
42 |
raise portage.exception.DigestException(hashname + \ |
43 |
" hash function not available (needs dev-python/pycrypto)") |
44 |
- myhash, mysize = hashfunc_map[hashname](myfilename) |
45 |
+ myhash, mysize = hashfunc_map[hashname].checksum_file(myfilename) |
46 |
except (OSError, IOError) as e: |
47 |
if e.errno in (errno.ENOENT, errno.ESTALE): |
48 |
raise portage.exception.FileNotFound(myfilename) |
49 |
-- |
50 |
2.12.0 |