X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=rhona;h=e0cf0f0fa4e90ec686b77de8b760879ed1df826e;hb=fa7b68ee3d2c9d467669021fd62e09a407e1244a;hp=f371a0a61ccc81a7044fc87bf4e8ab65a65b6c64;hpb=2f5e692bfbbb6f8146f50d944f7fcc169a95a0a3;p=dak.git diff --git a/rhona b/rhona index f371a0a6..e0cf0f0f 100755 --- 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 -# $Id: rhona,v 1.18 2001-11-18 19:57:58 rmurray Exp $ +# Copyright (C) 2000, 2001, 2002 James Troup +# $Id: rhona,v 1.25 2002-10-16 02:47:32 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 @@ -29,7 +29,7 @@ ################################################################################ -import os, pg, stat, string, sys, time +import os, pg, stat, sys, time import apt_pkg import utils @@ -185,7 +185,7 @@ def clean(): print "Cleaning out packages..." - date = time.strftime("%Y-%m-%d", time.localtime(time.time())); + date = time.strftime("%Y-%m-%d"); dest = Cnf["Dir::Morgue"] + '/' + Cnf["Rhona::MorgueSubDir"] + '/' + date; if not os.path.exists(dest): os.mkdir(dest); @@ -207,14 +207,14 @@ def clean(): continue; if os.path.isfile(filename): if os.path.islink(filename): - count = count + 1; + count += 1; if Options["No-Action"]: print "Removing symlink %s..." % (filename); else: os.unlink(filename); else: - size = size + os.stat(filename)[stat.ST_SIZE]; - count = count + 1; + size += os.stat(filename)[stat.ST_SIZE]; + count += 1; dest_filename = dest + '/' + os.path.basename(filename); # If the destination file exists; try to find another filename to use @@ -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..." @@ -252,7 +254,7 @@ SELECT m.id FROM maintainer m maintainer_id = i[0]; if not Options["No-Action"]: projectB.query("DELETE FROM maintainer WHERE id = %s" % (maintainer_id)); - count = count + 1; + count += 1; projectB.query("COMMIT WORK"); if count > 0: @@ -260,10 +262,64 @@ 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 += 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.ValueList("Dinstall::AcceptedAutoBuildSuites") 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 accepted_autobuild 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)); + 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)); + os.unlink(filename); + count += 1; + projectB.query("DELETE FROM accepted_autobuild WHERE last_used <= '%s'" % (our_delete_date)); + + if count: + sys.stderr.write("Cleaned %d accepted-autobuild files.\n" % (count)); + +################################################################################ + def main(): global Cnf, Options, projectB, delete_date, now_date; Cnf = utils.get_conf() + for i in ["Help", "No-Action" ]: + 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"])); @@ -276,7 +332,7 @@ def main(): if Options["Help"]: usage(); - now_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time())); + 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"]))); check_binaries(); @@ -285,6 +341,8 @@ def main(): check_files(); clean(); clean_maintainers(); + clean_fingerprints(); + clean_accepted_autobuild(); ################################################################################