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, %d)" % \
39 (package, version, suite_name, architecture, reason, id)
41 Logger.log([reason, package, version, suite_name, \
46 def obsoleteAnyByAllAssociations(suite, session):
48 SELECT obsolete.id, package, obsolete.version, suite_name, arch_string
49 FROM obsolete_any_by_all_associations AS obsolete
50 JOIN architecture ON obsolete.architecture = architecture.id
51 JOIN suite ON obsolete.suite = suite.id
54 return fetch('newer_all', query, { 'suite': suite }, session)
56 def obsoleteAnyAssociations(suite, session):
58 SELECT obsolete.id, package, obsolete.version, suite_name, arch_string
59 FROM obsolete_any_associations AS obsolete
60 JOIN architecture ON obsolete.architecture = architecture.id
61 JOIN suite ON obsolete.suite = suite.id
64 return fetch('newer_any', query, { 'suite': suite }, session)
66 def obsoleteSrcAssociations(suite, session):
68 SELECT obsolete.id, source, obsolete.version, suite_name,
69 'source' AS arch_string
70 FROM obsolete_src_associations AS obsolete
71 JOIN suite ON obsolete.suite = suite.id
74 return fetch('old_and_unreferenced', query, { 'suite': suite }, session)
76 def obsoleteAllAssociations(suite, session):
78 SELECT obsolete.id, package, obsolete.version, suite_name,
80 FROM obsolete_all_associations AS obsolete
81 JOIN suite ON obsolete.suite = suite.id
84 return fetch('old_and_unreferenced', query, { 'suite': suite }, session)
86 def deleteAssociations(table, idList, session):
92 session.execute(query, [{'id': id} for id in idList])
94 def doDaDoDa(suite, session):
95 # keep this part disabled because it is too dangerous
96 #idList = obsoleteAnyByAllAssociations(suite, session)
97 #deleteAssociations('bin_associations', idList, session)
99 idList = obsoleteAnyAssociations(suite, session)
100 deleteAssociations('bin_associations', idList, session)
102 idList = obsoleteSrcAssociations(suite, session)
103 deleteAssociations('src_associations', idList, session)
105 idList = obsoleteAllAssociations(suite, session)
106 deleteAssociations('bin_associations', idList, session)
109 print """Usage: dak dominate [OPTIONS]
110 Remove obsolete source and binary associations from suites.
112 -s, --suite=SUITE act on this suite
113 -h, --help show this help and exit
114 -n, --no-action don't commit changes
115 -f, --force also clean up untouchable suites
117 SUITE can be comma (or space) separated list, e.g.
118 --suite=testing,unstable"""
122 global Options, Logger
124 Arguments = [('h', "help", "Obsolete::Options::Help"),
125 ('s', "suite", "Obsolete::Options::Suite", "HasArg"),
126 ('n', "no-action", "Obsolete::Options::No-Action"),
127 ('f', "force", "Obsolete::Options::Force")]
128 query_suites = DBConn().session().query(Suite)
129 suites = [suite.suite_name for suite in query_suites.all()]
130 if not cnf.has_key('Obsolete::Options::Suite'):
131 cnf['Obsolete::Options::Suite'] = ','.join(suites)
132 cnf['Obsolete::Options::Help'] = ''
133 cnf['Obsolete::Options::No-Action'] = ''
134 cnf['Obsolete::Options::Force'] = ''
135 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
136 Options = cnf.SubTree("Obsolete::Options")
139 Logger = daklog.Logger("dominate")
140 session = DBConn().session()
141 for suite_name in utils.split_args(Options['Suite']):
142 suite = session.query(Suite).filter_by(suite_name = suite_name).one()
143 if not suite.untouchable or Options['Force']:
144 doDaDoDa(suite.suite_id, session)
145 if Options['No-Action']:
151 if __name__ == '__main__':