Move gen_contents_file() and gen_digest_file() from catalyst.target.generic_stage...
authorAndrew Gaffney <agaffney@gentoo.org>
Mon, 12 Jan 2009 02:28:32 +0000 (20:28 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Mon, 12 Jan 2009 02:28:32 +0000 (20:28 -0600)
ChangeLog
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

index afe30aba6fb5ee8b2e29eafea674b07822ca9838..3f3af62e3fa11e7fd49b51842ad363c73c56bef4 100644 (file)
--- 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 <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:
index bdcb0997f54f1ea8c7d0523198e1b8cffa27bbc7..5a8b879a2697176e4ab9890c480330df20915d2c 100644 (file)
@@ -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"],
 }
+
index 7b34c4236a0c88c6b023c1902d3cc60f8f77809f..76cd2ecfee0645e933429f5f33086eb1bf7afb91 100644 (file)
@@ -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:
index 9688077a18637f6599c0f106bee695c28de13fd4..8890236cc50c42f4777d23caab4ef4c117877e73 100644 (file)
@@ -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:
index 6cf15d10d004129794370523688fa23e2647cc2c..6b7770ddf50b752480908e646e43b24403c20653 100644 (file)
@@ -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",\
index b5de4d55c07759bd6cd7210d22cf92ea4119e294..bd9b8f07900b70f9152afeb9ca46b3337b41c4a7 100644 (file)
@@ -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!"