]> git.decadent.org.uk Git - dak.git/blob - denise
Add usage() and use it.
[dak.git] / denise
1 #!/usr/bin/env python
2
3 # Output override files for apt-ftparchive and indices/
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: denise,v 1.15 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 # 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.
26
27 ################################################################################
28
29 import pg, sys;
30 import utils, db_access;
31 import apt_pkg;
32
33 ################################################################################
34
35 Cnf = None;
36 projectB = None;
37 override = {}
38
39 ################################################################################
40
41 def usage(exit_code=0):
42     print """Usage: denise
43 Outputs the override tables to text files.
44
45   -h, --help                show this help and exit."""
46     sys.exit(exit_code)
47
48 ################################################################################
49
50 def list(file, suite, component, type):
51     global override;
52
53     suite_id = db_access.get_suite_id(suite);
54     if suite_id == -1:
55         utils.fubar("Suite '%s' not recognised." % (suite));
56
57     component_id = db_access.get_component_id(component);
58     if component_id == -1:
59         utils.fubar("Component '%s' not recognised." % (component));
60
61     type_id = db_access.get_override_type_id(type);
62     if type_id == -1:
63         utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (type));
64
65     if not override.has_key(suite):
66         override[suite] = {};
67     if not override[suite].has_key(component):
68         override[suite][component] = {};
69     if not override[suite][component].has_key(type):
70         override[suite][component][type] = {};
71
72     if type == "dsc":
73         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));
74         for i in q.getresult():
75             override[suite][component][type][i[0]] = i;
76             file.write(utils.result_join(i)+'\n');
77     else:
78         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));
79         for i in q.getresult():
80             i = i[:-1]; # Strip the priority level
81             override[suite][component][type][i[0]] = i;
82             file.write(utils.result_join(i)+'\n');
83
84 ################################################################################
85
86 def main ():
87     global Cnf, projectB, override;
88
89     Cnf = utils.get_conf()
90     Arguments = [('h',"help","Denise::Options::Help")];
91     for i in [ "help" ]:
92         if not Cnf.has_key("Denise::Options::%s" % (i)):
93             Cnf["Denise::Options::%s" % (i)] = "";
94     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
95     Options = Cnf.SubTree("Denise::Options")
96     if Options["Help"]:
97         usage();
98
99     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
100     db_access.init(Cnf, projectB);
101
102     for suite in [ "stable", "unstable" ]:
103         sys.stderr.write("Processing %s...\n" % (suite));
104         override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)];
105         for component in Cnf.SubTree("Component").List():
106             if component == "mixed":
107                 continue; # Ick
108             for type in Cnf.ValueList("OverrideType"):
109                 if type == "deb":
110                     override_type = "";
111                 elif type == "udeb":
112                     if suite != "unstable" or component != "main":
113                         continue; # Ick2
114                     override_type = ".debian-installer";
115                 elif type == "dsc":
116                     override_type = ".src";
117                 filename = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), override_type);
118                 file = utils.open_file(filename, 'w');
119                 list(file, suite, component, type);
120                 file.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.ValueList("OverrideType"):
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 = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), override_type);
143             file = utils.open_file(filename, 'w');
144             for i in q.getresult():
145                 package = i[0];
146                 if override["unstable"][component][type].has_key(package):
147                     file.write(utils.result_join(override["unstable"][component][type][package])+'\n');
148                 elif override["stable"][component][type].has_key(package):
149                     file.write(utils.result_join(override["stable"][component][type][package])+'\n');
150                 else:
151                     if type == "dsc" and (override["unstable"][component]["deb"].has_key(package) or override["stable"][component]["deb"].has_key(package)):
152                         continue; # source falls back on binary; so accept silently
153                     utils.warn("Can't find override entry for testing package '%s' (component %s, type %s)." % (package, component, type));
154             file.close();
155
156 #######################################################################################
157
158 if __name__ == '__main__':
159     main()
160