From: Chris Lamb Date: Wed, 28 Oct 2009 10:23:10 +0000 (+0000) Subject: Clean empty directories from the pool. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03f61bb1a9d434fee6e9558ff5f7e14318eabc20;p=dak Clean empty directories from the pool. Signed-off-by: Chris Lamb --- diff --git a/dak/clean_suites.py b/dak/clean_suites.py index 24ab0d6c..d0efdcc9 100755 --- a/dak/clean_suites.py +++ b/dak/clean_suites.py @@ -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()