target improvements, beginning of exception code
authorDaniel Robbins <drobbins@gentoo.org>
Tue, 28 Oct 2003 04:11:42 +0000 (04:11 +0000)
committerDaniel Robbins <drobbins@gentoo.org>
Tue, 28 Oct 2003 04:11:42 +0000 (04:11 +0000)
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@28 d1e1f19c-881f-0410-ab34-b69fee027534

ChangeLog
catalyst
modules/catalyst_support.py [new file with mode: 0644]
modules/targets.py

index e0295695ff8b475198ada0d797f2f2424c9df808..8f9dbeb88859f3fdcbeac5bea1b65ab6c649f84d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
 # ChangeLog for gentoo/src/catalyst 
 # Copyright 2002-2003 Gentoo Technologies, Inc.; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.5 2003/10/27 04:08:31 drobbins Exp $
+# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.6 2003/10/28 04:11:42 drobbins Exp $
 
+  27 Oct 2003; Daniel Robbins <drobbins@gentoo.org>: beginning of exception
+  handling integration, got some of the target code nicely fleshed out.
+  
   24 Oct 2003; Daniel Robbins <drobbins@gentoo.org>: major code rework in 
   progress on the python parts.
   
index 7fd83bf3ca4ee538b3dd84f8130bdfd564def837..698d3cb06d604bc6a02884bb771923de4adcd99b 100755 (executable)
--- a/catalyst
+++ b/catalyst
@@ -2,13 +2,10 @@
 
 import os,sys,imp,string
 
-def die(msg=None):
-       if msg:
-               print "catalyst: "+msg
-       sys.exit(1)
+#This allows plugins (and this code) to import modules in the /modules dir
+sys.path.append(os.getcwd()+"/modules")
 
-def warn(msg):
-       print "catalyst: "+msg
+from catalyst_support import *
 
 def usage():
        print "usage: meep!"
