public inbox for gentoo-catalyst@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto
@ 2015-10-06 20:20 Mike Frysinger
  2015-10-08 17:22 ` Mike Frysinger
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2015-10-06 20:20 UTC (permalink / raw
  To: gentoo-catalyst

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto
  2015-10-06 20:20 [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto Mike Frysinger
@ 2015-10-08 17:22 ` Mike Frysinger
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Frysinger @ 2015-10-08 17:22 UTC (permalink / raw
  To: gentoo-catalyst

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

i've pushed these since snapshot & stage[123] still works.
also verified behavior of things like:
	digests="auto"
	digests="auto crc32"
	digests="auto crc32 asdf"
	digests="crc32"
-mike

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-08 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06 20:20 [gentoo-catalyst] [PATCH] catalyst: add support for digests=auto Mike Frysinger
2015-10-08 17:22 ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox