From: Eric Edgar Date: Mon, 19 Dec 2005 22:18:54 +0000 (+0000) Subject: Detect missing binaries for the hashing functions and abort if not found X-Git-Tag: CATALYST_2_0_6_916~510 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=34f191c584e69636406de8ae96154e6c79ee02d7;p=catalyst.git Detect missing binaries for the hashing functions and abort if not found git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@984 d1e1f19c-881f-0410-ab34-b69fee027534 --- diff --git a/ChangeLog b/ChangeLog index 62359252..ef1df29c 100644 --- 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 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 README, files/catalyst.conf: diff --git a/catalyst b/catalyst index f83c8649..0283631c 100755 --- 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 @@ -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() diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py index 7262d306..8b2a8b48 100644 --- a/modules/catalyst_support.py +++ b/modules/catalyst_support.py @@ -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 diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py index 3cf7fe4f..fb8e5985 100644 --- a/modules/generic_stage_target.py +++ b/modules/generic_stage_target.py @@ -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):