From e14877bdf49f4792955236af22c2b3d3613522c8 Mon Sep 17 00:00:00 2001 From: Andrew Gaffney Date: Sun, 11 Jan 2009 20:28:32 -0600 Subject: [PATCH] Move gen_contents_file() and gen_digest_file() from catalyst.target.generic_stage to catalyst.hash --- ChangeLog | 7 ++++ modules/catalyst/hash.py | 44 ++++++++++++++++++++ modules/catalyst/target/generic.py | 2 +- modules/catalyst/target/generic_stage.py | 51 ++---------------------- modules/catalyst/target/grp.py | 10 ++--- modules/catalyst/target/snapshot.py | 8 ++-- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index afe30aba..3f3af62e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,13 @@ # Copyright 2002-2009 Gentoo Foundation; 2008-2009 Various authors (see AUTHORS) # Distributed under the GPL v2 + 12 Jan 2009; Andrew Gaffney + 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 targets/netboot/netboot-controller.sh, +targets/netboot/netboot-final.sh, -targets/support/netboot-final.sh: diff --git a/modules/catalyst/hash.py b/modules/catalyst/hash.py index bdcb0997..5a8b879a 100644 --- a/modules/catalyst/hash.py +++ b/modules/catalyst/hash.py @@ -6,6 +6,49 @@ import os 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 @@ -116,3 +159,4 @@ hash_map={ "tiger160":[calc_hash2,"shash","-a TIGER160","TIGER160"], "whirlpool":[calc_hash2,"shash","-a WHIRLPOOL","WHIRLPOOL"], } + diff --git a/modules/catalyst/target/generic.py b/modules/catalyst/target/generic.py index 7b34c423..76cd2ecf 100644 --- a/modules/catalyst/target/generic.py +++ b/modules/catalyst/target/generic.py @@ -1,8 +1,8 @@ - """ The toplevel class for generic_stage_target. This is about as generic as we get. """ +import os from catalyst.support import * class generic_target: diff --git a/modules/catalyst/target/generic_stage.py b/modules/catalyst/target/generic_stage.py index 9688077a..8890236c 100644 --- a/modules/catalyst/target/generic_stage.py +++ b/modules/catalyst/target/generic_stage.py @@ -1172,8 +1172,8 @@ class generic_stage_target(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") @@ -1315,8 +1315,8 @@ class generic_stage_target(generic_target): 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." @@ -1577,49 +1577,6 @@ class generic_stage_target(generic_target): 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: diff --git a/modules/catalyst/target/grp.py b/modules/catalyst/target/grp.py index 6cf15d10..6b7770dd 100644 --- a/modules/catalyst/target/grp.py +++ b/modules/catalyst/target/grp.py @@ -6,7 +6,7 @@ The builder class for GRP (Gentoo Reference Platform) builds. 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 * @@ -87,8 +87,8 @@ class grp_target(generic_stage_target): 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....." @@ -103,8 +103,8 @@ class grp_target(generic_stage_target): 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",\ diff --git a/modules/catalyst/target/snapshot.py b/modules/catalyst/target/snapshot.py index b5de4d55..bd9b8f07 100644 --- a/modules/catalyst/target/snapshot.py +++ b/modules/catalyst/target/snapshot.py @@ -6,10 +6,10 @@ Builder class for snapshots. 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"] @@ -53,8 +53,8 @@ class snapshot_target(generic_stage_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!" -- 2.26.2