From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-catalyst+bounces-3302-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id 5A15F13888F
	for <garchives@archives.gentoo.org>; Tue,  6 Oct 2015 20:20:09 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 644BD21C001;
	Tue,  6 Oct 2015 20:20:06 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id ED6B821C001
	for <gentoo-catalyst@lists.gentoo.org>; Tue,  6 Oct 2015 20:20:05 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.gentoo.org (Postfix) with ESMTP id B5AA03406AD
	for <gentoo-catalyst@lists.gentoo.org>; Tue,  6 Oct 2015 20:20:02 +0000 (UTC)
From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-catalyst@lists.gentoo.org
Subject: [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto
Date: Tue,  6 Oct 2015 16:20:01 -0400
Message-Id: <1444162801-10775-1-git-send-email-vapier@gentoo.org>
X-Mailer: git-send-email 2.5.2
Precedence: bulk
List-Post: <mailto:gentoo-catalyst@lists.gentoo.org>
List-Help: <mailto:gentoo-catalyst+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-catalyst+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-catalyst+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-catalyst.gentoo.org>
X-BeenThere: gentoo-catalyst@lists.gentoo.org
Reply-to: gentoo-catalyst@lists.gentoo.org
X-Archives-Salt: 514b2f85-7737-43d4-9cd9-054c8f0d9fa4
X-Archives-Hash: 8ced7b79f8b86de9e7e86eeacdf6df2a

Rather than require people to list all possible hashes, add support for
an "auto" keyword.  This serves two purposes:
- any digest that is missing system support (e.g. missing prog), then
  that digest will be silently skipped
- if it's the only value, then all available digests will be added
---
 catalyst/main.py          | 47 +++++++++++++++++++++++++++++++++++------------
 doc/catalyst-config.5.txt |  2 +-
 etc/catalyst.conf         |  6 ++++--
 3 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/catalyst/main.py b/catalyst/main.py
index ebec4d3..65e1431 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -259,23 +259,46 @@ def main():
 
 	# Start checking that digests are valid now that hash_map is initialized
 	if "digests" in conf_values:
-		for i in conf_values["digests"].split():
-			if i not in HASH_DEFINITIONS:
-				print
-				print i+" is not a valid digest entry"
-				print "Valid digest entries:"
-				print HASH_DEFINITIONS.keys()
-				print
-				print "Catalyst aborting...."
-				sys.exit(2)
-			if find_binary(hash_map.hash_map[i].cmd) == None:
+		digests = set(conf_values['digests'].split())
+		valid_digests = set(HASH_DEFINITIONS.keys())
+
+		# Use the magic keyword "auto" to use all algos that are available.
+		skip_missing = auto_add = False
+		if 'auto' in digests:
+			auto_digests = True
+			digests.remove('auto')
+			if not digests:
+				digests = set(valid_digests)
+
+		# First validate all the requested digests are valid keys.
+		if digests - valid_digests:
+			print
+			print "These are not a valid digest entries:"
+			print ', '.join(digests - valid_digests)
+			print "Valid digest entries:"
+			print ', '.join(sorted(valid_digests))
+			print
+			print "Catalyst aborting...."
+			sys.exit(2)
+
+		# Then check for any programs that the hash func requires.
+		for digest in digests:
+			if find_binary(hash_map.hash_map[digest].cmd) == None:
+				# In auto mode, just ignore missing support.
+				if skip_missing:
+					digests.remove(digest)
+					continue
 				print
-				print "digest=" + i
-				print "\tThe " + hash_map.hash_map[i].cmd + \
+				print "digest=" + digest
+				print "\tThe " + hash_map.hash_map[digest].cmd + \
 					" binary was not found. It needs to be in your system path"
 				print
 				print "Catalyst aborting...."
 				sys.exit(2)
+
+		# Now reload the config with our updated value.
+		conf_values['digests'] = ' '.join(digests)
+
 	if "hash_function" in conf_values:
 		if conf_values["hash_function"] not in HASH_DEFINITIONS:
 			print
diff --git a/doc/catalyst-config.5.txt b/doc/catalyst-config.5.txt
index 31c4fe9..f778a80 100644
--- a/doc/catalyst-config.5.txt
+++ b/doc/catalyst-config.5.txt
@@ -24,7 +24,7 @@ and empty lines are interpreted as comments.  For example:
 
 ---------------------------------
 # /etc/catalyst/catalyst.conf
-digests="md5 sha1 sha512 whirlpool"
+digests="auto"
 contents="auto"
 distdir="/usr/portage/distfiles"
 envscript="/etc/catalyst/catalystrc"
diff --git a/etc/catalyst.conf b/etc/catalyst.conf
index a2abb4a..939e941 100644
--- a/etc/catalyst.conf
+++ b/etc/catalyst.conf
@@ -4,13 +4,15 @@
 # documentation for more information.
 
 # Creates a .DIGESTS file containing the hash output from any of the supported
-# options below.  Adding them all may take a long time.
+# options below.  Adding them all may take a long time on slower systems.  The
+# special "auto" keyword will skip digests that the system does not support,
+# and if it's the only keyword given, will default to enabling all digests.
 # Supported hashes:
 # adler32, crc32, crc32b, gost, haval128, haval160, haval192, haval224,
 # haval256, md2, md4, md5, ripemd128, ripemd160, ripemd256, ripemd320, sha1,
 # sha224, sha256, sha384, sha512, snefru128, snefru256, tiger, tiger128,
 # tiger160, whirlpool
-digests="md5 sha1 sha512 whirlpool"
+digests="auto"
 
 # Creates a .CONTENTS file listing the contents of the file. Pick from any of
 # the supported options below:
-- 
2.5.2