Begin splitting up generic_stage_target into smaller code blocks.
authorBrian Dolbec <dolsen@gentoo.org>
Sun, 20 Jan 2013 08:10:03 +0000 (00:10 -0800)
committerW. Trevor King <wking@tremily.us>
Sun, 15 Dec 2013 04:25:05 +0000 (20:25 -0800)
This so snapshot_target does not need to import it since most of it was
not used or initialized properly.

catalyst/targets/clearbase.py [new file with mode: 0644]
catalyst/targets/genbase.py [new file with mode: 0644]
catalyst/targets/generic_stage_target.py
catalyst/targets/snapshot_target.py
catalyst/targets/targetbase.py [moved from catalyst/targets/generic_target.py with 60% similarity]

diff --git a/catalyst/targets/clearbase.py b/catalyst/targets/clearbase.py
new file mode 100644 (file)
index 0000000..8519acc
--- /dev/null
@@ -0,0 +1,115 @@
+
+import os
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
+
+
+from catalyst.support import cmd, countdown
+
+
+class ClearBase(object):
+       """
+       This class does all of clearing after task completion
+       """
+       def __init__(self, myspec):
+               self.settings = myspec
+
+
+
+       def clear_autoresume(self):
+               """ Clean resume points since they are no longer needed """
+               if "autoresume" in self.settings["options"]:
+                       print "Removing AutoResume Points: ..."
+               myemp=self.settings["autoresume_path"]
+               if os.path.isdir(myemp):
+                               if "autoresume" in self.settings["options"]:
+                                       print "Emptying directory",myemp
+                               """
+                               stat the dir, delete the dir, recreate the dir and set
+                               the proper perms and ownership
+                               """
+                               mystat=os.stat(myemp)
+                               if os.uname()[0] == "FreeBSD":
+                                       cmd("chflags -R noschg "+myemp,\
+                                               "Could not remove immutable flag for file "\
+                                               +myemp)
+                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
+                               shutil.rmtree(myemp)
+                               os.makedirs(myemp,0755)
+                               os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+                               os.chmod(myemp,mystat[ST_MODE])
+
+
+       def clear_chroot(self):
+               myemp=self.settings["chroot_path"]
+               if os.path.isdir(myemp):
+                       print "Emptying directory",myemp
+                       """
+                       stat the dir, delete the dir, recreate the dir and set
+                       the proper perms and ownership
+                       """
+                       mystat=os.stat(myemp)
+                       #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
+                       """ There's no easy way to change flags recursively in python """
+                       if os.uname()[0] == "FreeBSD":
+                               os.system("chflags -R noschg "+myemp)
+                       shutil.rmtree(myemp)
+                       os.makedirs(myemp,0755)
+                       os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+                       os.chmod(myemp,mystat[ST_MODE])
+
+
+       def clear_packages(self):
+               if "pkgcache" in self.settings["options"]:
+                       print "purging the pkgcache ..."
+
+                       myemp=self.settings["pkgcache_path"]
+                       if os.path.isdir(myemp):
+                               print "Emptying directory",myemp
+                               """
+                               stat the dir, delete the dir, recreate the dir and set
+                               the proper perms and ownership
+                               """
+                               mystat=os.stat(myemp)
+                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
+                               shutil.rmtree(myemp)
+                               os.makedirs(myemp,0755)
+                               os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+                               os.chmod(myemp,mystat[ST_MODE])
+
+
+       def clear_kerncache(self):
+               if "kerncache" in self.settings["options"]:
+                       print "purging the kerncache ..."
+
+                       myemp=self.settings["kerncache_path"]
+                       if os.path.isdir(myemp):
+                               print "Emptying directory",myemp
+                               """
+                               stat the dir, delete the dir, recreate the dir and set
+                               the proper perms and ownership
+                               """
+                               mystat=os.stat(myemp)
+                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
+                               shutil.rmtree(myemp)
+                               os.makedirs(myemp,0755)
+                               os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
+                               os.chmod(myemp,mystat[ST_MODE])
+
+
+       def purge(self):
+               countdown(10,"Purging Caches ...")
+               if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
+                       print "clearing autoresume ..."
+                       self.clear_autoresume()
+
+                       print "clearing chroot ..."
+                       self.clear_chroot()
+
+                       if "PURGETMPONLY" not in self.settings:
+                               print "clearing package cache ..."
+                               self.clear_packages()
+
+                       print "clearing kerncache ..."
+                       self.clear_kerncache()
+
diff --git a/catalyst/targets/genbase.py b/catalyst/targets/genbase.py
new file mode 100644 (file)
index 0000000..e818781
--- /dev/null
@@ -0,0 +1,58 @@
+
+
+import os
+
+
+class GenBase(object):
+       """
+       This class does generation of the contents and digests files.
+       """
+       def __init__(self,myspec):
+               self.settings = myspec
+
+
+       def gen_contents_file(self,file):
+               if os.path.exists(file+".CONTENTS"):
+                       os.remove(file+".CONTENTS")
+               if "contents" in self.settings:
+                       contents_map = self.settings["contents_map"]
+                       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 = contents_map.generate_contents(file, 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:
+                       hash_map = self.settings["hash_map"]
+                       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 list(hash_map.hash_map):
+                                                               hash = hash_map.generate_hash(f,hash_=k,
+                                                                       verbose = "VERBOSE" in self.settings)
+                                                               myf.write(hash)
+                                               else:
+                                                       for j in array:
+                                                               hash = hash_map.generate_hash(f,hash_=j,
+                                                                       verbose = "VERBOSE" in self.settings)
+                                                               myf.write(hash)
+                               myf.close()
+
index e66b4308e08ad2d9408f89eab3d2d24ff11a0491..18e6278c6a57b79f5c7c6abd641afa4c4a7384a7 100644 (file)
@@ -9,14 +9,14 @@ from stat import ST_UID, ST_GID, ST_MODE
 
 
 from catalyst.support import (CatalystError, msg, file_locate, normpath,
-       touch, cmd, warn, list_bashify, countdown, read_makeconf, read_from_clst,
-       ismount)
-
-from generic_target import generic_target
+       touch, cmd, warn, list_bashify, read_makeconf, read_from_clst, ismount)
+from catalyst.targets.targetbase import TargetBase
+from catalyst.targets.clearbase import ClearBase
+from catalyst.targets.genbase import GenBase
 from catalyst.lock import LockDir
 
 
