4 Remove obsolete source and binary associations from suites.
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009 Torsten Werner <twerner@debian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 from daklib.dbconn import *
26 from daklib.config import Config
27 from daklib import daklog, utils
33 def fetch(reason, query, args, session):
35 for row in session.execute(query, args).fetchall():
36 (id, package, version, suite_name, architecture) = row
37 if Options['No-Action']:
38 print "Delete %s %s from %s architecture %s (%s)" % \
39 (package, version, suite_name, architecture, reason)
41 Logger.log([reason, package, version, suite_name, architecture])
45 def obsoleteAnyByAllAssociations(suite, session):
47 SELECT obsolete.id, package, obsolete.version, suite_name, arch_string
48 FROM obsolete_any_by_all_associations AS obsolete
49 JOIN architecture ON obsolete.architecture = architecture.id
50 JOIN suite ON obsolete.suite = suite.id
53 return fetch('newer_all', query, { 'suite': suite }, session)
55 def obsoleteAnyAssociations(suite, session):
57 SELECT obsolete.id, package, obsolete.version, suite_name, arch_string
58 FROM obsolete_any_associations AS obsolete
59 JOIN architecture ON obsolete.architecture = architecture.id
60 JOIN suite ON obsolete.suite = suite.id
63 return fetch('newer_any', query, { 'suite': suite }, session)
65 def obsoleteSrcAssociations(suite, session):
67 SELECT obsolete.id, source, obsolete.version, suite_name,
68 'source' AS arch_string
69 FROM obsolete_src_associations AS obsolete
70 JOIN suite ON obsolete.suite = suite.id
73 return fetch('old_and_unreferenced', query, { 'suite': suite }, session)
75 def obsoleteAllAssociations(suite, session):
77 SELECT obsolete.id, package, obsolete.version, suite_name,
79 FROM obsolete_all_associations AS obsolete
80 JOIN suite ON obsolete.suite = suite.id
83 return fetch('old_and_unreferenced', query, { 'suite': suite }, session)
85 def deleteAssociations(table, idList, session):
91 session.execute(query, [{'id': id} for id in idList])
93 def doDaDoDa(suite, session):
94 # keep this part disabled because it is too dangerous
95 #idList = obsoleteAnyByAllAssociations(suite, session)
96 #deleteAssociations('bin_associations', idList, session)
98 idList = obsoleteAnyAssociations(suite, session)
99 deleteAssociations('bin_associations', idList, session)
101 idList = obsoleteSrcAssociations(suite, session)
102 deleteAssociations('src_associations', idList, session)
104 idList = obsoleteAllAssociations(suite, session)
105 deleteAssociations('bin_associations', idList, session)
108 print """Usage: dak dominate [OPTIONS]
109 Remove obsolete source and binary associations from suites.
111 -s, --suite=SUITE act on this suite
112 -h, --help show this help and exit
113 -n, --no-action don't commit changes
114 -f, --force also clean up untouchable suites
116 SUITE can be comma (or space) separated list, e.g.
117 --suite=testing,unstable"""
121 global Options, Logger
123 Arguments = [('h', "help", "Obsolete::Options::Help"),
124 ('s', "suite", "Obsolete::Options::Suite", "HasArg"),
125 ('n', "no-action", "Obsolete::Options::No-Action"),
126 ('f', "force", "Obsolete::Options::Force")]
127 query_suites = DBConn().session().query(Suite)
128 suites = [suite.suite_name for suite in query_suites.all()]
129 if not cnf.has_key('Obsolete::Options::Suite'):
130 cnf['Obsolete::Options::Suite'] = ','.join(suites)
131 cnf['Obsolete::Options::Help'] = ''
132 cnf['Obsolete::Options::No-Action'] = ''
133 cnf['Obsolete::Options::Force'] = ''
134 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
135 Options = cnf.SubTree("Obsolete::Options")
138 Logger = daklog.Logger(cnf.Cnf, "dominate")
139 session = DBConn().session()
140 for suite_name in utils.split_args(Options['Suite']):
141 suite = session.query(Suite).filter_by(suite_name = suite_name).one()
142 if not suite.untouchable or Options['Force']:
143 doDaDoDa(suite.suite_id, session)
144 if Options['No-Action']:
149 if __name__ == '__main__':