]> git.decadent.org.uk Git - dak.git/blob - dak/make_overrides.py
Enmasse adaptation for removal of silly names.
[dak.git] / dak / make_overrides.py
1 #!/usr/bin/env python
2
3 # Output override files for apt-ftparchive and indices/
4 # Copyright (C) 2000, 2001, 2002, 2004, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20 ################################################################################
21
22 # This is seperate because it's horribly Debian specific and I don't
23 # want that kind of horribleness in the otherwise generic 'dak
24 # make-overrides'.  It does duplicate code tho.
25
26 ################################################################################
27
28 import pg, sys
29 import dak.lib.utils, dak.lib.database
30 import apt_pkg
31
32 ################################################################################
33
34 Cnf = None
35 projectB = None
36 override = {}
37
38 ################################################################################
39
40 def usage(exit_code=0):
41     print """Usage: dak make-overrides
42 Outputs the override tables to text files.
43
44   -h, --help                show this help and exit."""
45     sys.exit(exit_code)
46
47 ################################################################################
48
49 def do_list(output_file, suite, component, otype):
50     global override
51
52     suite_id = dak.lib.database.get_suite_id(suite)
53     if suite_id == -1:
54         dak.lib.utils.fubar("Suite '%s' not recognised." % (suite))
55
56     component_id = dak.lib.database.get_component_id(component)
57     if component_id == -1:
58         dak.lib.utils.fubar("Component '%s' not recognised." % (component))
59
60     otype_id = dak.lib.database.get_override_type_id(otype)
61     if otype_id == -1:
62         dak.lib.utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (otype))
63
64     override.setdefault(suite, {})
65     override[suite].setdefault(component, {})
66     override[suite][component].setdefault(otype, {})
67
68     if otype == "dsc":
69         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))
70         for i in q.getresult():
71             override[suite][component][otype][i[0]] = i
72             output_file.write(dak.lib.utils.result_join(i)+'\n')
73     else:
74         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))
75         for i in q.getresult():
76             i = i[:-1]; # Strip the priority level
77             override[suite][component][otype][i[0]] = i
78             output_file.write(dak.lib.utils.result_join(i)+'\n')
79
80 ################################################################################
81
82 def main ():
83     global Cnf, projectB, override
84
85     Cnf = dak.lib.utils.get_conf()
86     Arguments = [('h',"help","Make-Overrides::Options::Help")]
87     for i in [ "help" ]:
88         if not Cnf.has_key("Make-Overrides::Options::%s" % (i)):
89             Cnf["Make-Overrides::Options::%s" % (i)] = ""
90     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
91     Options = Cnf.SubTree("Make-Overrides::Options")
92     if Options["Help"]:
93         usage()
94
95     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
96     dak.lib.database.init(Cnf, projectB)
97
98     for suite in Cnf.SubTree("Check-Overrides::OverrideSuites").List():
99         if Cnf.has_key("Suite::%s::Untouchable" % suite) and Cnf["Suite::%s::Untouchable" % suite] != 0:
100             continue
101         suite = suite.lower()
102
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 otype in Cnf.ValueList("OverrideType"):
109                 if otype == "deb":
110                     suffix = ""
111                 elif otype == "udeb":
112                     if component != "main":
113                         continue; # Ick2
114                     suffix = ".debian-installer"
115                 elif otype == "dsc":
116                     suffix = ".src"
117                 filename = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), suffix)
118                 output_file = dak.lib.utils.open_file(filename, 'w')
119                 do_list(output_file, suite, component, otype)
120                 output_file.close()
121
122 ################################################################################
123
124 if __name__ == '__main__':
125     main()