-class generic_stage_target(generic_target):
+class generic_stage_target(TargetBase, ClearBase, GenBase):
        """
        This class does all of the chroot setup, copying of files, etc. It is
        the driver class for pretty much everything that Catalyst does.
@@ -31,7 +31,9 @@ class generic_stage_target(generic_target):
                        "distcc_hosts","makeopts","pkgcache_path","kerncache_path"])
 
                self.set_valid_build_kernel_vars(addlargs)
-               generic_target.__init__(self,myspec,addlargs)
+               TargetBase.__init__(self, myspec, addlargs)
+               GenBase.__init__(self, myspec)
+               ClearBase.__init__(self, myspec)
 
                """
                The semantics of subarchmap and machinemap changed a bit in 2.0.3 to
@@ -1569,142 +1571,4 @@ class generic_stage_target(generic_target):
                                self.unbind()
                                raise CatalystError("build aborting due to livecd_update error.")
 
-       def clear_chroot(self):
-               myemp=self.settings["chroot_path"]
-               if os.path.isdir(myemp):
-                       print "Emptying directory",myemp
-                       """
-                       stat the dir, delete the dir, recreate the dir and set
-                       the proper perms and ownership
-                       """
-                       mystat=os.stat(myemp)
-                       #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
-                       """ There's no easy way to change flags recursively in python """
-                       if os.uname()[0] == "FreeBSD":
-                               os.system("chflags -R noschg "+myemp)
-                       shutil.rmtree(myemp)
-                       os.makedirs(myemp,0755)
-                       os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-                       os.chmod(myemp,mystat[ST_MODE])
-
-       def clear_packages(self):
-               if "pkgcache" in self.settings["options"]:
-                       print "purging the pkgcache ..."
-
-                       myemp=self.settings["pkgcache_path"]
-                       if os.path.isdir(myemp):
-                               print "Emptying directory",myemp
-                               """
-                               stat the dir, delete the dir, recreate the dir and set
-                               the proper perms and ownership
-                               """
-                               mystat=os.stat(myemp)
-                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
-                               shutil.rmtree(myemp)
-                               os.makedirs(myemp,0755)
-                               os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-                               os.chmod(myemp,mystat[ST_MODE])
-
-       def clear_kerncache(self):
-               if "kerncache" in self.settings["options"]:
-                       print "purging the kerncache ..."
-
-                       myemp=self.settings["kerncache_path"]
-                       if os.path.isdir(myemp):
-                               print "Emptying directory",myemp
-                               """
-                               stat the dir, delete the dir, recreate the dir and set
-                               the proper perms and ownership
-                               """
-                               mystat=os.stat(myemp)
-                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env=self.env)
-                               shutil.rmtree(myemp)
-                               os.makedirs(myemp,0755)
-                               os.chown(myemp,mystat[ST_UID],mystat[ST_GID])
-                               os.chmod(myemp,mystat[ST_MODE])
-
-       def clear_autoresume(self):
-               """ Clean resume points since they are no longer needed """
-               if "autoresume" in self.settings["options"]:
-                       print "Removing AutoResume Points: ..."
-               myemp=self.settings["autoresume_path"]
-               if os.path.isdir(myemp):
-                               if "autoresume" in self.settings["options"]:
-                                       print "Emptying directory",myemp
-                               """
-                               stat the dir, delete the dir, recreate the dir and set
-                               the proper perms and ownership
-                               """
-                               mystat=os.stat(myemp)
-                               if os.uname()[0] == "FreeBSD":
-                                       cmd("chflags -R noschg "+myemp,\
-                                               "Could not remove immutable flag for file "\
-                                               +myemp)
-                               #cmd("rm -rf "+myemp, "Could not remove existing file: "+myemp,env-self.env)
-                               shutil.rmtree(myemp)
-                               os.makedirs(myemp,0755)
-                               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:
-                       contents_map = self.settings["contents_map"]
-                       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 = contents_map.generate_contents(file, 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:
-                       hash_map = self.settings["hash_map"]
-                       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 list(hash_map.hash_map):
-                                                               hash = hash_map.generate_hash(f,hash_=k,
-                                                                       verbose = "VERBOSE" in self.settings)
-                                                               myf.write(hash)
-                                               else:
-                                                       for j in array:
-                                                               hash = hash_map.generate_hash(f,hash_=j,
-                                                                       verbose = "VERBOSE" in self.settings)
-                                                               myf.write(hash)
-                               myf.close()
-
-       def purge(self):
-               countdown(10,"Purging Caches ...")
-               if any(k in self.settings["options"] for k in ("purge","purgeonly","purgetmponly")):
-                       print "clearing autoresume ..."
-                       self.clear_autoresume()
-
-                       print "clearing chroot ..."
-                       self.clear_chroot()
-
-                       if "PURGETMPONLY" not in self.settings:
-                               print "clearing package cache ..."
-                               self.clear_packages()
-
-                       print "clearing kerncache ..."
-                       self.clear_kerncache()
-
 # vim: ts=4 sw=4 sta et sts=4 ai
index e6668376c5db0c971f24985e8f2a58f829139068..3289bbdec20960178f36579752fb58ab56889cf7 100644 (file)
@@ -8,9 +8,10 @@ from stat import ST_UID, ST_GID, ST_MODE
 
 
 from catalyst.support import normpath, cmd
-from generic_stage_target import generic_stage_target
+from catalyst.targets.targetbase import TargetBase
+from catalyst.targets.genbase import GenBase
 
-class snapshot_target(generic_stage_target):
+class snapshot_target(TargetBase, GenBase):
        """
        Builder class for snapshots.
        """
@@ -18,8 +19,9 @@ class snapshot_target(generic_stage_target):
                self.required_values=["version_stamp","target"]
                self.valid_values=["version_stamp","target"]
 
-               generic_stage_target.__init__(self,myspec,addlargs)
-               self.settings=myspec
+               TargetBase.__init__(self, myspec, addlargs)
+               GenBase.__init__(self,myspec)
+               #self.settings=myspec
                self.settings["target_subpath"]="portage"
                st=self.settings["storedir"]
                self.settings["snapshot_path"] = normpath(st + "/snapshots/"
similarity index 60%
rename from catalyst/targets/generic_target.py
rename to catalyst/targets/targetbase.py
index d3b9511ec5e1e1a2498bc67737199e991be9b0dd..b7a7428ae61c5b56a7609ef87bf991022af59ec2 100644 (file)
@@ -2,11 +2,11 @@
 
 from catalyst.support import addl_arg_parse
 
-class generic_target:
+class TargetBase(object):
        """
-       The toplevel class for generic_stage_target. This is about as generic as we get.
+       The toplevel class for all targets. This is about as generic as we get.
        """
-       def __init__(self,myspec,addlargs):
+       def __init__(self, myspec, addlargs):
                addl_arg_parse(myspec,addlargs,self.required_values,self.valid_values)
                self.settings=myspec
                self.env={}