Add support for purging to snapshot target
authorAndrew Gaffney <agaffney@gentoo.org>
Mon, 22 Dec 2008 04:47:50 +0000 (22:47 -0600)
committerAndrew Gaffney <agaffney@gentoo.org>
Mon, 22 Dec 2008 04:47:50 +0000 (22:47 -0600)
ChangeLog
modules/snapshot_target.py

index be7dd1b10ac5917738d0b1290e67907022979e7c..54797d9f62d8c828810d3027debdf29f65f5a774 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,10 @@
 # Copyright 2002-2008 Gentoo Foundation; 2008 Chris Gianelloni, Andrew Gaffney
 # Distributed under the GPL v2
 
+  22 Dec 2008; Andrew Gaffney <agaffney@gentoo.org>
+  modules/snapshot_target.py:
+  Add support for purging to snapshot target
+
   21 Dec 2008; Andrew Gaffney <agaffney@gentoo.org> TODO:
   Add mix-in cdtar idea to TODO
 
index 1957e56a46a2522f159cc876e06942b3f59e3151..0609377b8c1e9a9b5e562ccd8cc2110de1247a71 100644 (file)
@@ -29,6 +29,13 @@ class snapshot_target(generic_stage_target):
                pass
                
        def run(self):
+               if self.settings.has_key("PURGEONLY"):
+                       self.purge()
+                       return
+
+               if self.settings.has_key("PURGE"):
+                       self.purge()
+
                self.setup()
                print "Creating Portage tree snapshot "+self.settings["version_stamp"]+\
                        " from "+self.settings["portdir"]+"..."
@@ -55,6 +62,23 @@ class snapshot_target(generic_stage_target):
 
        def cleanup(self):
                print "Cleaning up..."
+
+       def purge(self):
+               myemp=self.settings["tmp_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)
+                       """ 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 register(foo):
        foo.update({"snapshot":snapshot_target})