From: Niels Thykier Date: Sat, 6 Jun 2015 09:41:35 +0000 (+0200) Subject: Add dak auto-decruft command based on cruft-report X-Git-Url: https://git.decadent.org.uk/gitweb/?p=dak.git;a=commitdiff_plain;h=49699d61d065deb2f4918deb44d37504be38cb2f Add dak auto-decruft command based on cruft-report The new auto-decruft command automatically removes: * sourceless binaries * NBS When the removals can be done without breaking any reverse dependencies. Signed-off-by: Niels Thykier --- diff --git a/dak/auto_decruft.py b/dak/auto_decruft.py new file mode 100644 index 00000000..0f807147 --- /dev/null +++ b/dak/auto_decruft.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python + +""" +Check for obsolete binary packages + +@contact: Debian FTP Master +@copyright: 2000-2006 James Troup +@copyright: 2009 Torsten Werner +@copyright: 2015 Niels Thykier +@license: GNU General Public License version 2 or later +""" + +# 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 + +################################################################################ + +# | priviledged positions? What privilege? The honour of working harder +# | than most people for absolutely no recognition? +# +# Manoj Srivastava in <87lln8aqfm.fsf@glaurung.internal.golden-gryphon.com> + +################################################################################ + +import sys +import apt_pkg + +from daklib.config import Config +from daklib.dbconn import * +from daklib import utils +from daklib.cruft import * +from daklib.rm import remove + +################################################################################ + +def usage(exit_code=0): + print """Usage: dak cruft-report +Check for obsolete or duplicated packages. + + -h, --help show this help and exit. + -n, --dry-run don't do anything, just show what would have been done + -s, --suite=SUITE check suite SUITE.""" + sys.exit(exit_code) + +################################################################################ + +def remove_sourceless_cruft(suite_name, suite_id, session, dryrun): + """Remove binaries without a source + + @type suite_name: string + @param suite_name: The name of the suite to remove from + + @type suite_id: int + @param suite_id: The id of the suite donated by suite_name + + @type session: SQLA Session + @param session: The database session in use + + @type dryrun: bool + @param dryrun: If True, just to print the actions rather than actually doing them + """"" + global Options + rows = query_without_source(suite_id, session) + arch_all_id = get_architecture('all', session=session) + + + message = '[auto-cruft] no longer built from source and no reverse dependencies' + for row in rows: + package = row[0] + if utils.check_reverse_depends([package], suite_name, [], session, True): + continue + + if dryrun: + # Embed the -R just in case someone wants to run it manually later + print 'Would do: dak rm -m "%s" -s %s -a all -p -R -b %s' % \ + (message, suite_name, package) + else: + q = session.execute(""" + SELECT b.package, b.version, a.arch_string, b.id + FROM binaries b + JOIN bin_associations ba ON b.id = ba.bin + JOIN architecture a ON b.architecture = a.id + JOIN suite su ON ba.suite = su.id + WHERE a.id = :arch_all_id AND b.package = :package AND su.id = :suite_id + """, {arch_all_id: arch_all_id, package: package, suite_id: suite_id}) + remove(session, message, [suite_name], list(q), partial=True, whoami="DAK's auto-decrufter") + + +def removeNBS(suite_name, suite_id, session, dryrun): + """Remove binaries no longer built + + @type suite_name: string + @param suite_name: The name of the suite to remove from + + @type suite_id: int + @param suite_id: The id of the suite donated by suite_name + + @type session: SQLA Session + @param session: The database session in use + + @type dryrun: bool + @param dryrun: If True, just to print the actions rather than actually doing them + """"" + global Options + rows = queryNBS(suite_id, session) + arch2ids = {} + for row in rows: + (pkg_list, arch_list, source, _) = row + if utils.check_reverse_depends(pkg_list, suite_name, arch_list, session, True): + continue + arch_string = ','.join(arch_list) + message = '[auto-cruft] NBS (no longer built by %s and had no reverse dependencies)' % source + + if dryrun: + # Embed the -R just in case someone wants to run it manually later + pkg_string = ' '.join(pkg_list) + print 'Would do: dak rm -m "%s" -s %s -a %s -p -R -b %s' % \ + (message, suite_name, arch_string, pkg_string) + else: + for architecture in arch_list: + if architecture in arch2ids: + arch2ids[architecture] = utils.get_architecture(architecture, session=session) + arch_ids = ", ".join(arch2ids[architecture] for architecture in arch_list) + pkg_db_set = ", ".join('"%s"' % package for package in pkg_list) + # TODO: Fix this properly to remove the remaining non-bind arguments + q = session.execute(""" + SELECT b.package, b.version, a.arch_string, b.id + FROM binaries b + JOIN bin_associations ba ON b.id = ba.bin + JOIN architecture a ON b.architecture = a.id + JOIN suite su ON ba.suite = su.id + WHERE a.id IN (%s) AND b.package IN (%s) AND su.id = :suite_id + """ % (arch_ids, pkg_db_set), { suite_id: suite_id}) + remove(session, message, [suite_name], list(q), partial=True, whoami="DAK's auto-decrufter") + +################################################################################ + +def main (): + global Options + cnf = Config() + + Arguments = [('h',"help","Auto-Decruft::Options::Help"), + ('n',"dry-run","Auto-Decruft::Options::Dry-Run"), + ('s',"suite","Auto-Decruft::Options::Suite","HasArg")] + for i in ["help", "Dry-Run"]: + if not cnf.has_key("Auto-Decruft::Options::%s" % (i)): + cnf["Auto-Decruft::Options::%s" % (i)] = "" + + cnf["Auto-Decruft::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable") + + apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) + + Options = cnf.subtree("Auto-Decruft::Options") + if Options["Help"]: + usage() + + dryrun = False + if Options["Dry-Run"]: + dryrun = True + + session = DBConn().session() + + suite = get_suite(Options["Suite"].lower(), session) + if not suite: + utils.fubar("Cannot find suite %s" % Options["Suite"].lower()) + + suite_id = suite.suite_id + suite_name = suite.suite_name.lower() + + remove_sourceless_cruft(suite_name, suite_id, session, dryrun) + removeNBS(suite_name, suite_id, session, dryrun) + +################################################################################ + +if __name__ == '__main__': + main() diff --git a/dak/dak.py b/dak/dak.py index 52bf3af6..18be3cef 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -117,6 +117,8 @@ def init(): "Update suite with packages from a different suite"), ("cruft-report", "Check for obsolete or duplicated packages"), + ("auto-decruft", + "Clean cruft without reverse dependencies automatically"), ("examine-package", "Show information useful for NEW processing"), ("import", diff --git a/docs/README.quotes b/docs/README.quotes index ff6810f7..9f818a5f 100644 --- a/docs/README.quotes +++ b/docs/README.quotes @@ -134,13 +134,6 @@ DON'T PUT http://172.16.100.107/ IN YOUR URLS, YOU INCOMPETENT FUCKMONKEYS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -| priviledged positions? What privilege? The honour of working harder -| than most people for absolutely no recognition? - -Manoj Srivastava in <87lln8aqfm.fsf@glaurung.internal.golden-gryphon.com> - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - you could just r00t klecker through [...] and do it yourself heh I think there's a bit in the DMUP about that