]> err.no Git - dak/commitdiff
Clean empty directories from the pool.
authorChris Lamb <lamby@debian.org>
Wed, 28 Oct 2009 10:23:10 +0000 (10:23 +0000)
committerChris Lamb <lamby@debian.org>
Wed, 28 Oct 2009 10:23:10 +0000 (10:23 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
dak/clean_suites.py

index 24ab0d6c5b60263da3dfb95a2fd2ac07d6d4281c..d0efdcc9d5f9d09df9da2cf9f6cffaa5c43ff3b1 100755 (executable)
@@ -359,6 +359,33 @@ def clean_queue_build(now_date, delete_date, max_delete, session):
 
 ################################################################################
 
+def clean_empty_directories(session):
+    """
+    Removes empty directories from pool directories.
+    """
+
+    count = 0
+
+    cursor = session.execute(
+        "SELECT DISTINCT(path) FROM location WHERE type = :type",
+        {'type': 'pool'},
+    )
+    bases = [x[0] for x in cursor.fetchall()]
+
+    for base in bases:
+        for dirpath, dirnames, filenames in os.walk(base, topdown=False):
+            if not filenames and not dirnames:
+                if not Options["No-Action"]:
+                    os.removedirs(os.path.join(base, dirpath))
+                count += 1
+
+    if count:
+        Logger.log(["total", count])
+        print "Cleaned %d empty directories from %d location(s)" % \
+            (count, len(bases))
+
+################################################################################
+
 def main():
     global Options, Logger
 
@@ -404,6 +431,7 @@ def main():
     clean_maintainers(now_date, delete_date, max_delete, session)
     clean_fingerprints(now_date, delete_date, max_delete, session)
     clean_queue_build(now_date, delete_date, max_delete, session)
+    clean_empty_directories(session)
 
     Logger.close()