Detect missing binaries for the hashing functions and abort if not found
authorEric Edgar <rocket@gentoo.org>
Mon, 19 Dec 2005 22:18:54 +0000 (22:18 +0000)
committerEric Edgar <rocket@gentoo.org>
Mon, 19 Dec 2005 22:18:54 +0000 (22:18 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@984 d1e1f19c-881f-0410-ab34-b69fee027534

ChangeLog
catalyst
modules/catalyst_support.py
modules/generic_stage_target.py

index 623592524380c0c564c952bb7290a59c4fb8588d..ef1df29c34249dc946bf28aa927fe5eeccf96543 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 # Copyright 2002-2005 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.471 2005/12/19 21:19:11 wolf31o2 Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.472 2005/12/19 22:18:54 rocket Exp $
+
+  19 Dec 2005; Eric Edgar <rocket@gentoo.org> catalyst,
+  modules/catalyst_support.py, modules/generic_stage_target.py:
+  Detect missing binaries for the hashing functions and abort if not found
 
   19 Dec 2005; Chris Gianelloni <wolf31o2@gentoo.org> README,
   files/catalyst.conf:
index f83c86499259ef33789fdd4580f22f4d2fd72573..0283631c9fe7883cf2cd70eab2b2e5ca8531b025 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -1,7 +1,7 @@
 #!/usr/bin/python -OO
 # Copyright 1999-2005 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.116 2005/12/19 20:53:13 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/catalyst,v 1.117 2005/12/19 22:18:54 rocket Exp $
 
 # Maintained in full by:
 # Eric Edgar <rocket@gentoo.org>
@@ -328,10 +328,39 @@ if __name__ == "__main__":
        if conf_values.has_key("digests"):
                for i in conf_values["digests"].split():
                        if not hash_map.has_key(i):
+                               print
+                               print i+" is not a valid digest entry"
                                print "Valid digest entries:"
                                print hash_map.keys()
-                               raise CatalystError, i+" is not a valid digest entry"
-       
+                               print
+                               print "Catalyst aborting...."
+                               sys.exit(2)
+                       if find_binary(hash_map[i][1]) == None:
+                               print
+                               print "digest="+i
+                               print "\tThe "+hash_map[i][1]+\
+                                       " binary was not found. It needs to be in your system path"
+                               print
+                               print "Catalyst aborting...."
+                               sys.exit(2)
+       if conf_values.has_key("hash_function"):
+               if not hash_map.has_key(conf_values["hash_function"]):
+                       print
+                       print conf_values["hash_function"]+" is not a valid hash_function entry"
+                       print "Valid hash_function entries:"
+                       print hash_map.keys()
+                       print
+                       print "Catalyst aborting...."
+                       sys.exit(2)
+               if find_binary(hash_map[conf_values["hash_function"]][1]) == None:
+                       print
+                       print "hash_function="+conf_values["hash_function"]
+                       print "\tThe "+hash_map[conf_values["hash_function"]][1]+\
+                               " binary was not found. It needs to be in your system path"
+                       print
+                       print "Catalyst aborting...."
+                       sys.exit(2)
+
        # import the rest of the catalyst modules
        targetmap=import_modules()
 
index 7262d306236b3d2b4a03528bfc19ae3605822468..8b2a8b486577cba916795d81ece868d46067d0ea 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2005 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.64 2005/12/19 20:53:13 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.65 2005/12/19 22:18:54 rocket Exp $
 
 import sys,string,os,types,re,signal,traceback,time
 #import md5,sha
@@ -67,12 +67,13 @@ def hexify(str):
 
 def generate_hash(file,hash_function="crc32",verbose=False):
        try:
-               return hash_map[hash_function][0](file,hash_map[hash_function][1],hash_map[hash_function][2],verbose)
+               return hash_map[hash_function][0](file,hash_map[hash_function][1],hash_map[hash_function][2],\
+                       hash_map[hash_function][3],verbose)
        except:
                raise CatalystError,"Error generating hash, is appropriate utility installed on your system?"
 
-def calc_hash(file,cmd,id_string="MD5",verbose=False):
-       a=os.popen(cmd+" "+file)
+def calc_hash(file,cmd,cmd_args,id_string="MD5",verbose=False):
+       a=os.popen(cmd+" "+cmd_args+" "+file)
        mylines=a.readlines()
        a.close()
        mylines=mylines[0].split()
@@ -81,8 +82,8 @@ def calc_hash(file,cmd,id_string="MD5",verbose=False):
                print id_string+" (%s) = %s" % (file, result)
        return result
 
-def calc_hash2(file,cmd,id_string="MD5",verbose=False):
-       a=os.popen(cmd+" "+file)
+def calc_hash2(file,cmd,cmd_args,id_string="MD5",verbose=False):
+       a=os.popen(cmd+" "+cmd_args+" "+file)
        a.readline()
        mylines=a.readline().split()
        a.close()
@@ -93,17 +94,18 @@ def calc_hash2(file,cmd,id_string="MD5",verbose=False):
 
 #This has map must be defined after the function calc_hash
 #It is possible to call different functions from this but they must be defined before hash_map
-hash_map={"md5":[calc_hash,"md5sum","MD5"],\
-        "crc32":[calc_hash,"crc32","CRC32"],\
-        "sha1":[calc_hash,"sha1sum","SHA1"],\
-        "sha224":[calc_hash2,"shash -a SHA224","SHA224"],\
-        "sha256":[calc_hash2,"shash -a SHA256","SHA256"],\
-        "sha384":[calc_hash2,"shash -a SHA384","SHA384"],\
-        "sha512":[calc_hash2,"shash -a SHA512","SHA512"],\
-        "ripemd128":[calc_hash2,"shash -a RIPEMD128","RIPEMD128"],\
-        "ripemd160":[calc_hash2,"shash -a RIPEMD160","RIPEMD160"],\
-        "ripemd256":[calc_hash2,"shash -a RIPEMD256","RIPEMD256"],\
-        "ripemd320":[calc_hash2,"shash -a RIPEMD320","RIPEMD320"]}
+#      Key,function,cmd,cmd_args,Print string
+hash_map={"md5":[calc_hash,"md5sum","","MD5"],\
+        "crc32":[calc_hash,"crc32","","CRC32"],\
+        "sha1":[calc_hash,"sha1sum","","SHA1"],\
+        "sha224":[calc_hash2,"shash","-a SHA224","SHA224"],\
+        "sha256":[calc_hash2,"shash","-a SHA256","SHA256"],\
+        "sha384":[calc_hash2,"shash","-a SHA384","SHA384"],\
+        "sha512":[calc_hash2,"shash","-a SHA512","SHA512"],\
+        "ripemd128":[calc_hash2,"shash","-a RIPEMD128","RIPEMD128"],\
+        "ripemd160":[calc_hash2,"shash","-a RIPEMD160","RIPEMD160"],\
+        "ripemd256":[calc_hash2,"shash","-a RIPEMD256","RIPEMD256"],\
+        "ripemd320":[calc_hash2,"shash","-a RIPEMD320","RIPEMD320"]}
 
 def read_from_clst(file):
        line = ''
@@ -179,8 +181,8 @@ class CatalystError(Exception):
                if message:
                        (type,value)=sys.exc_info()[:2]
                        if value!=None:
-                           print
-                           print traceback.print_exc(file=sys.stdout)
+                               print 
+                               print traceback.print_exc(file=sys.stdout)
                        print
                        print "!!! catalyst: "+message
                        print
index 3cf7fe4fefd4f5932f444c678e11a54d0f58cb83..fb8e5985ffc0214ec5af186b3a86d4c536db6160 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2005 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.101 2005/12/19 20:53:13 rocket Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.102 2005/12/19 22:18:54 rocket Exp $
 
 """
 This class does all of the chroot setup, copying of files, etc. It is
@@ -1269,7 +1269,7 @@ class generic_stage_target(generic_target):
                                                hash=generate_hash(file,hash_function=i,verbose=True)
                                        else:
                                                hash=generate_hash(file,hash_function=i)
-                                       myf.write(hash_map[i][2]+": "+hash+"\n")
+                                       myf.write(hash_map[i][3]+": "+hash+"\n")
                                myf.close()
 
        def purge(self):