]> git.decadent.org.uk Git - dak.git/commitdiff
dak/clean_suites.py: allow limiting file removal to specific archives
authorAnsgar Burchardt <ansgar@debian.org>
Sun, 12 Aug 2012 06:45:30 +0000 (08:45 +0200)
committerAnsgar Burchardt <ansgar@debian.org>
Sun, 12 Aug 2012 07:30:39 +0000 (09:30 +0200)
This allows us to remove all obsolete files from the NEW queue even when
the maximum number of removals would be reached normally.

dak/clean_suites.py

index caa69709b2561333c1e95d61878d8fc29cf297c0..e9360012550da7fd686a5d1db17951eda60d0873 100755 (executable)
@@ -222,7 +222,7 @@ def clean_binaries(now_date, session):
 
 ########################################
 
-def clean(now_date, max_delete, session):
+def clean(now_date, archives, max_delete, session):
     cnf = Config()
 
     count = 0
@@ -280,6 +280,10 @@ def clean(now_date, max_delete, session):
         old_files = old_files.limit(max_delete)
         print "Limiting removals to %d" % max_delete
 
+    if archives is not None:
+        archive_ids = [ a.archive_id for a in archives ]
+        old_files = old_files.filter(ArchiveFile.archive_id.in_(archive_ids))
+
     for af in old_files:
         filename = af.path
         if not os.path.exists(filename):
@@ -445,6 +449,7 @@ def main():
             cnf["Clean-Suites::Options::%s" % (i)] = ""
 
     Arguments = [('h',"help","Clean-Suites::Options::Help"),
+                 ('a','archive','Clean-Suites::Options::Archive','HasArg'),
                  ('n',"no-action","Clean-Suites::Options::No-Action"),
                  ('m',"maximum","Clean-Suites::Options::Maximum", "HasArg")]
 
@@ -469,6 +474,13 @@ def main():
 
     session = DBConn().session()
 
+    archives = None
+    if 'Archive' in Options:
+        archive_names = Options['Archive'].split(',')
+        archives = session.query(Archive).filter(Archive.archive_name.in_(archive_names)).all()
+        if len(archives) == 0:
+            utils.fubar('Unknown archive.')
+
     now_date = datetime.now()
 
     set_archive_delete_dates(now_date, session)
@@ -477,7 +489,7 @@ def main():
     clean_binaries(now_date, session)
     check_sources(now_date, session)
     check_files(now_date, session)
-    clean(now_date, max_delete, session)
+    clean(now_date, archives, max_delete, session)
     clean_maintainers(now_date, session)
     clean_fingerprints(now_date, session)
     clean_empty_directories(session)