From: Eric Edgar Date: Fri, 2 Dec 2005 01:58:02 +0000 (+0000) Subject: Add sha/md5 digests support for grp and cleanup other sha/md5 code X-Git-Tag: CATALYST_2_0_6_916~570 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=873dfd63cbd734c834ec83ee52ec8fbbc1354f89;p=catalyst.git Add sha/md5 digests support for grp and cleanup other sha/md5 code git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@924 d1e1f19c-881f-0410-ab34-b69fee027534 --- diff --git a/ChangeLog b/ChangeLog index 32c01cb7..d1200d99 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.411 2005/12/01 21:29:30 rocket Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.412 2005/12/02 01:58:02 rocket Exp $ + + 02 Dec 2005; Eric Edgar modules/catalyst_support.py, + modules/generic_stage_target.py, modules/grp_target.py: + Add sha/md5 digests support for grp and cleanup other sha/md5 code 01 Dec 2005; Eric Edgar modules/grp_target.py: Fix folder name for grp build dir to not have .tar.bz2 at the end diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py index 19867843..c59aba15 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.58 2005/12/01 19:18:27 rocket Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/catalyst_support.py,v 1.59 2005/12/02 01:58:02 rocket Exp $ import sys,string,os,types,re,signal,traceback,md5,sha,time selinux_capable = False @@ -65,26 +65,27 @@ def hexify(str): # hexify() # A function to calculate the md5 sum of a file -def calc_md5(file): +def calc_md5(file,verbose=False): m = md5.new() f = open(file, 'r') for line in f.readlines(): m.update(line) f.close() md5sum = hexify(m.digest()) - print "MD5 (%s) = %s" % (file, md5sum) + if verbose: + print "MD5 (%s) = %s" % (file, md5sum) return md5sum # calc_md5 -def calc_sha(file): +def calc_sha(file,verbose=False): m = sha.new() f = open(file, 'r') for line in f.readlines(): m.update(line) f.close() shaval = hexify(m.digest()) - #shaval = sha.new(file(file).read()).hexdigest() # loads all into memory first - print "SHA (%s) = %s" % (file, shaval) + if verbose: + print "SHA (%s) = %s" % (file, shaval) return shaval def read_from_clst(file): diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py index 719ec3a8..2b217d48 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.81 2005/12/01 19:18:27 rocket Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/generic_stage_target.py,v 1.82 2005/12/02 01:58:02 rocket Exp $ """ This class does all of the chroot setup, copying of files, etc. It is @@ -334,8 +334,8 @@ class generic_stage_target(generic_target): if os.path.isfile(self.settings["source_path"]): if os.path.exists(self.settings["source_path"]): - self.settings["source_path_md5sum"]=calc_md5(self.settings["source_path"]) - self.settings["source_path_sha"]=calc_sha(self.settings["source_path"]) + self.settings["source_path_md5sum"]=calc_md5(self.settings["source_path"],True) + self.settings["source_path_sha"]=calc_sha(self.settings["source_path"],True) if os.path.isdir(self.settings["source_path"]): print "Source path set to "+self.settings["source_path"] print "\tIf this is not desired, remove this directory or turn of seedcache in the options of catalyst.conf" @@ -354,8 +354,8 @@ class generic_stage_target(generic_target): def set_snapshot_path(self): self.settings["snapshot_path"]=normpath(self.settings["storedir"]+"/snapshots/portage-"+self.settings["snapshot"]+".tar.bz2") if os.path.exists(self.settings["snapshot_path"]): - self.settings["snapshot_path_md5sum"]=calc_md5(self.settings["snapshot_path"]) - self.settings["snapshot_path_sha"]=calc_sha(self.settings["snapshot_path"]) + self.settings["snapshot_path_md5sum"]=calc_md5(self.settings["snapshot_path"],True) + self.settings["snapshot_path_sha"]=calc_sha(self.settings["snapshot_path"],True) def set_snapcache_path(self): if self.settings.has_key("SNAPCACHE"): @@ -899,19 +899,7 @@ class generic_stage_target(generic_target): cmd("tar cjf "+self.settings["target_path"]+" -C "+self.settings["stage_path"]+\ " .","Couldn't create stage tarball") - if self.settings.has_key("MD5") \ - and os.path.exists(self.settings["target_path"]): - md5=calc_md5(self.settings["target_path"]) - myf=open(self.settings["target_path"]+".digests","w") - myf.write("MD5: "+md5+"\n") - myf.close() - - if self.settings.has_key("SHA") \ - and os.path.exists(self.settings["target_path"]): - sha=calc_sha(self.settings["target_path"]) - myf=open(self.settings["target_path"]+".digests","w") - myf.write("SHA: "+sha+"\n") - myf.close() + self.gen_digest_file(self.settings["target_path"]+".digests") touch(self.settings["autoresume_path"]+"capture") @@ -1023,22 +1011,10 @@ class generic_stage_target(generic_target): if self.settings.has_key("iso"): cmd("/bin/bash "+self.settings["controller_file"]+" iso "+\ self.settings["iso"],"ISO creation script failed.") + self.gen_digest_file(self.settings["iso"]) touch(self.settings["autoresume_path"]+"create_iso") - if self.settings.has_key("MD5") \ - and os.path.exists(self.settings["iso"]): - md5=calc_md5(self.settings["iso"]) - myf=open(self.settings["iso"]+".digests","w") - myf.write("MD5: "+md5+"\n") - myf.close() - if self.settings.has_key("SHA") \ - and os.path.exists(self.settings["iso"]): - sha=calc_sha(self.settings["iso"]) - myf=open(self.settings["iso"]+".digests","w") - myf.write("SHA: "+sha+"\n") - myf.close() - else: print "WARNING livecd/iso was not defined." print "A CD Image will not be created, skipping create-iso.sh..." @@ -1221,6 +1197,23 @@ class generic_stage_target(generic_target): os.chown(myemp,mystat[ST_UID],mystat[ST_GID]) os.chmod(myemp,mystat[ST_MODE]) + def gen_digest_file(self,file): + if os.path.exists(file+".digests"): + os.remove(file+".digests") + if self.settings.has_key("SHA") or self.settings.has_key("MD5"): + if os.path.exists(file): + myf=open(file+".digests","w") + + if self.settings.has_key("MD5"): + md5=calc_md5(file) + myf.write("MD5: "+md5+"\n") + + if self.settings.has_key("SHA"): + sha=calc_sha(file) + myf.write("SHA: "+sha+"\n") + + myf.close() + def purge(self): countdown(10,"Purging Caches ...") if self.settings.has_key("PURGE"): diff --git a/modules/grp_target.py b/modules/grp_target.py index 281258b1..c0e41a7b 100644 --- a/modules/grp_target.py +++ b/modules/grp_target.py @@ -1,12 +1,12 @@ # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/modules/grp_target.py,v 1.16 2005/12/01 21:29:30 rocket Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/modules/grp_target.py,v 1.17 2005/12/02 01:58:02 rocket Exp $ """ The builder class for GRP (Gentoo Reference Platform) builds. """ -import os,types +import os,types,glob from catalyst_support import * from generic_stage_target import * @@ -40,12 +40,13 @@ class grp_target(generic_stage_target): print "Resume point detected, skipping target path setup operation..." else: # first clean up any existing target stuff - if os.path.isdir(self.settings["target_path"]): - cmd("rm -rf "+self.settings["target_path"], - "Could not remove existing directory: "+self.settings["target_path"]) - touch(self.settings["autoresume_path"]+"setup_target_path") + #if os.path.isdir(self.settings["target_path"]): + #cmd("rm -rf "+self.settings["target_path"], + #"Could not remove existing directory: "+self.settings["target_path"]) if not os.path.exists(self.settings["target_path"]): os.makedirs(self.settings["target_path"]) + + touch(self.settings["autoresume_path"]+"setup_target_path") def run_local(self): for pkgset in self.settings["grp"]: @@ -66,13 +67,6 @@ class grp_target(generic_stage_target): else: generic_stage_target.set_pkgcache_path(self) - def set_action_sequence(self): - self.settings["action_sequence"]=["unpack","unpack_snapshot",\ - "config_profile_link","setup_confdir","bind","chroot_setup",\ - "setup_environment","run_local","unbind",\ - "clear_autoresume"] - - def set_use(self): generic_stage_target.set_use(self) if self.settings.has_key("use"): @@ -83,6 +77,44 @@ class grp_target(generic_stage_target): def set_mounts(self): self.mounts.append("/tmp/grp") self.mountmap["/tmp/grp"]=self.settings["target_path"] + + def generate_digests(self): + for pkgset in self.settings["grp"]: + if self.settings["grp/"+pkgset+"/type"] == "pkgset": + destdir=normpath(self.settings["target_path"]+"/"+pkgset+"/All") + + digests=glob.glob(destdir+'/*.digests') + for i in digests: + if os.path.exists(i): + os.remove(i) + + files=os.listdir(destdir) + #ignore files starting with '.' using list comprehension + files=[filename for filename in files if filename[0] != '.'] + for i in files: + if os.path.isfile(normpath(destdir+"/"+i)): + self.gen_digest_file(normpath(destdir+"/"+i)) + else: + destdir=normpath(self.settings["target_path"]+"/"+pkgset) + + digests=glob.glob(destdir+'/*.digests') + for i in digests: + if os.path.exists(i): + os.remove(i) + + files=os.listdir(destdir) + #ignore files starting with '.' using list comprehension + files=[filename for filename in files if filename[0] != '.'] + for i in files: + if os.path.isfile(normpath(destdir+"/"+i)): + self.gen_digest_file(normpath(destdir+"/"+i)) + + + def set_action_sequence(self): + self.settings["action_sequence"]=["unpack","unpack_snapshot",\ + "config_profile_link","setup_confdir","bind","chroot_setup",\ + "setup_environment","run_local","unbind",\ + "generate_digests","clear_autoresume"] def register(foo): foo.update({"grp":grp_target})