]> git.decadent.org.uk Git - dak.git/blob - cindy
Fix database name to be a config option. Fix debian/rules typo. [Ryan Murray]
[dak.git] / cindy
1 #!/usr/bin/env python
2
3 # Output override files for apt-ftparchive and indices/
4 # Copyright (C) 2000, 2001  James Troup <james@nocrew.org>
5 # $Id: cindy,v 1.3 2001-03-20 00:28:11 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 # X-Listening-To: Sanitarium / Master of the Puppets - Metallica
23
24 ################################################################################
25
26 import pg, sys, string
27 import utils, db_access, natalie
28 import apt_pkg;
29
30 ################################################################################
31
32 Cnf = None;
33 projectB = None;
34 override = {}
35
36 ################################################################################
37
38 def process(suite, component, type):
39     global override;
40     
41     suite_id = db_access.get_suite_id(suite);
42     if suite_id == -1:
43         sys.stderr.write("Suite '%s' not recognised.\n" % (suite));
44         sys.exit(2);
45
46     component_id = db_access.get_component_id(component);
47     if component_id == -1:
48         sys.stderr.write("Component '%s' not recognised.\n" % (component));
49         sys.exit(2);
50
51     type_id = db_access.get_override_type_id(type);
52     if type_id == -1:
53         sys.stderr.write("Type '%s' not recognised. (Valid types are deb, udeb and dsc.)\n" % (type));
54         sys.exit(2);
55     dsc_type_id = db_access.get_override_type_id("dsc");
56
57     if type == "deb" or type == "udeb":
58         packages = {};
59         q = projectB.query("SELECT DISTINCT b.package FROM binaries b, bin_associations ba WHERE b.id = ba.bin AND ba.suite = %s" % (suite_id));
60         for i in q.getresult():
61             packages[i[0]] = "";
62
63     src_packages = {};
64     q = projectB.query("SELECT DISTINCT s.source FROM source s, src_associations sa WHERE s.id = sa.source AND sa.suite = %s" % (suite_id));
65     for i in q.getresult():
66         src_packages[i[0]] = "";
67
68     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));
69     projectB.query("BEGIN WORK");
70     for i in q.getresult():
71         package = i[0];
72         if type == "deb" or type == "udeb":
73             if not packages.has_key(package):
74                 if not src_packages.has_key(package):
75                     print "DELETING: %s" % (package);
76                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
77                     #% (package, suite_id, component_id, type_id));
78                 else:
79                     print "MAKING SOURCE: %s" % (package);
80                     #projectB.query("DELETE FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s"
81                     #% (package, suite_id, component_id, type_id));
82                     # Then if source doesn't already have a copy, insert it into source
83                     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));
84                     if q.getresult() == []:
85                         #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]));
86                         print "(nop)"
87         else: # dsc
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     projectB.query("COMMIT WORK");
93             
94
95 ################################################################################
96
97 def main ():
98     global Cnf, projectB, override;
99
100     apt_pkg.init();
101     
102     Cnf = apt_pkg.newConfiguration();
103     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
104     Arguments = [('D',"debug","Denise::Options::Debug", "IntVal"),
105                  ('h',"help","Denise::Options::Help"),
106                  ('V',"version","Denise::Options::Version")];
107     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
108
109     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
110     db_access.init(Cnf, projectB);
111
112     for suite in [ "stable", "unstable" ]:
113         sys.stderr.write("Processing %s...\n" % (suite));
114         for component in Cnf.SubTree("Component").List():
115             if component == "mixed":
116                 continue; # Ick
117             for type in Cnf.SubTree("OverrideType").List():
118                 print "Processing %s [%s - %s]..." % (suite, component, type);
119                 process(suite, component, type);
120
121 #######################################################################################
122
123 if __name__ == '__main__':
124     main()
125