]> git.decadent.org.uk Git - dak.git/blobdiff - rhona
Changed accepted_autobuild to queue_build everywhere.Add a queue table.Add a "queue...
[dak.git] / rhona
diff --git a/rhona b/rhona
index e0cf0f0fa4e90ec686b77de8b760879ed1df826e..fdbcf26da1347c1d209d65cab0257611b2730142 100755 (executable)
--- a/rhona
+++ b/rhona
@@ -1,8 +1,8 @@
 #!/usr/bin/env python
 
 # rhona, cleans up unassociated binary and source packages
-# Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
-# $Id: rhona,v 1.25 2002-10-16 02:47:32 troup Exp $
+# Copyright (C) 2000, 2001, 2002, 2003  James Troup <james@nocrew.org>
+# $Id: rhona,v 1.29 2005-11-25 06:59:45 ajt Exp $
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -60,10 +60,10 @@ def check_binaries():
 
     # Get the list of binary packages not in a suite and mark them for
     # deletion.
-
     q = projectB.query("""
-SELECT b.file FROM binaries b WHERE NOT EXISTS
-        (SELECT ba.bin FROM bin_associations ba WHERE ba.bin = b.id)""");
+SELECT b.file FROM binaries b, files f
+ WHERE f.last_used IS NULL AND b.file = f.id
+   AND NOT EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)""");
     ql = q.getresult();
 
     projectB.query("BEGIN WORK");
@@ -74,30 +74,32 @@ SELECT b.file FROM binaries b WHERE NOT EXISTS
 
     # Check for any binaries which are marked for eventual deletion
     # but are now used again.
-
     q = projectB.query("""
 SELECT b.file FROM binaries b, files f
-   WHERE f.last_used IS NOT NULL AND f.id = b.file AND
-      EXISTS (SELECT suite FROM bin_associations ba WHERE ba.bin = b.id)""");
+   WHERE f.last_used IS NOT NULL AND f.id = b.file
+    AND EXISTS (SELECT 1 FROM bin_associations ba WHERE ba.bin = b.id)""");
     ql = q.getresult();
+
     projectB.query("BEGIN WORK");
     for i in ql:
         file_id = i[0];
         projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id));
     projectB.query("COMMIT WORK");
 
+########################################
+
 def check_sources():
     global delete_date, now_date;
 
     print "Checking for orphaned source packages..."
 
-    # Get the list of source packages not in a suite.
-
+    # Get the list of source packages not in a suite and not used by
+    # any binaries.
     q = projectB.query("""
-SELECT s.id, s.file FROM source s
-  WHERE NOT EXISTS
-   (SELECT sa.suite FROM src_associations sa WHERE sa.source = s.id)
-  AND NOT EXISTS (SELECT b.id FROM binaries b WHERE b.source = s.id)""");
+SELECT s.id, s.file FROM source s, files f
+  WHERE f.last_used IS NULL AND s.file = f.id
+    AND NOT EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id)
+    AND NOT EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)""");
 
     #### XXX: this should ignore cases where the files for the binary b
     ####      have been marked for deletion (so the delay between bins go
@@ -127,8 +129,8 @@ SELECT s.id, s.file FROM source s
     q = projectB.query("""
 SELECT f.id FROM source s, files f, dsc_files df
   WHERE f.last_used IS NOT NULL AND s.id = df.source AND df.file = f.id
-    AND ((EXISTS (SELECT sa.suite FROM src_associations sa WHERE sa.source = s.id))
-      OR (EXISTS (SELECT b.id FROM binaries b WHERE b.source = s.id)))""");
+    AND ((EXISTS (SELECT 1 FROM src_associations sa WHERE sa.source = s.id))
+      OR (EXISTS (SELECT 1 FROM binaries b WHERE b.source = s.id)))""");
 
     #### XXX: this should also handle deleted binaries specially (ie, not
     ####      reinstate sources because of them
@@ -142,6 +144,8 @@ SELECT f.id FROM source s, files f, dsc_files df
         projectB.query("UPDATE files SET last_used = NULL WHERE id = %s" % (file_id));
     projectB.query("COMMIT WORK");
 
+########################################
+
 def check_files():
     global delete_date, now_date;
 
@@ -151,11 +155,10 @@ def check_files():
     return;
 
     print "Checking for unused files..."
