public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <1444162801-10775-1-git-send-email-vapier@gentoo.org> (raw)

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



             reply	other threads:[~2015-10-06 20:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-06 20:20 Mike Frysinger [this message]
2015-10-08 17:22 ` [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444162801-10775-1-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gentoo-catalyst@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox