]> git.decadent.org.uk Git - dak.git/blob - denise
Fix database name to be a config option. Fix debian/rules typo. [Ryan Murray]
[dak.git] / denise
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: denise,v 1.4 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 # This is seperate because it's horribly Debian specific and I don't
22 # want that kind of horribleness in the otherwise generic natalie.  It
23 # does duplicate code tho.
24
25 ################################################################################
26
27 import pg, sys, string
28 import utils, db_access, natalie
29 import apt_pkg;
30
31 ################################################################################
32
33 Cnf = None;
34 projectB = None;
35 override = {}
36
37 ################################################################################
38
39 def list(suite, component, type):
40     global override;
41     
42     suite_id = db_access.get_suite_id(suite);
43     if suite_id == -1:
44         sys.stderr.write("Suite '%s' not recognised.\n" % (suite));
45         sys.exit(2);
46
47     component_id = db_access.get_component_id(component);
48     if component_id == -1:
49         sys.stderr.write("Component '%s' not recognised.\n" % (component));
50         sys.exit(2);
51
52     type_id = db_access.get_override_type_id(type);
53     if type_id == -1:
54         sys.stderr.write("Type '%s' not recognised. (Valid types are deb, udeb and dsc.)\n" % (type));
55         sys.exit(2);
56
57     if not override.has_key(suite):
58         override[suite] = {};
59     if not override[suite].has_key(component):
60         override[suite][component] = {};
61     if not override[suite][component].has_key(type):
62         override[suite][component][type] = {};
63
64     if type == "dsc":
65         q = projectB.query("SELECT o.package, s.section, o.maintainer FROM override o, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.section = s.id ORDER BY s.section, o.package" % (suite_id, component_id, type_id));
66         for i in q.getresult():
67             override[suite][component][type][i[0]] = i;
68             print string.join(i, '\t');
69     else:
70         q = projectB.query("SELECT o.package, p.priority, s.section, o.maintainer, p.level FROM override o, priority p, section s WHERE o.suite = %s AND o.component = %s AND o.type = %s AND o.priority = p.id AND o.section = s.id ORDER BY s.section, p.level, o.package" % (suite_id, component_id, type_id));
71         for i in q.getresult():
72             i = i[:-1]; # Strip the priority level
73             override[suite][component][type][i[0]] = i;
74             print string.join(i, '\t');
75
76 ################################################################################
77
78 def main ():
79     global Cnf, projectB, override;
80
81     apt_pkg.init();
82     
83     Cnf = apt_pkg.newConfiguration();
84     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
85     Arguments = [('D',"debug","Denise::Options::Debug", "IntVal"),
86                  ('h',"help","Denise::Options::Help"),
87                  ('V',"version","Denise::Options::Version")];
88     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
89
90     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
91     db_access.init(Cnf, projectB);
92
93     natalie.init();
94
95     for suite in [ "stable", "unstable" ]:
96         sys.stderr.write("Processing %s...\n" % (suite));
97         override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
98         for component in Cnf.SubTree("Component").List():
99             if component == "mixed":
100                 continue; # Ick
101             for type in Cnf.SubTree("OverrideType").List():
102                 if type == "deb":
103                     override_type = "";
104                 elif type == "udeb":
105                     if suite != "unstable" or component != "main":
106                         continue; # Ick2
107                     override_type = ".debian-installer";
108                 elif type == "dsc":
109                     override_type = ".src";
110                 filename = "%s/override.%s.%s%s" % (Cnf["Dir::OverrideDir"], override_suite, string.replace(component, "non-US/", ""), override_type);
111                 file = utils.open_file(filename, 'w');
112                 sys.stdout = file;
113                 list(suite, component, type);
114                 sys.stdout.close();
115
116     # Munge the override file for testing by using unstable's where
117     # possible and falling back on stable's where it's not.
118
119     sys.stderr.write("Processing testing...\n");
120     suite = "testing";
121     suite_id = db_access.get_suite_id(suite);
122     override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
123     for component in Cnf.SubTree("Component").List():
124         if component == "mixed":
125             continue;
126         component_id = db_access.get_component_id(component);
127         for type in Cnf.SubTree("OverrideType").List():
128             if type == "deb":
129                 override_type = "";
130                 q = projectB.query("SELECT DISTINCT b.package FROM bin_associations ba, binaries b, files f, location l WHERE ba.suite = %s AND l.component = %s AND ba.bin = b.id AND b.file = f.id AND f.location = l.id" % (suite_id, component_id));
131             elif type == "dsc":
132                 q = projectB.query("SELECT DISTINCT s.source FROM src_associations sa, source s, files f, location l WHERE sa.suite = %s AND l.component = %s AND sa.source = s.id AND s.file = f.id AND f.location = l.id" % (suite_id, component_id));
133                 override_type = ".src";
134             elif type == "udeb":
135                 continue;
136             filename = "override.%s.%s%s" % (override_suite, string.replace(component, "non-US/", ""), override_type);
137             file = utils.open_file(filename, 'w');
138             sys.stdout = file;
139             for i in q.getresult():
140                 package = i[0];
141                 if override["unstable"][component][type].has_key(package):
142                     print string.join(override["unstable"][component][type][package], '\t');
143                 elif override["stable"][component][type].has_key(package):
144                     print string.join(override["stable"][component][type][package], '\t');
145                 else:
146                     if type == "dsc" and (override["unstable"][component]["deb"].has_key(package) or override["stable"][component]["deb"].has_key(package)):
147                         continue; # source falls back on binary; so accept silently
148                     sys.stderr.write("W: Can't find override entry for testing package '%s' (component %s, type %s).\n" % (package, component, type));
149             sys.stdout.close();
150     
151
152 #######################################################################################
153
154 if __name__ == '__main__':
155     main()
156