]> git.decadent.org.uk Git - dak.git/blob - cindy
Add usage() and use it.
[dak.git] / cindy
1 #!/usr/bin/env python
2
3 # Cruft checker for overrides
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: cindy,v 1.11 2003-01-02 18:10:02 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 projectB = None;
41 override = {}
42
43 ################################################################################
44
45 def usage (exit_code=0):
46     print """Usage: cindy
47 Check for cruft in overrides.
48
49   -h, --help                 show this help and exit"""
50
51     sys.exit(exit_code)
52
53 ################################################################################
54
55 def process(suite, component, type):
56     global override;
57
58     suite_id = db_access.get_suite_id(suite);
59     if suite_id == -1:
60         utils.fubar("Suite '%s' not recognised." % (suite));
61
62     component_id = db_access.get_component_id(component);
63     if component_id == -1:
64         utils.fubar("Component '%s' not recognised." % (component));
65
66     type_id = db_access.get_override_type_id(type);
67     if type_id == -1:
68         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
69     dsc_type_id = db_access.get_override_type_id("dsc");
70
71     if type == "deb" or type == "udeb":
72         packages = {};
73         q = projectB.query("SELECT DISTINCT b.package FROM binaries b, bin_associations ba WHERE b.id = ba.bin AND ba.suite = %s" % (suite_id));
74         for i in q.getresult():
75             packages[i[0]] = "";
76
77     src_packages = {};
78     q = projectB.query("SELECT DISTINCT s.source FROM source s, src_associations sa WHERE s.id = sa.source AND sa.suite = %s" % (suite_id));
79     for i in q.getresult():
80         src_packages[i[0]] = "";
81
82     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));
83     projectB.query("BEGIN WORK");
84     for i in q.getresult():
85         package = i[0];
86         if type == "deb" or type == "udeb":
87             if not packages.has_key(package):
88                 if not src_packages.has_key(package):
89                     print "DELETING: %s" % (package);
90                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
91                     #% (package, suite_id, component_id, type_id));
92                 else:
93                     print "MAKING SOURCE: %s" % (package);
94                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
95                     #% (package, suite_id, component_id, type_id));
96                     # Then if source doesn't already have a copy, insert it into source
97                     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));
98                     if not q.getresult():
99                         #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]));
100                         print "(nop)"
101         else: # dsc
102             if not src_packages.has_key(package):
103                 print "DELETING: %s" % (package);
104                 #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
105                 #% (package, suite_id, component_id, type_id));
106     projectB.query("COMMIT WORK");
107
108
109 ################################################################################
110
111 def main ():
112     global Cnf, projectB, override;
113
114     Cnf = utils.get_conf()
115
116     Arguments = [('h',"help","Cindy::Options::Help")];
117     for i in [ "help" ]:
118         if not Cnf.has_key("Cindy::Options::%s" % (i)):
119             Cnf["Cindy::Options::%s" % (i)] = "";
120     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
121     Options = Cnf.SubTree("Cindy::Options")
122
123     if Options["Help"]:
124         usage();
125
126     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
127     db_access.init(Cnf, projectB);
128
129     for suite in [ "stable", "unstable" ]:
130         print "Processing %s..." % (suite);
131         for component in Cnf.SubTree("Component").List():
132             if component == "mixed":
133                 continue; # Ick
134             for type in Cnf.ValueList("OverrideType"):
135                 print "Processing %s [%s - %s]..." % (suite, component, type);
136                 process(suite, component, type);
137
138 ################################################################################
139
140 if __name__ == '__main__':
141     main()
142