From 0e065ded4af23d7467d458fbffa889f7253f8158 Mon Sep 17 00:00:00 2001 From: James Troup Date: Thu, 15 Mar 2001 00:35:12 +0000 Subject: [PATCH] more rewrites. --- rhona | 60 ++++++++++++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/rhona b/rhona index 8a9be01f..5673e0aa 100755 --- a/rhona +++ b/rhona @@ -2,7 +2,7 @@ # rhona, cleans up unassociated binary and source packages # Copyright (C) 2000, 2001 James Troup -# $Id: rhona,v 1.9 2001-03-14 20:31:56 troup Exp $ +# $Id: rhona,v 1.10 2001-03-15 00:35:12 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 @@ -145,24 +145,15 @@ def check_files(): print "Checking for unused files..." - # Check for files not references in either binaries or dsc_files - used = {}; - q = projectB.query("SELECT file FROM binaries"); - for i in q.getresult(): - used[i[0]] = ""; - q = projectB.query("SELECT file FROM dsc_files"); - for i in q.getresult(): - used[i[0]] = ""; - - all = {}; - q = projectB.query("SELECT f.id, l.path, f.filename FROM files f, location l WHERE f.location = l.id;"); - for i in q.getresult(): - all[i[0]] = i[1] + i[2]; + 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)"""); projectB.query("BEGIN WORK"); - for id in all.keys(): - if not used.has_key(id): - projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s" % (delete_date, id)); + for i in q.getresult(): + file_id = i[0]; + projectB.query("UPDATE files SET last_used = '%s' WHERE id = %s" % (delete_date, file_id)); projectB.query("COMMIT WORK"); def clean_binaries(): @@ -176,7 +167,7 @@ def clean_binaries(): 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.stdout.write("done. (%d)]\n" % (int(time.time()-before))); + sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); def clean(): global delete_date; @@ -196,7 +187,7 @@ def clean(): 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)); - sys.stdout.write("done. (%d)]\n" % (int(time.time()-before))); + sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); # Delete files from the pool q = projectB.query("SELECT l.path, f.filename FROM location l, files f WHERE f.last_used <= '%s' AND l.id = f.location" % (delete_date)); @@ -227,32 +218,25 @@ def clean(): before = time.time(); sys.stdout.write("[Deleting from files table... "); projectB.query("DELETE FROM files WHERE last_used <= '%s'" % (delete_date)); - sys.stdout.write("done. (%d)]\n" % (int(time.time()-before))); + sys.stdout.write("done. (%d seconds)]\n" % (int(time.time()-before))); 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..." - used = {}; - q = projectB.query("SELECT maintainer FROM binaries WHERE maintainer IS NOT NULL"); - for i in q.getresult(): - used[i[0]] = ""; - q = projectB.query("SELECT maintainer FROM source WHERE maintainer IS NOT NULL"); - for i in q.getresult(): - used[i[0]] = ""; - - all = {}; - q = projectB.query("SELECT id, name FROM maintainer"); - for i in q.getresult(): - all[i[0]] = i[1]; + 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)"""); + ql = q.getresult(); count = 0; projectB.query("BEGIN WORK"); - for id in all.keys(): - if not used.has_key(id): - if not Cnf["Rhona::Options::No-Action"]: - projectB.query("DELETE FROM maintainer WHERE id = %s" % (id)); + for i in ql: + maintainer_id = i[0]; + if not Cnf["Rhona::Options::No-Action"]: + projectB.query("DELETE FROM maintainer WHERE id = %s" % (maintainer_id)); count = count + 1; projectB.query("COMMIT WORK"); @@ -289,11 +273,11 @@ def main(): sys.stderr.write("W: Could not find source-only override file '%s'.\n" % (override_filename)); delete_date = time.strftime("%Y-%m-%d %H:%M", time.localtime(time.time()-int(Cnf["Rhona::StayOfExecution"]))); - + check_binaries(); clean_binaries(); check_sources(); - #check_files(); + check_files(); clean(); clean_maintainers(); -- 2.39.5