@@ -78,9 +75,6 @@ Overview of catalyst operation
 * The catalyst process is now complete :)
 """
 
-#This allows plugins to import modules in the /modules dir
-sys.path.append(os.getcwd()+"/modules")
-
 #map current machine information from uname() to the mainarch we are running
 #under
 
@@ -168,6 +162,11 @@ mytarget=targetmap[myspec["target"]](myspec)
 print
 spec_dump(myspec)
 
+#set up build directories, etc.
+retval=mytarget.run()
+if not retval:
+       die("Target failed.")
+
 #to test this program, type:
 
 # ./catalyst subarch=pentium4 version_stamp=20031016 target=stage3 rel_type=default rel_version=1.4 snapshot=20031016 source_subpath=default-x86-1.4/stage2-pentium4-20031016
diff --git a/modules/catalyst_support.py b/modules/catalyst_support.py
new file mode 100644 (file)
index 0000000..1ff8aa8
--- /dev/null
@@ -0,0 +1,15 @@
+import sys
+
+class CatalystError(Exception):
+       def __init__(self, message):
+               if message:
+                       print "catalyst: "+message
+               sys.exit(1)
+
+def die(msg=None):
+       raise CatalystError, msg
+
+def warn(msg):
+       print "catalyst: "+msg
+
+
index 749b1f018164e02f040902175290bf55a9d62a85..300dce4318a38f8b992f6a1d3ec9cf9cfd87a0f1 100644 (file)
@@ -1,31 +1,14 @@
-
-"""
-local variables from spec:
-
-version_stamp                  20031016                                        user (from spec)
-target                         stage3                                          user (from spec)
-subarch                                pentium4                                        user (from spec)
-rel_type                       default                                         user (from spec) (was BUILDTYPE)
-rel_version                    1.4                                             user (from spec) (was MAINVERSION)
-snapshot                       20031016                                        user (from spec)
-source_subpath                 default-x86-1.4/stage2-pentium4-20031016        user (from spec)
-"""
+import os,stat
+from catalyst_support import *
 
 class generic_target:
+
        def __init__(self,myspec):
                self.settings=myspec
                pass
-       def run_prep(self):
-               """copy scripts into location, generate files containing build
-               commands (for GRP), etc."""
-       def list_mounts(self):
-               """specify needed mounts and their locations."""
-       def run_script(self):
-               """specify script to run."""
-       def spec_require(self):
-               """return list of definitions required from spec"""
 
 class generic_stage_target(generic_target):
+
        def __init__(self,myspec):
                generic_target.__init__(self,myspec)
                #we'd want to make sure we have all the settings we need here
@@ -38,11 +21,84 @@ class generic_stage_target(generic_target):
                self.settings["chroot_path"]=st+"/tmp/"+self.settings["target_subpath"]
                self.settings["pkgcache_path"]=st+"/packages/"+self.settings["target_subpath"]
 
+       def mount_safety_check(self,mypath):
+               #check and verify that none of our paths in mypath are mounted. We don't want to clean up with things still
+               #mounted, and this allows us to check. returns 1 on ok, 0 on "something is still mounted" case.
+               paths=["/usr/portage/packages","/usr/portage/distfiles", "/var/tmp/distfiles", "/proc", "/root/.ccache", "/dev"]
+               if not os.path.exists(mypath):
+                       return 1 
+               mypstat=os.stat(mypath)[stat.ST_DEV]
+               for x in paths:
+                       if not os.path.exists(mypath+x):
+                               continue
+                       teststat=os.stat(mypath+x)[stat.ST_DEV]
+                       if teststat!=mypstat:
+                               #something is still mounted
+                               return 0
+               return 1
+               
+       def dir_setup(self):
+               if not self.mount_safety_check(self.settings["chroot_path"]):
+                       print "Error: bind mounts still mounted in "+self.settings["chroot_path"]+"."
+                       print "Will not clean up directory until this is fixed."
+                       return 0
+               retval=os.system("rm -rf "+self.settings["chroot_path"])
+               if retval != 0:
+                       print "Could not remove existing directory: "+self.settings["chroot_path"]
+                       return 0
+               os.makedirs(self.settings["chroot_path"])
+               if not os.path.exists(self.settings["pkgcache_path"]):
+                       os.makedirs(self.settings["pkgcache_path"])
+               return 1
+               
+       def unpack_and_bind(self):
+               retval=os.system("tar xjpf "+self.settings["source_path"]+" -C "+self.settings["chroot_path"])
+               if retval!=0:
+                       die("Unpack error")
+               for x in [[self.settings["portdir"],"/usr/portage"],[self.settings["distdir"],"/usr/portage/distfiles"],
+                               ["/proc","/proc"],["/dev","/dev"]]:
+                       retval=os.system("mount --bind "+x[0]+" "+x[1])
+                       if not retval:
+                               die("Bind mount error")
+       
+       def run(self):
+               print "I'm running!"
+               retval=self.dir_setup()
+               if not retval:
+                       return 0
+               retval=self.unpack_and_bind()
+               if not retval:
+                       return 0
+
 class snapshot_target(generic_target):
        def __init__(self):
-               pass
-       def spec_require(self):
-               return ["snapshot"]
+               self.settings["target_subpath"]="portage-"+self.settings["version_stamp"]
+               st=self.settings["storedir"]
+               self.settings["snapshot_path"]=st+"/snapshots/"+self.settings["target_subpath"]+".tar.bz2"
+               self.settings["tmp_path"]=st+"/tmp/"+self.settings["target_subpath"]
+
+       def do_snapshot(portdir,snap_temp_dir,snapdir,snapversion):
+               print "Creating Portage tree snapshot "+snapversion+" from "+portdir+"..."
+               mytmp=snap_temp_dir+"/snap-"+snapversion
+               if os.path.exists(mytmp):
+                       retval=os.system("rm -rf "+mytmp)
+                       if retval != 0:
+                               die("Could not remove existing directory: "+mytmp)
+               os.makedirs(mytmp)
+               retval=os.system("rsync -a --exclude /packages/ --exclude /distfiles/ --exclude CVS/ "+portdir+"/ "+mytmp+"/portage/")
+               if retval != 0:
+                       die("snapshot failure.")
+               print "Compressing Portage snapshot tarball..."
+               retval=os.system("( cd "+mytmp+"; tar cjf "+snapdir+"/portage-"+snapversion+".tar.bz2 portage )")
+               if retval != 0:
+                       die("snapshot tarball creation failure.")
+               print "Cleaning up temporary snapshot directory..."
+               #Be a good citizen and clean up after ourselves
+               retval=os.system("rm -rf "+mytmp)
+               if retval != 0:
+                       die("Unable to clean up directory: "+mytmp)
+       def run(self):
+               self.do_snapshot(self.settings["portdir"],self.settings["tmp_path"],self.settings["snapshot_path"],self.settings["snapversion"])
 
 class stage1_target(generic_stage_target):
        def __init__(self,spec):