commit:     9ee6508a43da4f23761a585d658dafa716e4c0d2
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 20 08:10:03 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue Sep  2 06:31:50 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=9ee6508a

Begin splitting up generic_stage_target into smaller code blocks.

This so snapshot_target does not need to import it since most of it was
not used or initialized properly.

Conflicts:
        catalyst/targets/generic_stage_target.py
        catalyst/targets/snapshot_target.py

---
 catalyst/defaults.py                               |   2 +-
 catalyst/targets/clearbase.py                      | 115 ++++++++++++++
 catalyst/targets/genbase.py                        |  58 +++++++
 catalyst/targets/generic_stage_target.py           | 167 +++------------------
 catalyst/targets/snapshot_target.py                |  16 +-
 .../targets/{generic_target.py => targetbase.py}   |   6 +-
 6 files changed, 208 insertions(+), 156 deletions(-)

diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index b36eff7..f6b2163 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -1,7 +1,7 @@
 
 
 # these should never be touched
-required_build_targets = ["generic_target", "generic_stage_target"]
+required_build_targets = ["targetbase", "generic_stage_target"]
 
 # new build types should be added here
 valid_build_targets = ["stage1_target", "stage2_target", "stage3_target",

diff --git a/catalyst/targets/clearbase.py b/catalyst/targets/clearbase.py
new file mode 100644
index 0000000..8519acc
--- /dev/null
+++ b/catalyst/targets/clearbase.py
@@ -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
index 0000000..e818781
--- /dev/null
+++ b/catalyst/targets/genbase.py
@@ -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()
+

diff --git a/catalyst/targets/generic_stage_target.py 
b/catalyst/targets/generic_stage_target.py
index 0b506e2..c6b8dcc 100644
--- a/catalyst/targets/generic_stage_target.py
+++ b/catalyst/targets/generic_stage_target.py
@@ -1,17 +1,26 @@
-import os,string,imp,types,shutil
-from catalyst.support import *
-from generic_target import *
-from stat import *
-from catalyst.lock import LockDir
 
-from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS,
-       PORT_LOGDIR_CLEAN)
+import os
+import string
+import imp
+import types
+import shutil
+import sys
+from stat import ST_UID, ST_GID, ST_MODE
 
 # for convienience
 pjoin = os.path.join
 
+from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS,
+       PORT_LOGDIR_CLEAN)
+from catalyst.support import (CatalystError, msg, file_locate, normpath,
+       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.
@@ -26,7 +35,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
@@ -1616,142 +1627,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

diff --git a/catalyst/targets/snapshot_target.py 
b/catalyst/targets/snapshot_target.py
index 50133ec..3289bbd 100644
--- a/catalyst/targets/snapshot_target.py
+++ b/catalyst/targets/snapshot_target.py
@@ -3,10 +3,15 @@ Snapshot target
 """
 
 import os
-from catalyst.support import *
-from generic_stage_target import *
+import shutil
+from stat import ST_UID, ST_GID, ST_MODE
 
-class snapshot_target(generic_stage_target):
+
+from catalyst.support import normpath, cmd
+from catalyst.targets.targetbase import TargetBase
+from catalyst.targets.genbase import GenBase
+
+class snapshot_target(TargetBase, GenBase):
        """
        Builder class for snapshots.
        """
@@ -14,8 +19,9 @@ class snapshot_target(generic_stage_target):
                self.required_values=["version_stamp","target"]
                self.valid_values=["version_stamp","target"]
 
-               generic_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/"

diff --git a/catalyst/targets/generic_target.py b/catalyst/targets/targetbase.py
similarity index 64%
rename from catalyst/targets/generic_target.py
rename to catalyst/targets/targetbase.py
index 382f1c7..e0c03df 100644
--- a/catalyst/targets/generic_target.py
+++ b/catalyst/targets/targetbase.py
@@ -2,11 +2,11 @@ import os
 
 from catalyst.support import *
 
-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 = {

Reply via email to