1 |
Rather than require people to list all possible hashes, add support for |
2 |
an "auto" keyword. This serves two purposes: |
3 |
- any digest that is missing system support (e.g. missing prog), then |
4 |
that digest will be silently skipped |
5 |
- if it's the only value, then all available digests will be added |
6 |
--- |
7 |
catalyst/main.py | 47 +++++++++++++++++++++++++++++++++++------------ |
8 |
doc/catalyst-config.5.txt | 2 +- |
9 |
etc/catalyst.conf | 6 ++++-- |
10 |
3 files changed, 40 insertions(+), 15 deletions(-) |
11 |
|
12 |
diff --git a/catalyst/main.py b/catalyst/main.py |
13 |
index ebec4d3..65e1431 100644 |
14 |
--- a/catalyst/main.py |
15 |
+++ b/catalyst/main.py |
16 |
@@ -259,23 +259,46 @@ def main(): |
17 |
|
18 |
# Start checking that digests are valid now that hash_map is initialized |
19 |
if "digests" in conf_values: |
20 |
- for i in conf_values["digests"].split(): |
21 |
- if i not in HASH_DEFINITIONS: |
22 |
- print |
23 |
- print i+" is not a valid digest entry" |
24 |
- print "Valid digest entries:" |
25 |
- print HASH_DEFINITIONS.keys() |
26 |
- print |
27 |
- print "Catalyst aborting...." |
28 |
- sys.exit(2) |
29 |
- if find_binary(hash_map.hash_map[i].cmd) == None: |
30 |
+ digests = set(conf_values['digests'].split()) |
31 |
+ valid_digests = set(HASH_DEFINITIONS.keys()) |
32 |
+ |
33 |
+ # Use the magic keyword "auto" to use all algos that are available. |
34 |
+ skip_missing = auto_add = False |
35 |
+ if 'auto' in digests: |
36 |
+ auto_digests = True |
37 |
+ digests.remove('auto') |
38 |
+ if not digests: |
39 |
+ digests = set(valid_digests) |
40 |
+ |
41 |
+ # First validate all the requested digests are valid keys. |
42 |
+ if digests - valid_digests: |
43 |
+ print |
44 |
+ print "These are not a valid digest entries:" |
45 |
+ print ', '.join(digests - valid_digests) |
46 |
+ print "Valid digest entries:" |
47 |
+ print ', '.join(sorted(valid_digests)) |
48 |
+ print |
49 |
+ print "Catalyst aborting...." |
50 |
+ sys.exit(2) |
51 |
+ |
52 |
+ # Then check for any programs that the hash func requires. |
53 |
+ for digest in digests: |
54 |
+ if find_binary(hash_map.hash_map[digest].cmd) == None: |
55 |
+ # In auto mode, just ignore missing support. |
56 |
+ if skip_missing: |
57 |
+ digests.remove(digest) |
58 |
+ continue |
59 |
print |
60 |
- print "digest=" + i |
61 |
- print "\tThe " + hash_map.hash_map[i].cmd + \ |
62 |
+ print "digest=" + digest |
63 |
+ print "\tThe " + hash_map.hash_map[digest].cmd + \ |
64 |
" binary was not found. It needs to be in your system path" |
65 |
print |
66 |
print "Catalyst aborting...." |
67 |
sys.exit(2) |
68 |
+ |
69 |
+ # Now reload the config with our updated value. |
70 |
+ conf_values['digests'] = ' '.join(digests) |
71 |
+ |
72 |
if "hash_function" in conf_values: |
73 |
if conf_values["hash_function"] not in HASH_DEFINITIONS: |
74 |
print |
75 |
diff --git a/doc/catalyst-config.5.txt b/doc/catalyst-config.5.txt |
76 |
index 31c4fe9..f778a80 100644 |
77 |
--- a/doc/catalyst-config.5.txt |
78 |
+++ b/doc/catalyst-config.5.txt |
79 |
@@ -24,7 +24,7 @@ and empty lines are interpreted as comments. For example: |
80 |
|
81 |
--------------------------------- |
82 |
# /etc/catalyst/catalyst.conf |
83 |
-digests="md5 sha1 sha512 whirlpool" |
84 |
+digests="auto" |
85 |
contents="auto" |
86 |
distdir="/usr/portage/distfiles" |
87 |
envscript="/etc/catalyst/catalystrc" |
88 |
diff --git a/etc/catalyst.conf b/etc/catalyst.conf |
89 |
index a2abb4a..939e941 100644 |
90 |
--- a/etc/catalyst.conf |
91 |
+++ b/etc/catalyst.conf |
92 |
@@ -4,13 +4,15 @@ |
93 |
# documentation for more information. |
94 |
|
95 |
# Creates a .DIGESTS file containing the hash output from any of the supported |
96 |
-# options below. Adding them all may take a long time. |
97 |
+# options below. Adding them all may take a long time on slower systems. The |
98 |
+# special "auto" keyword will skip digests that the system does not support, |
99 |
+# and if it's the only keyword given, will default to enabling all digests. |
100 |
# Supported hashes: |
101 |
# adler32, crc32, crc32b, gost, haval128, haval160, haval192, haval224, |
102 |
# haval256, md2, md4, md5, ripemd128, ripemd160, ripemd256, ripemd320, sha1, |
103 |
# sha224, sha256, sha384, sha512, snefru128, snefru256, tiger, tiger128, |
104 |
# tiger160, whirlpool |
105 |
-digests="md5 sha1 sha512 whirlpool" |
106 |
+digests="auto" |
107 |
|
108 |
# Creates a .CONTENTS file listing the contents of the file. Pick from any of |
109 |
# the supported options below: |
110 |
-- |
111 |
2.5.2 |