From 83563889f7b658d2e5609c82820d951b7cba511d Mon Sep 17 00:00:00 2001 From: Ansgar Burchardt Date: Sat, 19 Dec 2015 13:09:58 +0100 Subject: [PATCH] Add program to remove old packages from debug suites We don't want to have to remove packages from *-debug by hand after we removed them from the main archive. --- dak/dak.py | 2 + dak/manage_debug_suites.py | 133 +++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 dak/manage_debug_suites.py diff --git a/dak/dak.py b/dak/dak.py index 32ddd62f..c3c7f0de 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -98,6 +98,8 @@ def init(): "Clean unused/superseded packages from the archive"), ("manage-build-queues", "Clean and update metadata for build queues"), + ("manage-debug-suites", + "Clean obsolete packages from debug suites"), ("clean-queues", "Clean cruft from incoming"), diff --git a/dak/manage_debug_suites.py b/dak/manage_debug_suites.py new file mode 100644 index 00000000..c8a95a68 --- /dev/null +++ b/dak/manage_debug_suites.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python + +""" Manage debug suites + +@contact: Debian FTP Master +@copyright: 2015, Ansgar Burchardt + +""" + +# 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 +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +import apt_pkg +import sys + +from daklib import daklog +from daklib.archive import ArchiveTransaction +from daklib.dbconn import * +from daklib.config import Config + +################################################################################ + +Options = None +Logger = None + +################################################################################ + +def usage (exit_code=0): + print """Usage: dak manage-debug-suites [-a|--all|...] +Manage the contents of one or more debug suites + + -a, --all run on all known debug suites + -n, --no-action don't do anything + -h, --help show this help and exit""" + + sys.exit(exit_code) + +################################################################################ + +def clean(debug_suite, transaction): + session = transaction.session + + # Sanity check: make sure this is a debug suite or we would remove everything + any_suite = session.query(Suite).filter_by(debug_suite=debug_suite).first() + if any_suite is None: + raise Exception("Suite '{0}' is not a debug suite".format(debug_suite.suite_name)) + + # Only keep source packages that are still a base suite. + # All other sources and their binary packages can go. + query = """ + WITH + sources_to_keep AS + (SELECT DISTINCT sa.source + FROM src_associations sa + JOIN suite ON sa.suite = suite.id + WHERE suite.debugsuite_id = :debugsuite_id), + sources_removed AS + (DELETE FROM src_associations sa + WHERE sa.suite = :debugsuite_id + AND sa.source NOT IN (SELECT source FROM sources_to_keep) + RETURNING sa.source) + DELETE FROM bin_associations ba + USING binaries b + WHERE ba.suite = :debugsuite_id + AND ba.bin = b.id + AND b.source IN (SELECT source FROM sources_removed) + RETURNING + b.package, + b.version, + (SELECT arch_string FROM architecture WHERE id=b.architecture) AS architecture + """ + result = session.execute(query, {"debugsuite_id": debug_suite.suite_id}) + for row in result: + Logger.log(["remove", debug_suite.suite_name, row[0], row[1], row[2]]) + +def main (): + global Options, Logger + + cnf = Config() + + for i in ["Help", "No-Action", "All"]: + if not cnf.has_key("Manage-Debug-Suites::Options::%s" % (i)): + cnf["Manage-Debug-Suites::Options::%s" % (i)] = "" + + Arguments = [('h',"help","Manage-Debug-Suites::Options::Help"), + ('n',"no-action","Manage-Debug-Suites::Options::No-Action"), + ('a',"all","Manage-Debug-Suites::Options::All")] + + debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) + Options = cnf.subtree("Manage-Debug-Suites::Options") + + if Options["Help"]: + usage() + + Logger = daklog.Logger('manage-debug-suites', Options['No-Action']) + + with ArchiveTransaction() as transaction: + session = transaction.session + if Options['All']: + if len(debug_suite_names) != 0: + print "E: Cannot use both -a and a queue name" + sys.exit(1) + raise Exception("Not yet implemented.") + else: + debug_suites = session.query(Suite).filter(Suite.suite_name.in_(debug_suite_names)) + + for debug_suite in debug_suites: + Logger.log(['cleaning debug suite {0}'.format(debug_suite.suite_name)]) + clean(debug_suite, transaction) + if not Options['No-Action']: + transaction.commit() + else: + transaction.rollback() + + Logger.close() + +####################################################################################### + +if __name__ == '__main__': + main() -- 2.39.5