]> git.decadent.org.uk Git - dak.git/blob - dak/make_overrides.py
commit updates from live dak tree on ftp-master
[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 apt_pkg
30 import daklib.database
31 import daklib.utils
32
33 ################################################################################
34
35 Cnf = None
36 projectB = None
37 override = {}
38
39 ################################################################################
40
41 def usage(exit_code=0):
42     print """Usage: dak make-overrides
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 do_list(output_file, suite, component, otype):
51     global override
52
53     suite_id = daklib.database.get_suite_id(suite)
54     if suite_id == -1:
55         daklib.utils.fubar("Suite '%s' not recognised." % (suite))
56
57     component_id = daklib.database.get_component_id(component)
58     if component_id == -1:
59         daklib.utils.fubar("Component '%s' not recognised." % (component))
60
61     otype_id = daklib.database.get_override_type_id(otype)
62     if otype_id == -1:
63         daklib.utils.fubar("Type '%s' not recognised. (Valid types are deb, udeb and dsc)" % (otype))
64
65     override.setdefault(suite, {})
66     override[suite].setdefault(component, {})
67     override[suite][component].setdefault(otype, {})
68
69     if otype == "dsc":
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(daklib.utils.result_join(i)+'\n')
74     else:
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(daklib.utils.result_join(i)+'\n')
80
81 ################################################################################
82
83 def main ():
84     global Cnf, projectB, override
85
86     Cnf = daklib.utils.get_conf()
87     Arguments = [('h',"help","Make-Overrides::Options::Help")]
88     for i in [ "help" ]:
89         if not Cnf.has_key("Make-Overrides::Options::%s" % (i)):
90             Cnf["Make-Overrides::Options::%s" % (i)] = ""
91     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
92     Options = Cnf.SubTree("Make-Overrides::Options")
93     if Options["Help"]:
94         usage()
95
96     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
97     daklib.database.init(Cnf, projectB)
98
99     for suite in Cnf.SubTree("Check-Overrides::OverrideSuites").List():
100         if Cnf.has_key("Suite::%s::Untouchable" % suite) and Cnf["Suite::%s::Untouchable" % suite] != 0:
101             continue
102         suite = suite.lower()
103
104         sys.stderr.write("Processing %s...\n" % (suite))
105         override_suite = Cnf["Suite::%s::OverrideCodeName" % (suite)]
106         for component in Cnf.SubTree("Component").List():
107             if component == "mixed":
108                 continue; # Ick
109             for otype in Cnf.ValueList("OverrideType"):
110                 if otype == "deb":
111                     suffix = ""
112                 elif otype == "udeb":
113                     if component == "contrib":
114                         continue; # Ick2
115                     suffix = ".debian-installer"
116                 elif otype == "dsc":
117                     suffix = ".src"
118                 filename = "%s/override.%s.%s%s" % (Cnf["Dir::Override"], override_suite, component.replace("non-US/", ""), suffix)
119                 output_file = daklib.utils.open_file(filename, 'w')
120                 do_list(output_file, suite, component, otype)
121                 output_file.close()
122
123 ################################################################################
124
125 if __name__ == '__main__':
126     main()