# 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 <rocket@gentoo.org> 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 <rocket@gentoo.org> modules/grp_target.py:
Fix folder name for grp build dir to not have .tar.bz2 at the end
# 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
# 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):
# 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
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"
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"):
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")
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..."
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"):
# 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 *
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"]:
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"):
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})