]> git.decadent.org.uk Git - dak.git/blobdiff - rhona
sync
[dak.git] / rhona
diff --git a/rhona b/rhona
index 9aa3215f5ed8a3b1a0a3f96b0c2ac636211af0a1..7033a23edacc5b44b153cdd447ead9f17e845d3c 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  James Troup <james@nocrew.org>
-# $Id: rhona,v 1.20 2002-02-12 22:14:38 troup Exp $
+# Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
+# $Id: rhona,v 1.23 2002-05-08 11:13:30 troup 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
@@ -237,6 +237,8 @@ def clean():
     if count > 0:
         sys.stderr.write("Cleaned %d files, %s.\n" % (count, utils.size_type(size)));
 
+################################################################################
+
 def clean_maintainers():
     print "Cleaning out unused Maintainer entries..."
 
@@ -260,6 +262,56 @@ SELECT m.id FROM maintainer m
 
 ################################################################################
 
+def clean_fingerprints():
+    print "Cleaning out unused fingerprint entries..."
+
+    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)""");
+    ql = q.getresult();
+
+    count = 0;
+    projectB.query("BEGIN WORK");
+    for i in ql:
+        fingerprint_id = i[0];
+        if not Options["No-Action"]:
+            projectB.query("DELETE FROM fingerprint WHERE id = %s" % (fingerprint_id));
+            count = count + 1;
+    projectB.query("COMMIT WORK");
+
+    if count > 0:
+        sys.stderr.write("Cleared out %d fingerprint entries.\n" % (count));
+
+################################################################################
+
+def clean_accepted_autobuild():
+    global now_date;
+
+    if not Cnf.FindB("Dinstall::SpecialAcceptedAutoBuild") or Options["No-Action"]:
+        return;
+
+    print "Cleaning out accepted autobuild symlinks..."
+
+    our_delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::AcceptedAutoBuildStayOfExecution"])));
+    count = 0;
+
+    q = projectB.query("SELECT filename FROM unstable_accepted WHERE last_used <= '%s'" % (our_delete_date));
+    for i in q.getresult():
+        filename = i[0];
+        if not os.path.exists(filename):
+            utils.fubar("%s (from unstable_accepted) doesn't exist." % (filename));
+        if not os.path.islink(filename):
+            utils.fubar("%s (from unstable_accepted) should be a symlink but isn't." % (filename));
+        os.unlink(filename);
+        count = count + 1;
+    projectB.query("DELETE FROM unstable_accepted WHERE last_used <= '%s'" % (our_delete_date));
+
+    if count > 0:
+        sys.stderr.write("Cleaned %d accepted-autobuild symlinks.\n" % (count));
+
+################################################################################
+
 def main():
     global Cnf, Options, projectB, delete_date, now_date;
 
@@ -288,6 +340,8 @@ def main():
     check_files();
     clean();
     clean_maintainers();
+    clean_fingerprints();
+    clean_accepted_autobuild();
 
 ################################################################################