]> git.decadent.org.uk Git - dak.git/blob - cindy
2004-11-27 James Troup <james@nocrew.org> * cindy (process): restrict "find all...
[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.12 2004-11-27 16:08:21 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 ################################################################################
32
33 import pg, sys;
34 import utils, db_access;
35 import apt_pkg;
36
37 ################################################################################
38
39 Cnf = None;
40 Options = None;
41 projectB = None;
42 override = {}
43
44 ################################################################################
45
46 def usage (exit_code=0):
47     print """Usage: cindy
48 Check for cruft in overrides.
49
50   -h, --help                 show this help and exit"""
51
52     sys.exit(exit_code)
53
54 ################################################################################
55
56 def process(suite, component, type):
57     global override;
58
59     suite_id = db_access.get_suite_id(suite);
60     if suite_id == -1:
61         utils.fubar("Suite '%s' not recognised." % (suite));
62
63     component_id = db_access.get_component_id(component);
64     if component_id == -1:
65         utils.fubar("Component '%s' not recognised." % (component));
66
67     type_id = db_access.get_override_type_id(type);
68     if type_id == -1:
69         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
70     dsc_type_id = db_access.get_override_type_id("dsc");
71
72     if type == "deb" or type == "udeb":
73         packages = {};
74         q = projectB.query("""
75 SELECT b.package FROM binaries b, bin_associations ba, files f,
76                               location l, component c
77  WHERE b.id = ba.bin AND f.id = b.file AND l.id = f.location
78    AND c.id = l.component AND ba.suite = %s AND c.id = %s
79 """ % (suite_id, component_id));
80         for i in q.getresult():
81             packages[i[0]] = "";
82
83     src_packages = {};
84     q = projectB.query("""
85 SELECT s.source FROM source s, src_associations sa, files f, location l,
86                      component c
87  WHERE s.id = sa.source AND f.id = s.file AND l.id = f.location
88    AND c.id = l.component AND sa.suite = %s AND c.id = %s
89 """ % (suite_id, component_id));
90     for i in q.getresult():
91         src_packages[i[0]] = "";
92
93     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));
94     projectB.query("BEGIN WORK");
95     for i in q.getresult():
96         package = i[0];
97         if type == "deb" or type == "udeb":
98             if not packages.has_key(package):
99                 if not src_packages.has_key(package):
100                     print "DELETING: %s" % (package);
101                     if not Options["No-Action"]:
102                         projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
103                 else:
104                     print "MAKING SOURCE: %s" % (package);
105                     if not Options["No-Action"]:
106                         projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
107                     # Then if source doesn't already have a copy, insert it into source
108                     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));
109                     if not q.getresult() and not Options["No-Action"]:
110                         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]));
111         else: # dsc
112             if not src_packages.has_key(package):
113                 print "DELETING: %s" % (package);
114                 if not Options["No-Action"]:
115                     projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (package, suite_id, component_id, type_id));
116     projectB.query("COMMIT WORK");
117
118
119 ################################################################################
120
121 def main ():
122     global Cnf, Options, projectB, override;
123
124     Cnf = utils.get_conf()
125
126     Arguments = [('h',"help","Cindy::Options::Help"),
127                  ('n',"no-action", "Cindy::Options::No-Action")];
128     for i in [ "help", "no-action" ]:
129         if not Cnf.has_key("Cindy::Options::%s" % (i)):
130             Cnf["Cindy::Options::%s" % (i)] = "";
131     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
132     Options = Cnf.SubTree("Cindy::Options")
133
134     if Options["Help"]:
135         usage();
136
137     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
138     db_access.init(Cnf, projectB);
139
140     suite = "unstable"
141     print "Processing %s..." % (suite);
142     for component in Cnf.SubTree("Component").List():
143         if component == "mixed":
144             continue; # Ick
145         for otype in Cnf.ValueList("OverrideType"):
146             print "Processing %s [%s - %s]..." % (suite, component, otype);
147             process(suite, component, otype);
148
149 ################################################################################
150
151 if __name__ == '__main__':
152     main()
153