]> git.decadent.org.uk Git - dak.git/blob - dak/make_overrides.py
b925d927c294108d3998bb7abcc9703abb307587
[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 os
33 import sys
34 import apt_pkg
35
36 from daklib.dbconn import *
37 from daklib.config import Config
38 from daklib import utils
39
40 ################################################################################
41
42 def usage(exit_code=0):
43     print """Usage: dak make-overrides
44 Outputs the override tables to text files.
45
46   -h, --help                show this help and exit."""
47     sys.exit(exit_code)
48
49 ################################################################################
50
51 def do_list(output_file, suite, component, otype, session):
52     """
53     Fetch override data for suite from the database and dump it.
54
55     @type output_file: fileobject
56     @param output_file: where to write the overrides to
57
58     @type suite: Suite object
59     @param suite: A suite object describing the Suite
60
61     @type component: Component object
62     @param component: The name of the component
63
64     @type otype: OverrideType object
65     @param otype: object of type of override. deb/udeb/dsc
66
67     @type session: SQLA Session
68     @param session: the database session in use
69
70     """
71     # Here's a nice example of why the object API isn't always the
72     # right answer.  On my laptop, the object version of the code
73     # takes 1:45, the 'dumb' tuple-based one takes 0:16 - mhy
74
75     if otype.overridetype == "dsc":
76         #q = session.query(Override).filter_by(suite_id = suite.suite_id)
77         #q = q.filter_by(component_id = component.component_id)
78         #q = q.filter_by(overridetype_id = otype.overridetype_id)
79         #q = q.join(Section).order_by(Section.section, Override.package)
80         #for o in q.all():
81         #    dat = (o.package, o.section.section, o.maintainer)
82         #    output_file.write(utils.result_join(dat) + '\n')
83         q = session.execute("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.suite_id, component.component_id, otype.overridetype_id))
84         for i in q.fetchall():
85             output_file.write(utils.result_join(i) + '\n')
86
87     else:
88         #q = session.query(Override).filter_by(suite_id = suite.suite_id)
89         #q = q.filter_by(component_id = component.component_id)
90         #q = q.filter_by(overridetype_id = otype.overridetype_id)
91         #q = q.join(Priority).join(Section).order_by(Section.section, Priority.level, Override.package)
92         #for o in q.all():
93         #    dat = (o.package, o.priority.priority, o.section.section, o.maintainer)
94         #    output_file.write(utils.result_join(dat) + '\n')
95         q = session.execute("SELECT o.package, p.priority, s.section, o.maintainer 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.suite_id, component.component_id, otype.overridetype_id))
96         for i in q.fetchall():
97             output_file.write(utils.result_join(i) + '\n')
98
99 ################################################################################
100
101 def main ():
102     cnf = Config()
103     Arguments = [('h',"help","Make-Overrides::Options::Help")]
104     for i in [ "help" ]:
105         if not cnf.has_key("Make-Overrides::Options::%s" % (i)):
106             cnf["Make-Overrides::Options::%s" % (i)] = ""
107     apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
108     Options = cnf.SubTree("Make-Overrides::Options")
109     if Options["Help"]:
110         usage()
111
112     d = DBConn()
113     session = d.session()
114
115     for suite_name in cnf.SubTree("Check-Overrides::OverrideSuites").List():
116         suite = get_suite(suite_name.lower(), session)
117         if not suite:
118             utils.fubar('Suite %s not found' % suite_name)
119         if suite.untouchable:
120             continue
121
122         sys.stderr.write("Processing %s...\n" % (suite.suite_name))
123         override_suite = suite.overridecodename
124
125         for component_name in cnf.SubTree("Component").List():
126             component = get_component(component_name, session)
127             if not component:
128                 utils.fubar('Component %s not found' % component_name)
129
130             for otype_name in cnf.ValueList("OverrideType"):
131                 otype = get_override_type(otype_name, session)
132                 if not otype:
133                     utils.fubar('OverrideType %s not found' % otype_name)
134
135                 if otype_name == "deb":
136                     suffix = ""
137                 elif otype_name == "udeb":
138                     if component == "contrib":
139                         continue # Ick2
140                     suffix = ".debian-installer"
141                 elif otype_name == "dsc":
142                     suffix = ".src"
143
144                 cname = component.component_name.replace('/', '_')
145                 filename = os.path.join(cnf["Dir::Override"], "override.%s.%s%s" % (override_suite, cname, suffix))
146
147                 output_file = utils.open_file(filename, 'w')
148                 do_list(output_file, suite, component, otype, session)
149                 output_file.close()
150
151 ################################################################################
152
153 if __name__ == '__main__':
154     main()