-
     q = projectB.query("""
 SELECT id FROM files f
-  WHERE NOT EXISTS (SELECT id FROM binaries b WHERE b.file = f.id)
-    AND NOT EXISTS (SELECT id FROM dsc_files df WHERE df.file = f.id)""");
+  WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.file = f.id)
+    AND NOT EXISTS (SELECT 1 FROM dsc_files df WHERE df.file = f.id)""");
 
     projectB.query("BEGIN WORK");
     for i in q.getresult():
@@ -175,9 +178,12 @@ def clean_binaries():
     if not Options["No-Action"]:
         before = time.time();
         sys.stdout.write("[Deleting from binaries table... ");
-        projectB.query("DELETE FROM binaries WHERE EXISTS (SELECT id FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')" % (delete_date));
+        sys.stderr.write("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')\n" % (delete_date));
+        projectB.query("DELETE FROM binaries WHERE EXISTS (SELECT 1 FROM files WHERE binaries.file = files.id AND files.last_used <= '%s')" % (delete_date));
         sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before)));
 
+########################################
+
 def clean():
     global delete_date, now_date;
     count = 0;
@@ -194,8 +200,8 @@ def clean():
     if not Options["No-Action"]:
         before = time.time();
         sys.stdout.write("[Deleting from source table... ");
-        projectB.query("DELETE FROM dsc_files WHERE EXISTS (SELECT df.id FROM source s, files f, dsc_files df WHERE f.last_used <= '%s' AND s.file = f.id AND s.id = df.source AND df.id = dsc_files.id)" % (delete_date));
-        projectB.query("DELETE FROM source WHERE EXISTS (SELECT id FROM files WHERE source.file = files.id AND files.last_used <= '%s')" % (delete_date));
+        projectB.query("DELETE FROM dsc_files WHERE EXISTS (SELECT 1 FROM source s, files f, dsc_files df WHERE f.last_used <= '%s' AND s.file = f.id AND s.id = df.source AND df.id = dsc_files.id)" % (delete_date));
+        projectB.query("DELETE FROM source WHERE EXISTS (SELECT 1 FROM files WHERE source.file = files.id AND files.last_used <= '%s')" % (delete_date));
         sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before)));
 
     # Delete files from the pool
@@ -244,8 +250,8 @@ def clean_maintainers():
 
     q = projectB.query("""
 SELECT m.id FROM maintainer m
-  WHERE NOT EXISTS (SELECT id FROM binaries b WHERE b.maintainer = m.id)
-    AND NOT EXISTS (SELECT id FROM source s WHERE s.maintainer = m.id)""");
+  WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.maintainer = m.id)
+    AND NOT EXISTS (SELECT 1 FROM source s WHERE s.maintainer = m.id)""");
     ql = q.getresult();
 
     count = 0;
@@ -267,8 +273,8 @@ def clean_fingerprints():
 
     q = projectB.query("""
 SELECT f.id FROM fingerprint f
-  WHERE NOT EXISTS (SELECT id FROM binaries b WHERE b.sig_fpr = f.id)
-    AND NOT EXISTS (SELECT id FROM source s WHERE s.sig_fpr = f.id)""");
+  WHERE NOT EXISTS (SELECT 1 FROM binaries b WHERE b.sig_fpr = f.id)
+    AND NOT EXISTS (SELECT 1 FROM source s WHERE s.sig_fpr = f.id)""");
     ql = q.getresult();
 
     count = 0;
@@ -285,31 +291,31 @@ SELECT f.id FROM fingerprint f
 
 ################################################################################
 
-def clean_accepted_autobuild():
+def clean_queue_build():
     global now_date;
 
-    if not Cnf.ValueList("Dinstall::AcceptedAutoBuildSuites") or Options["No-Action"]:
+    if not Cnf.ValueList("Dinstall::QueueBuildSuites") or Options["No-Action"]:
         return;
 
-    print "Cleaning out accepted autobuild symlinks..."
+    print "Cleaning out queue build symlinks..."
 
-    our_delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::AcceptedAutoBuildStayOfExecution"])));
+    our_delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::QueueBuildStayOfExecution"])));
     count = 0;
 
-    q = projectB.query("SELECT filename FROM accepted_autobuild WHERE last_used <= '%s'" % (our_delete_date));
+    q = projectB.query("SELECT filename FROM queue_build WHERE last_used <= '%s'" % (our_delete_date));
     for i in q.getresult():
         filename = i[0];
         if not os.path.exists(filename):
-            utils.warn("%s (from accepted_autobuild) doesn't exist." % (filename));
+            utils.warn("%s (from queue_build) doesn't exist." % (filename));
             continue;
-        if not Cnf.FindB("Dinstall::SecurityAcceptedAutoBuild") and not os.path.islink(filename):
-            utils.fubar("%s (from accepted_autobuild) should be a symlink but isn't." % (filename));
+        if not Cnf.FindB("Dinstall::SecurityQueueBuild") and not os.path.islink(filename):
+            utils.fubar("%s (from queue_build) should be a symlink but isn't." % (filename));
         os.unlink(filename);
         count += 1;
-    projectB.query("DELETE FROM accepted_autobuild WHERE last_used <= '%s'" % (our_delete_date));
+    projectB.query("DELETE FROM queue_build WHERE last_used <= '%s'" % (our_delete_date));
 
     if count:
-        sys.stderr.write("Cleaned %d accepted-autobuild files.\n" % (count));
+        sys.stderr.write("Cleaned %d queue_build files.\n" % (count));
 
 ################################################################################
 
@@ -321,8 +327,6 @@ def main():
        if not Cnf.has_key("Rhona::Options::%s" % (i)):
            Cnf["Rhona::Options::%s" % (i)] = "";
 
-    projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
-
     Arguments = [('h',"help","Rhona::Options::Help"),
                  ('n',"no-action","Rhona::Options::No-Action")];
 
@@ -332,6 +336,8 @@ def main():
     if Options["Help"]:
         usage();
 
+    projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
+
     now_date = time.strftime("%Y-%m-%d %H:%M");
     delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::StayOfExecution"])));
 
@@ -342,7 +348,7 @@ def main():
     clean();
     clean_maintainers();
     clean_fingerprints();
-    clean_accepted_autobuild();
+    clean_queue_build();
 
 ################################################################################