# Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS)
# Distributed under the GPL v2
+ 12 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
+ modules/catalyst/hash.py, modules/catalyst/target/generic.py,
+ modules/catalyst/target/generic_stage.py, modules/catalyst/target/grp.py,
+ modules/catalyst/target/snapshot.py:
+ Move gen_contents_file() and gen_digest_file() from
+ catalyst.target.generic_stage to catalyst.hash
+
12 Jan 2009; Andrew Gaffney <agaffney@gentoo.org>
targets/netboot/netboot-controller.sh, +targets/netboot/netboot-final.sh,
-targets/support/netboot-final.sh:
from catalyst.error import *
from catalyst.output import warn
+def gen_contents_file(file, settings):
+ if os.path.exists(file+".CONTENTS"):
+ os.remove(file+".CONTENTS")
+ if "contents" in settings:
+ if os.path.exists(file):
+ myf=open(file+".CONTENTS","w")
+ keys={}
+ for i in settings["contents"].split():
+ keys[i]=1
+ array=keys.keys()
+ array.sort()
+ for j in array:
+ contents = generate_contents(file,contents_function=j,\
+ verbose=("VERBOSE" in settings))
+ if contents:
+ myf.write(contents)
+ myf.close()
+
+def gen_digest_file(file, settings):
+ if os.path.exists(file+".DIGESTS"):
+ os.remove(file+".DIGESTS")
+ if "digests" in settings:
+ if os.path.exists(file):
+ myf=open(file+".DIGESTS","w")
+ keys={}
+ for i in settings["digests"].split():
+ keys[i]=1
+ array=keys.keys()
+ array.sort()
+ for f in [file, file+'.CONTENTS']:
+ if os.path.exists(f):
+ if "all" in array:
+ for k in catalyst.hash.hash_map.keys():
+ tmphash = generate_hash(f,hash_function=k,verbose=\
+ ("VERBOSE" in settings))
+ myf.write(tmphash)
+ else:
+ for j in array:
+ tmphash = generate_hash(f,hash_function=j,verbose=\
+ ("VERBOSE" in settings))
+ myf.write(tmphash)
+ myf.close()
+
def generate_contents(file, contents_function="auto", verbose=False):
try:
_ = contents_function
"tiger160":[calc_hash2,"shash","-a TIGER160","TIGER160"],
"whirlpool":[calc_hash2,"shash","-a WHIRLPOOL","WHIRLPOOL"],
}
+
-
"""
The toplevel class for generic_stage_target. This is about as generic as we get.
"""
+import os
from catalyst.support import *
class generic_target:
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"])
+ catalyst.hash.gen_contents_file(self.settings["target_path"], self.settings)
+ catalyst.hash.gen_digest_file(self.settings["target_path"], settings)
catalyst.util.touch(self.settings["autoresume_path"]+"capture")
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"])
+ catalyst.hash.gen_contents_file(self.settings["iso"], self.settings)
+ catalyst.hash.gen_digest_file(self.settings["iso"], self.settings)
catalyst.util.touch(self.settings["autoresume_path"]+"create_iso")
else:
print "WARNING: livecd/iso was not defined."
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 "contents" in self.settings:
- 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=catalyst.hash.generate_contents(file,contents_function=j,\
- verbose=("VERBOSE" in self.settings))
- if contents:
- myf.write(contents)
- myf.close()
-
- def gen_digest_file(self,file):
- if os.path.exists(file+".DIGESTS"):
- os.remove(file+".DIGESTS")
- if "digests" in self.settings:
- if os.path.exists(file):
- myf=open(file+".DIGESTS","w")
- keys={}
- for i in self.settings["digests"].split():
- keys[i]=1
- array=keys.keys()
- array.sort()
- for f in [file, file+'.CONTENTS']:
- if os.path.exists(f):
- if "all" in array:
- for k in catalyst.hash.hash_map.keys():
- tmphash=catalyst.hash.generate_hash(f,hash_function=k,verbose=\
- ("VERBOSE" in self.settings))
- myf.write(tmphash)
- else:
- for j in array:
- tmphash=catalyst.hash.generate_hash(f,hash_function=j,verbose=\
- ("VERBOSE" in self.settings))
- myf.write(tmphash)
- myf.close()
-
def purge(self):
catalyst.util.countdown(10, "Purging Caches ...")
if "PURGE" in self.settings or "PURGEONLY" in self.settings:
import os,types,glob
from catalyst.support import *
from generic_stage import *
-import catalyst.util
+import catalyst
from catalyst.error import *
from catalyst.spawn import *
files=[filename for filename in files if filename[0] != '.']
for i in files:
if os.path.isfile(catalyst.util.normpath(destdir+"/"+i)):
- self.gen_contents_file(catalyst.util.normpath(destdir+"/"+i))
- self.gen_digest_file(catalyst.util.normpath(destdir+"/"+i))
+ catalyst.hash.gen_contents_file(catalyst.util.normpath(destdir+"/"+i), self.settings)
+ catalyst.hash.gen_digest_file(catalyst.util.normpath(destdir+"/"+i), self.settings)
else:
destdir=catalyst.util.normpath(self.settings["target_path"]+"/"+pkgset)
print "Digesting files in the srcset....."
files=[filename for filename in files if filename[0] != '.']
for i in files:
if os.path.isfile(catalyst.util.normpath(destdir+"/"+i)):
- #self.gen_contents_file(catalyst.util.normpath(destdir+"/"+i))
- self.gen_digest_file(catalyst.util.normpath(destdir+"/"+i))
+ #catalyst.hash.gen_contents_file(catalyst.util.normpath(destdir+"/"+i), self.settings)
+ catalyst.hash.gen_digest_file(catalyst.util.normpath(destdir+"/"+i), self.settings)
def set_action_sequence(self):
self.settings["action_sequence"]=["unpack","unpack_snapshot",\
import os
from catalyst.support import *
from generic_stage import *
-import catalyst.util
+import catalyst
from catalyst.spawn import *
-class snapshot_target(generic_stage_target):
+class snapshot_target(generic_target):
def __init__(self,myspec,addlargs):
self.required_values=["version_stamp","target"]
self.valid_values=["version_stamp","target"]
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"])
+ catalyst.hash.gen_contents_file(self.settings["snapshot_path"], self.settings)
+ catalyst.hash.gen_digest_file(self.settings["snapshot_path"], self.settings)
self.cleanup()
print "snapshot: complete!"