3 # Output override files for apt-ftparchive and indices/
4 # Copyright (C) 2000, 2001, 2002, 2004 James Troup <james@nocrew.org>
5 # $Id: denise,v 1.17 2004-11-27 17:56:42 troup Exp $
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.
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.
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
21 ################################################################################
23 # This is seperate because it's horribly Debian specific and I don't
24 # want that kind of horribleness in the otherwise generic natalie. It
25 # does duplicate code tho.
27 ################################################################################
30 import utils, db_access;
33 ################################################################################
39 ################################################################################
41 def usage(exit_code=0):
42 print """Usage: denise
43 Outputs the override tables to text files.
45 -h, --help show this help and exit."""
48 ################################################################################
50 def do_list(output_file, suite, component, otype):
53 suite_id = db_access.get_suite_id(suite);
55 utils.fubar("Suite '%s' not recognised." % (suite));
57 component_id = db_access.get_component_id(component);
58 if component_id == -1:
59 utils.fubar("Component '%s' not recognised." % (component));
61 otype_id = db_access.get_override_type_id(otype);
63 utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (otype));
65 override.setdefault(suite, {});
66 override[suite].setdefault(component, {});
67 override[suite][component].setdefault(otype, {});
70 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, otype_id));
71 for i in q.getresult():
72 override[suite][component][otype][i[0]] = i;
73 output_file.write(utils.result_join(i)+'\n');
75 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, otype_id));
76 for i in q.getresult():
77 i = i[:-1]; # Strip the priority level
78 override[suite][component][otype][i[0]] = i;
79 output_file.write(utils.result_join(i)+'\n');
81 ################################################################################
84 global Cnf, projectB, override;
86 Cnf = utils.get_conf()
87 Arguments = [('h',"help","Denise::Options::Help")];
89 if not Cnf.has_key("Denise::Options::%s" % (i)):
90 Cnf["Denise::Options::%s" % (i)] = "";
91 apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
92 Options = Cnf.SubTree("Denise::Options")
96 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
97 db_access.init(Cnf, projectB);
99 for suite in [ "stable", "unstable" ]:
100 sys.stderr.write("Processing %s...\n" % (suite));
101 override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
102 for component in Cnf.SubTree("Component").List():
103 if component == "mixed":
105 for otype in Cnf.ValueList("OverrideType"):
108 elif otype == "udeb":
109 if suite != "unstable" or component != "main":
111 suffix = ".debian-installer";
114 filename = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), suffix);
115 output_file = utils.open_file(filename, 'w');
116 do_list(output_file, suite, component, otype);
119 # Munge the override file for testing by using unstable's where
120 # possible and falling back on stable's where it's not.
122 sys.stderr.write("Processing testing...\n");
124 suite_id = db_access.get_suite_id(suite);
125 override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
126 for component in Cnf.SubTree("Component").List():
127 if component == "mixed":
129 component_id = db_access.get_component_id(component);
130 for otype in Cnf.ValueList("OverrideType"):
131 if otype == "deb" or otype == "udeb":
134 elif otype == "udeb":
135 if component != "main":
137 suffix = ".debian-installer";
138 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 b.type = '%s' AND ba.bin = b.id AND b.file = f.id AND f.location = l.id" % (suite_id, component_id, otype));
140 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));
142 filename = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), suffix);
143 output_file = utils.open_file(filename, 'w');
144 for i in q.getresult():
146 if otype == "deb" or otype == "dsc":
147 if override["unstable"][component][otype].has_key(package):
148 output_file.write(utils.result_join(override["unstable"][component][otype][package])+'\n');
149 elif override["stable"][component][otype].has_key(package):
150 output_file.write(utils.result_join(override["stable"][component][otype][package])+'\n');
152 if otype == "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, otype));
155 elif otype == "udeb":
156 if component == "main" and override["unstable"][component][otype].has_key(package):
157 output_file.write(utils.result_join(override["unstable"][component][otype][package])+'\n');
159 utils.warn("Can't find override entry for testing package '%s' (component %s, type %s)." % (package, component, otype));
163 ################################################################################
165 if __name__ == '__main__':