1 |
On Wed, Nov 23, 2005 at 08:05:33PM +0100, Marius Mauch wrote: |
2 |
> --- pym/portage_checksum.py 2005-11-13 14:55:16.000000000 +0100 |
3 |
> +++ pym/portage_checksum.py 2005-11-23 19:53:53.000000000 +0100 |
4 |
> @@ -4,7 +4,7 @@ |
5 |
> # $Id: /var/cvsroot/gentoo-src/portage/pym/portage_checksum.py,v 1.10.2.2 2005/08/10 05:42:03 ferringb Exp $ |
6 |
|
7 |
+hashfuncs = {} |
8 |
|
9 |
> -from portage_const import PRIVATE_PATH,PRELINK_BINARY |
10 |
> +from portage_const import PRIVATE_PATH,PRELINK_BINARY,HASHING_BLOCKSIZE |
11 |
> import os |
12 |
> import shutil |
13 |
> import stat |
14 |
> @@ -14,6 +14,42 @@ |
15 |
> import commands |
16 |
> import sha |
17 |
> |
18 |
> + |
19 |
> +# actual hash functions first |
20 |
> +# We _try_ to load this module. If it fails we do the slightly slower fallback. |
21 |
> +try: |
22 |
> + import fchksum |
23 |
> + |
24 |
> + def md5hash(filename): |
25 |
> + return fchksum.fmd5t(filename) |
26 |
> + |
27 |
> +except ImportError: |
28 |
> + import md5 |
29 |
> + def md5hash(filename): |
30 |
> + return pyhash(filename, md5) |
31 |
|
32 |
+hashfuncs["md5"] = md5hash |
33 |
|
34 |
> +def sha1hash(filename): |
35 |
> + return pyhash(filename, sha) |
36 |
|
37 |
+hashfuncs["sha1"] = sha1hash |
38 |
|
39 |
> +# Keep pycrypto optional for now, there are no internal fallbacks for these |
40 |
> +try: |
41 |
> + import Crypto.Hash.SHA256 |
42 |
> + |
43 |
> + def sha256hash(filename): |
44 |
> + return pyhash(filename, Crypto.Hash.SHA256) |
45 |
|
46 |
+ hashfuncs["sha256"] = sha256hash |
47 |
|
48 |
> +except ImportError: |
49 |
pass |
50 |
> + |
51 |
> +try: |
52 |
> + import Crypto.Hash.RIPEMD |
53 |
> + |
54 |
> + def rmd160hash(filename): |
55 |
> + return pyhash(filename, Crypto.Hash.RIPEMD) |
56 |
|
57 |
+ hashfuncs["rmd160hash"] = rmd160hash |
58 |
|
59 |
> +except ImportError: |
60 |
pass |
61 |
|
62 |
> +# end actual hash functions |
63 |
> + |
64 |
> prelink_capable = False |
65 |
> if os.path.exists(PRELINK_BINARY): |
66 |
> results = commands.getstatusoutput(PRELINK_BINARY+" --version > /dev/null 2>&1") |
67 |
> @@ -21,20 +57,29 @@ |
68 |
> prelink_capable=1 |
69 |
> del results |
70 |
> |
71 |
|
72 |
<snip> |
73 |
|
74 |
Add the keys only if there is a func that can be used- list of |
75 |
required chksums is a config thing (and repoman thing during |
76 |
commiting), so I'm not seeing any reason to have None as a value in |
77 |
your hashfunc mapping... |
78 |
~harring |