Lars Weiler <pylon@gentoo.org>
Andrew Gaffney <agaffney@gentoo.org>
Diego Pettenò <flameeyes@gentoo.org>
+Robin H. Johnson <robbat2@gentoo.org>
# Copyright 2002-2008 Gentoo Foundation; Distributed under the GPL v2
# $Id: $
+ 08 Feb 2008; Chris Gianelloni <wolf31o2@gentoo.org> AUTHORS, catalyst,
+ files/catalyst.conf, modules/catalyst_support.py,
+ modules/generic_stage_target.py, modules/grp_target.py,
+ modules/snapshot_target.py:
+ Added support for generating CONTENTS files automatically. Patch by Robin
+ Johnson <robbat2@gentoo.org> for bug #207862.
+
08 Feb 2008; Chris Gianelloni <wolf31o2@gentoo.org>
modules/snapshot_target.py:
Add a patch from Robin Johnson <robbat2@gentoo.org> from bug #207860 to
if myconf.has_key("digests"):
conf_values["digests"]=myconf["digests"]
+ if myconf.has_key("contents"):
+ conf_values["contents"]=myconf["contents"]
if myconf.has_key("envscript"):
print "Envscript support enabled."
# ripemd256, sha256, sha512, ripemd160, md5
digests="md5 sha1"
+# Creates a .CONTENTS file listing the contents of the file. Pick from any of
+# the supported options below:
+# auto - strongly recommended
+# tar-tv - does 'tar tvf FILE'
+# tar-tvz - does 'tar tvzf FILE'
+# tar-tvy - does 'tar tvyf FILE'
+# isoinfo-l - does 'isoinfo -l -i FILE'
+# isoinfo-f - does 'isoinfo -f -i FILE'
+# 'isoinfo-f' is the only option not chosen by the automatic algorithm.
+# If this variable is empty, no .CONTENTS will be generated at all.
+contents="auto"
+
# distdir specifies where your distfiles are located. This setting should
# work fine for most default installations.
distdir="/usr/portage/distfiles"
return r
# hexify()
+def generate_contents(file,contents_function="auto",verbose=False):
+ try:
+ _ = contents_function
+ if _ is 'auto' and file.endswith('.iso'):
+ _ = 'isoinfo-l'
+ if (_ in ['tar-tv','auto']):
+ if file.endswith('.tgz') or file.endswith('.tar.gz'):
+ _ = 'tar-tvz'
+ elif file.endswith('.tbz2') or file.endswith('.tar.bz2'):
+ _ = 'tar-tvj'
+ elif file.endswith('.tar'):
+ _ = 'tar-tv'
+
+ contents_function = _
+ _ = contents_map[contents_function]
+ return _[0](file,_[1],verbose)
+ except:
+ raise CatalystError,\
+ "Error generating contents, is appropriate utility (%s) installed on your system?" \
+ % (contents_function, )
+
+def calc_contents(file,cmd,verbose):
+ args={ 'file': file }
+ cmd=cmd % dict(args)
+ a=os.popen(cmd)
+ mylines=a.readlines()
+ a.close()
+ result="".join(mylines)
+ if verbose:
+ print result
+ return result
+
+# This has map must be defined after the function calc_content
+# It is possible to call different functions from this but they must be defined
+# before hash_map
+# Key,function,cmd
+contents_map={
+ # 'find' is disabled because it requires the source path, which is not
+ # always available
+ #"find" :[calc_content,"find %(path)s"],
+ "tar-tv":[calc_content,"tar tvf %(file)s"],
+ "tar-tvz":[calc_content,"tar tvzf %(file)s"],
+ "tar-tvj":[calc_content,"tar tvjf %(file)s"],
+ "isoinfo-l":[calc_content,"isoinfo -l -i %(file)s"],
+ # isoinfo-f should be a last resort only
+ "isoinfo-f":[calc_content,"isoinfo -f -i %(file)s"],
+}
+
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],\
valid_config_file_values.append("snapshot_cache")
valid_config_file_values.append("hash_function")
valid_config_file_values.append("digests")
+valid_config_file_values.append("contents")
valid_config_file_values.append("SEEDCACHE")
verbosity=1
# The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
# work better with vapier's CBUILD stuff. I've removed the "monolithic"
- # machinemap from this file and split up its contents amongst the various
- # arch/foo.py files.
+ # machinemap from this file and split up its contents amongst the
+ # various arch/foo.py files.
#
# When register() is called on each module in the arch/ dir, it now
# returns a tuple instead of acting on the subarchmap dict that is
cmd("tar cjpf "+self.settings["target_path"]+" -C "+self.settings["stage_path"]+\
" .","Couldn't create stage tarball",env=self.env)
+ self.gen_contents_file(self.settings["target_path"])
self.gen_digest_file(self.settings["target_path"])
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.",env=self.env)
+ self.gen_contents_file(self.settings["iso"])
self.gen_digest_file(self.settings["iso"])
touch(self.settings["autoresume_path"]+"create_iso")
os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
os.chmod(myemp,mystat[ST_MODE])
+
+ def gen_contents_file(self,file):
+ if os.path.exists(file+".CONTENTS"):
+ os.remove(file+".CONTENTS")
+ if self.settings.has_key("contents"):
+ if os.path.exists(file):
+ myf=open(file+".CONTENTS","w")
+ keys={}
+ for i in self.settings["contents"].split():
+ keys[i]=1
+ array=keys.keys()
+ array.sort()
+ for j in array:
+ contents=generate_contents(file,contents_function=j,verbose=self.settings.has_key("VERBOSE"))
+ myf.write(contents)
+ myf.close()
+
def gen_digest_file(self,file):
if os.path.exists(file+".DIGESTS"):
os.remove(file+".DIGESTS")
keys[i]=1
array=keys.keys()
array.sort()
- for j in array:
- if self.settings.has_key("VERBOSE"):
- hash=generate_hash(file,hash_function=j,verbose=True)
- else:
- hash=generate_hash(file,hash_function=j)
- myf.write(hash)
+ for f in [file, file+'.CONTENTS']:
+ if os.path.exists(f):
+ for j in array:
+ hash=generate_hash(f,hash_function=j,verbose=self.settings.has_key("VERBOSE"))
+ myf.write(hash)
myf.close()
def purge(self):
files=[filename for filename in files if filename[0] != '.']
for i in files:
if os.path.isfile(normpath(destdir+"/"+i)):
+ self.gen_contents_file(normpath(destdir+"/"+i))
self.gen_digest_file(normpath(destdir+"/"+i))
else:
destdir=normpath(self.settings["target_path"]+"/"+pkgset)
files=[filename for filename in files if filename[0] != '.']
for i in files:
if os.path.isfile(normpath(destdir+"/"+i)):
+ self.gen_contents_file(normpath(destdir+"/"+i))
self.gen_digest_file(normpath(destdir+"/"+i))
def set_action_sequence(self):
cmd("tar cjf "+self.settings["snapshot_path"]+" -C "+mytmp+" portage",\
"Snapshot creation failure",env=self.env)
+ self.gen_contents_file(self.settings["snapshot_path"])
self.gen_digest_file(self.settings["snapshot_path"])
self.cleanup()