]> git.decadent.org.uk Git - dak.git/blob - denise
Postgres 7.1 fixes
[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.7 2001-09-13 23:51:51 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 result_join (original):
40     list = [];
41     for i in xrange(len(original)):
42         if original[i] == None:
43             list.append("");
44         else:
45             list.append(original[i]);
46     return string.join(list, '\t');
47
48 def list(suite, component, type):
49     global override;
50
51     suite_id = db_access.get_suite_id(suite);
52     if suite_id == -1:
53         utils.fubar("Suite '%s' not recognised." % (suite));
54
55     component_id = db_access.get_component_id(component);
56     if component_id == -1:
57         utils.fubar("Component '%s' not recognised." % (component));
58
59     type_id = db_access.get_override_type_id(type);
60     if type_id == -1:
61         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
62
63     if not override.has_key(suite):
64         override[suite] = {};
65     if not override[suite].has_key(component):
66         override[suite][component] = {};
67     if not override[suite][component].has_key(type):
68         override[suite][component][type] = {};
69
70     if type == "dsc":
71         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));
72         for i in q.getresult():
73             override[suite][component][type][i[0]] = i;
74             print result_join(i);
75     else:
76         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));
77         for i in q.getresult():
78             i = i[:-1]; # Strip the priority level
79             override[suite][component][type][i[0]] = i;
80             print result_join(i);
81
82 ################################################################################
83
84 def main ():
85     global Cnf, projectB, override;
86
87     apt_pkg.init();
88
89     Cnf = apt_pkg.newConfiguration();
90     apt_pkg.ReadConfigFileISC(Cnf,utils.which_conf_file());
91     Arguments = [('D',"debug","Denise::Options::Debug", "IntVal"),
92                  ('h',"help","Denise::Options::Help"),
93                  ('V',"version","Denise::Options::Version")];
94     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
95
96     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
97     db_access.init(Cnf, projectB);
98
99     natalie.init();
100
101     for suite in [ "stable", "unstable" ]:
102         sys.stderr.write("Processing %s...\n" % (suite));
103         override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
104         for component in Cnf.SubTree("Component").List():
105             if component == "mixed":
106                 continue; # Ick
107             for type in Cnf.SubTree("OverrideType").List():
108                 if type == "deb":
109                     override_type = "";
110                 elif type == "udeb":
111                     if suite != "unstable" or component != "main":
112                         continue; # Ick2
113                     override_type = ".debian-installer";
114                 elif type == "dsc":
115                     override_type = ".src";
116                 filename = "%s/override.%s.%s%s" % (Cnf["Dir::OverrideDir"], override_suite, string.replace(component, "non-US/", ""), override_type);
117                 file = utils.open_file(filename, 'w');
118                 sys.stdout = file;
119                 list(suite, component, type);
120                 sys.stdout.close();
121
122     # Munge the override file for testing by using unstable's where
123     # possible and falling back on stable's where it's not.
124
125     sys.stderr.write("Processing testing...\n");
126     suite = "testing";
127     suite_id = db_access.get_suite_id(suite);
128     override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
129     for component in Cnf.SubTree("Component").List():
130         if component == "mixed":
131             continue;
132         component_id = db_access.get_component_id(component);
133         for type in Cnf.SubTree("OverrideType").List():
134             if type == "deb":
135                 override_type = "";
136                 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));
137             elif type == "dsc":
138                 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));
139                 override_type = ".src";
140             elif type == "udeb":
141                 continue;
142             filename = "override.%s.%s%s" % (override_suite, string.replace(component, "non-US/", ""), override_type);
143             file = utils.open_file(filename, 'w');
144             sys.stdout = file;
145             for i in q.getresult():
146                 package = i[0];
147                 if override["unstable"][component][type].has_key(package):
148                     print result_join(override["unstable"][component][type][package]);
149                 elif override["stable"][component][type].has_key(package):
150                     print result_join(override["stable"][component][type][package]);
151                 else:
152                     if type == "dsc" and (override["unstable"][component]["deb"].has_key(package) or override["stable"][component]["deb"].has_key(package)):
153                         continue; # source falls back on binary; so accept silently
154                     utils.warn("Can't find override entry for testing package '%s' (component %s, type %s)." % (package, component, type));
155             sys.stdout.close();
156
157 #######################################################################################
158
159 if __name__ == '__main__':
160     main()
161