]> git.decadent.org.uk Git - dak.git/blob - cindy
add changelog back
[dak.git] / cindy
1 #!/usr/bin/env python
2
3 # Cruft checker for overrides
4 # Copyright (C) 2000, 2001, 2002, 2004  James Troup <james@nocrew.org>
5 # $Id: cindy,v 1.13 2004-11-27 19:23:40 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 ######################################################################
24 # NB: cindy is not a good idea with New Incoming as she doesn't take #
25 # into account accepted.  You can minimize the impact of this by     #
26 # running her immediately after kelly but that's still racy because  #
27 # lisa doesn't lock with kelly.  A better long term fix is the evil  #
28 # plan for accepted to be in the DB.                                 #
29 ######################################################################
30
31 # NB[2]: cindy entirely breaks for suites that share overrides,
32 # e.g. experimental in Debian.
33
34 # NB[3]: cindy ENTIRELY breaks for 'source-only'-upload based distros
35 # like Ubuntu.  Go Cindy.
36
37 ################################################################################
38
39 import pg, sys;
40 import utils, db_access;
41 import apt_pkg;
42
43 ################################################################################
44
45 Cnf = None;
46 Options = None;
47 projectB = None;
48 override = {}
49
50 ################################################################################
51
52 def usage (exit_code=0):
53     print """Usage: cindy
54 Check for cruft in overrides.
55
56   -h, --help                 show this help and exit"""
57
58     sys.exit(exit_code)
59
60 ################################################################################
61
62 def process(suite, component, type):
63     global override;
64
65     suite_id = db_access.get_suite_id(suite);
66     if suite_id == -1:
67         utils.fubar("Suite '%s' not recognised." % (suite));
68
69     component_id = db_access.get_component_id(component);
70     if component_id == -1:
71         utils.fubar("Component '%s' not recognised." % (component));
72
73     type_id = db_access.get_override_type_id(type);
74     if type_id == -1:
75         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
76     dsc_type_id = db_access.get_override_type_id("dsc");
77
78     if type == "deb" or type == "udeb":
79         packages = {};
80         q = projectB.query("""
81 SELECT b.package FROM binaries b, bin_associations ba, files f,
82                               location l, component c
83  WHERE b.id = ba.bin AND f.id = b.file AND l.id = f.location
84    AND c.id = l.component AND ba.suite = %s AND c.id = %s
85 """ % (suite_id, component_id));
86         for i in q.getresult():
87             packages[i[0]] = "";
88
89     src_packages = {};
90     q = projectB.query("""
91 SELECT s.source FROM source s, src_associations sa, files f, location l,
92                      component c
93  WHERE s.id = sa.source AND f.id = s.file AND l.id = f.location
94    AND c.id = l.component AND sa.suite = %s AND c.id = %s
95 """ % (suite_id, component_id));
96     for i in q.getresult():
97         src_packages[i[0]] = "";
98
99     q = projectB.query("SELECT package, priority, section, maintainer FROM override WHERE suite = %s AND component = %s AND type = %s" % (suite_id, component_id, type_id));
100     projectB.query("BEGIN WORK");
101     for i in q.getresult():
102         package = i[0];
103         if type == "deb" or type == "udeb":
104             if not packages.has_key(package):
105                 if not src_packages.has_key(package):
106                     print "DELETING: %s" % (package);
107                     if not Options["No-Action"]:
108                         projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
109                 else:
110                     print "MAKING SOURCE: %s" % (package);
111                     if not Options["No-Action"]:
112                         projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
113                     # Then if source doesn't already have a copy, insert it into source
114                     q = projectB.query("SELECT package FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, dsc_type_id));
115                     if not q.getresult() and not Options["No-Action"]:
116                         projectB.query("INSERT INTO override (package, suite, component, priority, section, type, maintainer) VALUES ('%s', %s, %s, %s, %s, %s, '%s')" % (package, suite_id, component_id, i[1], i[2], dsc_type_id, i[3]));
117         else: # dsc
118             if not src_packages.has_key(package):
119                 print "DELETING: %s" % (package);
120                 if not Options["No-Action"]:
121                     projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
122     projectB.query("COMMIT WORK");
123
124
125 ################################################################################
126
127 def main ():
128     global Cnf, Options, projectB, override;
129
130     Cnf = utils.get_conf()
131
132     Arguments = [('h',"help","Cindy::Options::Help"),
133                  ('n',"no-action", "Cindy::Options::No-Action")];
134     for i in [ "help", "no-action" ]:
135         if not Cnf.has_key("Cindy::Options::%s" % (i)):
136             Cnf["Cindy::Options::%s" % (i)] = "";
137     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
138     Options = Cnf.SubTree("Cindy::Options")
139
140     if Options["Help"]:
141         usage();
142
143     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
144     db_access.init(Cnf, projectB);
145
146     suite = "unstable"
147     print "Processing %s..." % (suite);
148     for component in Cnf.SubTree("Component").List():
149         if component == "mixed":
150             continue; # Ick
151         for otype in Cnf.ValueList("OverrideType"):
152             print "Processing %s [%s - %s]..." % (suite, component, otype);
153             process(suite, component, otype);
154
155 ################################################################################
156
157 if __name__ == '__main__':
158     main()
159