Author: wade
Date: 2006-11-07 20:14:58 -0500 (Tue, 07 Nov 2006)
New Revision: 67506

Modified:
   trunk/release/monobuild/clean-builds.py
Log:
clean-builds.py:
-finish some options that will allow build info to be saved while
 deleting the source files and builds (which don't take up much space 
comparitively)



Modified: trunk/release/monobuild/clean-builds.py
===================================================================
--- trunk/release/monobuild/clean-builds.py     2006-11-08 01:02:15 UTC (rev 
67505)
+++ trunk/release/monobuild/clean-builds.py     2006-11-08 01:14:58 UTC (rev 
67506)
@@ -6,10 +6,13 @@
 # remove_builds removes the links in the files dir, as well as the actual rpm 
or zip files
 # remove_tarball_logs removes the links in the logs dir, as well as the actual 
mktarball log file
 
+# TODO: what about sources that were never built?
+
 import sys
 import os
 import shutil
 import getopt
+import re 
 
 import pdb
 
@@ -23,24 +26,61 @@
        sys.exit(1)
 
 
+# TODO: This in forming invalid paths...  try this to see:
+# ./clean-builds.py --remove_builds HEAD 1000
 def handle_link_files(path):
        full_path = config.build_info_dir + os.sep + path
        if os.path.exists(path):
                for f in os.listdir(full_path):
                        if os.path.islink(full_path + os.sep + f):
                                link_target = 
os.readlink(os.path.join(full_path, f) )
-                               link_targets.append(os.path.join(path, f, 
link_target))
+                               link_target = os.path.join(path, link_target)
 
+                               # Only add this to the link if it exists
+                               if os.path.exists(link_target):
+                                       link_targets.append(link_target)
+                               else:
+                                       print "link_target doesn't exist: " + 
link_target
+
                                # Also remove the symlink
                                links.append(os.path.join(path, f))
 
+def get_size_of_files(files):
+       sum = 0
+       for f in files:
+               if os.path.isdir(f):
+                       new_files = []
+                       for f2 in os.listdir(f):
+                               new_files.append(f + os.sep + f2)
+                       sum += get_size_of_files(new_files)
+               else:
+                       sum += os.path.getsize(f)
+       return sum
+
+
+
 def cleanup(files, type):
+       # TODO: see how much space these files take up
+       if type != 'link':
+               size = get_size_of_files(files)
+               print "Total size for %s: %d (MB)" % (type, size / 1024 / 1024)
+               space_summary.append("Total size for %s: %d (MB)" % (type, size 
/ 1024 / 1024))
        for f in files:
-               if os.path.exists(f):
+               # os.path.exists doesn't check existance of the link, but the 
target
+               if os.path.islink(f):
                        print "Removing (%s) " % type + f,
                        if execute:
                                print "for real..."
-                               shutil.rmtree(f)
+                               os.unlink(f)
+               elif os.path.exists(f):
+                       print "Removing (%s) " % type + f,
+                       if execute:
+                               print "for real..."
+                               # rmtree dies if removing a link pointing to an 
invalid file, or if it's a file
+                               if os.path.isdir(f):
+                                       shutil.rmtree(f)
+                               else:
+                                       os.unlink(f)
                        else:
                                print
 
@@ -83,9 +123,13 @@
 
 
 # Gather all the files
+space_summary = []
 dirs = []
 links = []
 link_targets = []
+
+os.chdir(config.build_info_dir)
+
 for distro in os.listdir(config.build_info_dir + os.sep + HEAD_or_RELEASE):
        for component in os.listdir(config.build_info_dir + os.sep + 
HEAD_or_RELEASE + os.sep + distro):
                # Get the last 'num_builds' number of elements from the list
@@ -98,7 +142,6 @@
                                my_path = os.path.join(HEAD_or_RELEASE, distro, 
component, j)
                                if remove_build_info:
                                        
dirs.append(os.path.join(HEAD_or_RELEASE, distro, component, j))
-                                       # TODO: remove from 
[snapshot][zip_]packages as well ... ?  will have to follow the symlink
                                        if remove_tarball_logs:
                                                handle_link_files(my_path + 
os.sep + 'logs')
                                if remove_builds:
@@ -106,10 +149,12 @@
                                                        
 
 # Start removing files
-os.chdir(config.build_info_dir)
-
 cleanup(link_targets, "link_target")
 cleanup(dirs, "dir")
 cleanup(links, "link")
 
+# The space summary isn't accurate and will always over estimate
+#  Just gives an idea of about how much space to recover
+#  (the same sources are listed as taking up space for each platform)
+print "\n".join(space_summary)
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to