1
2
3 """ Manage debug suites
4
5 @contact: Debian FTP Master <ftpmaster@debian.org>
6 @copyright: 2015, Ansgar Burchardt <ansgar@debian.org>
7
8 """
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import apt_pkg
27 import sys
28
29 from daklib import daklog
30 from daklib.archive import ArchiveTransaction
31 from daklib.dbconn import *
32 from daklib.config import Config
33
34
35
36 Options = None
37 Logger = None
38
39
40
41
43 print("""Usage: dak manage-debug-suites [-a|--all|<suite>...]
44 Manage the contents of one or more debug suites
45
46 -a, --all run on all known debug suites
47 -n, --no-action don't do anything
48 -h, --help show this help and exit""")
49
50 sys.exit(exit_code)
51
52
53
54
55 -def clean(debug_suite, transaction):
56 session = transaction.session
57
58
59 any_suite = session.query(Suite).filter_by(debug_suite=debug_suite).first()
60 if any_suite is None:
61 raise Exception("Suite '{0}' is not a debug suite".format(debug_suite.suite_name))
62
63
64
65 query = """
66 WITH
67 sources_to_keep AS
68 (SELECT DISTINCT sa.source
69 FROM src_associations sa
70 JOIN suite ON sa.suite = suite.id
71 WHERE suite.debugsuite_id = :debugsuite_id),
72 sources_removed AS
73 (DELETE FROM src_associations sa
74 WHERE sa.suite = :debugsuite_id
75 AND sa.source NOT IN (SELECT source FROM sources_to_keep)
76 RETURNING sa.source)
77 DELETE FROM bin_associations ba
78 USING binaries b
79 WHERE ba.suite = :debugsuite_id
80 AND ba.bin = b.id
81 AND b.source NOT IN (SELECT source FROM sources_to_keep)
82 RETURNING
83 b.package,
84 b.version,
85 (SELECT arch_string FROM architecture WHERE id=b.architecture) AS architecture
86 """
87 result = session.execute(query, {"debugsuite_id": debug_suite.suite_id})
88 for row in result:
89 Logger.log(["remove", debug_suite.suite_name, row[0], row[1], row[2]])
90
91
93 global Options, Logger
94
95 cnf = Config()
96
97 for i in ["Help", "No-Action", "All"]:
98 key = "Manage-Debug-Suites::Options::%s" % i
99 if key not in cnf:
100 cnf[key] = ""
101
102 Arguments = [('h', "help", "Manage-Debug-Suites::Options::Help"),
103 ('n', "no-action", "Manage-Debug-Suites::Options::No-Action"),
104 ('a', "all", "Manage-Debug-Suites::Options::All")]
105
106 debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
107 Options = cnf.subtree("Manage-Debug-Suites::Options")
108
109 if Options["Help"]:
110 usage()
111
112 Logger = daklog.Logger('manage-debug-suites', Options['No-Action'])
113
114 with ArchiveTransaction() as transaction:
115 session = transaction.session
116 if Options['All']:
117 if len(debug_suite_names) != 0:
118 print("E: Cannot use both -a and a queue name")
119 sys.exit(1)
120 raise Exception("Not yet implemented.")
121 else:
122 debug_suites = session.query(Suite).filter(Suite.suite_name.in_(debug_suite_names))
123
124 for debug_suite in debug_suites:
125 Logger.log(['cleaning debug suite {0}'.format(debug_suite.suite_name)])
126 clean(debug_suite, transaction)
127 if not Options['No-Action']:
128 transaction.commit()
129 else:
130 transaction.rollback()
131
132 Logger.close()
133
134
135
136
137 if __name__ == '__main__':
138 main()
139