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