3 """ Manage debug suites
5 @contact: Debian FTP Master <ftpmaster@debian.org>
6 @copyright: 2015, Ansgar Burchardt <ansgar@debian.org>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ################################################################################
29 from daklib import daklog
30 from daklib.archive import ArchiveTransaction
31 from daklib.dbconn import *
32 from daklib.config import Config
34 ################################################################################
39 ################################################################################
41 def usage (exit_code=0):
42 print """Usage: dak manage-debug-suites [-a|--all|<suite>...]
43 Manage the contents of one or more debug suites
45 -a, --all run on all known debug suites
46 -n, --no-action don't do anything
47 -h, --help show this help and exit"""
51 ################################################################################
53 def clean(debug_suite, transaction):
54 session = transaction.session
56 # Sanity check: make sure this is a debug suite or we would remove everything
57 any_suite = session.query(Suite).filter_by(debug_suite=debug_suite).first()
59 raise Exception("Suite '{0}' is not a debug suite".format(debug_suite.suite_name))
61 # Only keep source packages that are still a base suite.
62 # All other sources and their binary packages can go.
66 (SELECT DISTINCT sa.source
67 FROM src_associations sa
68 JOIN suite ON sa.suite = suite.id
69 WHERE suite.debugsuite_id = :debugsuite_id),
71 (DELETE FROM src_associations sa
72 WHERE sa.suite = :debugsuite_id
73 AND sa.source NOT IN (SELECT source FROM sources_to_keep)
75 DELETE FROM bin_associations ba
77 WHERE ba.suite = :debugsuite_id
79 AND b.source IN (SELECT source FROM sources_removed)
83 (SELECT arch_string FROM architecture WHERE id=b.architecture) AS architecture
85 result = session.execute(query, {"debugsuite_id": debug_suite.suite_id})
87 Logger.log(["remove", debug_suite.suite_name, row[0], row[1], row[2]])
90 global Options, Logger
94 for i in ["Help", "No-Action", "All"]:
95 if not cnf.has_key("Manage-Debug-Suites::Options::%s" % (i)):
96 cnf["Manage-Debug-Suites::Options::%s" % (i)] = ""
98 Arguments = [('h',"help","Manage-Debug-Suites::Options::Help"),
99 ('n',"no-action","Manage-Debug-Suites::Options::No-Action"),
100 ('a',"all","Manage-Debug-Suites::Options::All")]
102 debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
103 Options = cnf.subtree("Manage-Debug-Suites::Options")
108 Logger = daklog.Logger('manage-debug-suites', Options['No-Action'])
110 with ArchiveTransaction() as transaction:
111 session = transaction.session
113 if len(debug_suite_names) != 0:
114 print "E: Cannot use both -a and a queue name"
116 raise Exception("Not yet implemented.")
118 debug_suites = session.query(Suite).filter(Suite.suite_name.in_(debug_suite_names))
120 for debug_suite in debug_suites:
121 Logger.log(['cleaning debug suite {0}'.format(debug_suite.suite_name)])
122 clean(debug_suite, transaction)
123 if not Options['No-Action']:
126 transaction.rollback()
130 #######################################################################################
132 if __name__ == '__main__':