--- /dev/null
+# Distributed under the GNU General Public License version 2
+# Copyright 2003-2004 Gentoo Technologies, Inc.
+# $Header: /var/cvsroot/gentoo/src/catalyst/modules/snapshot_target.py,v 1.1 2004/05/17 01:56:19 zhen Exp $
+
+"""
+Builder class for snapshots.
+"""
+
+import os,string,imp,types,shutil
+from catalyst_support import *
+from generic_stage_target import *
+from stat import *
+
+class snapshot_target(generic_target):
+ def __init__(self,myspec,addlargs):
+ self.required_values=["version_stamp","target"]
+ self.valid_values=["version_stamp","target"]
+ generic_target.__init__(self,myspec,addlargs)
+ self.settings=myspec
+ 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 setup(self):
+ x=self.settings["storedir"]+"/snapshots"
+ if not os.path.exists(x):
+ os.makedirs(x)
+
+ def run(self):
+ self.setup()
+ print "Creating Portage tree snapshot "+self.settings["version_stamp"]+" from "+self.settings["portdir"]+"..."
+ mytmp=self.settings["tmp_path"]
+ if os.path.exists(mytmp):
+ cmd("rm -rf "+mytmp,"Could not remove existing directory: "+mytmp)
+ os.makedirs(mytmp)
+ cmd("rsync -a --exclude /packages/ --exclude /distfiles/ --exclude CVS/ "+self.settings["portdir"]+"/ "+mytmp+"/portage/","Snapshot failure")
+ print "Compressing Portage snapshot tarball..."
+ cmd("tar cjf "+self.settings["snapshot_path"]+" -C "+mytmp+" portage","Snapshot creation failure")
+ self.cleanup()
+
+ def cleanup(self):
+ print "Cleaning up temporary snapshot directory..."
+ #Be a good citizen and clean up after ourselves
+ cmd("rm -rf "+self.settings["tmp_path"],"Snapshot cleanup failure")
+
+def register(foo):
+ foo.update({"snapshot":snapshot_target})
+ return foo
+