Coverage for dak/make_overrides.py: 93%
53 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
1"""
2Output override files for apt-ftparchive and indices/
3@contact: Debian FTP Master <ftpmaster@debian.org>
4@copyright: 2000, 2001, 2002, 2004, 2006 James Troup <james@nocrew.org>
5@license: GNU General Public License version 2 or later
6"""
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22################################################################################
24# This is separate because it's horribly Debian specific and I don't
25# want that kind of horribleness in the otherwise generic 'dak
26# make-overrides'. It does duplicate code tho.
28################################################################################
30import os
31import sys
32from typing import TextIO
34import apt_pkg
35from sqlalchemy import select, sql
37from daklib import utils
38from daklib.config import Config
39from daklib.dbconn import Component, DBConn, OverrideType, Suite
41################################################################################
44def usage(exit_code=0):
45 print(
46 """Usage: dak make-overrides
47Outputs the override tables to text files.
49 -h, --help show this help and exit."""
50 )
51 sys.exit(exit_code)
54################################################################################
57def do_list(
58 output_file: TextIO,
59 suite: Suite,
60 component: Component,
61 otype: OverrideType,
62 session,
63):
64 """
65 Fetch override data for suite from the database and dump it.
67 :param output_file: where to write the overrides to
68 :param suite: A suite object describing the Suite
69 :param component: The name of the component
70 :param otype: object of type of override. deb/udeb/dsc
71 :param session: the database session in use
72 """
73 # Here's a nice example of why the object API isn't always the
74 # right answer. On my laptop, the object version of the code
75 # takes 1:45, the 'dumb' tuple-based one takes 0:16 - mhy
77 if otype.overridetype == "dsc":
78 q = session.execute(
79 sql.text(
80 "SELECT o.package, s.section, o.maintainer FROM override o, section s WHERE o.suite = :suite AND o.component = :component AND o.type = :otype AND o.section = s.id ORDER BY s.section, o.package"
81 ),
82 {
83 "suite": suite.suite_id,
84 "component": component.component_id,
85 "otype": otype.overridetype_id,
86 },
87 )
88 output_file.writelines(utils.result_join(i) + "\n" for i in q.fetchall())
90 else:
91 q = session.execute(
92 sql.text(
93 "SELECT o.package, p.priority, s.section, o.maintainer FROM override o, priority p, section s WHERE o.suite = :suite AND o.component = :component AND o.type = :otype AND o.priority = p.id AND o.section = s.id ORDER BY s.section, p.level, o.package"
94 ),
95 {
96 "suite": suite.suite_id,
97 "component": component.component_id,
98 "otype": otype.overridetype_id,
99 },
100 )
101 output_file.writelines(utils.result_join(i) + "\n" for i in q.fetchall())
104################################################################################
107def main():
108 cnf = Config()
109 Arguments = [("h", "help", "Make-Overrides::Options::Help")]
110 for i in ["help"]:
111 key = "Make-Overrides::Options::%s" % i
112 if key not in cnf: 112 ↛ 110line 112 didn't jump to line 110 because the condition on line 112 was always true
113 cnf[key] = ""
114 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined]
115 Options = cnf.subtree("Make-Overrides::Options")
116 if Options["Help"]:
117 usage()
119 d = DBConn()
120 session = d.session()
122 for suite in session.scalars(select(Suite).where(Suite.overrideprocess)):
123 if suite.untouchable: 123 ↛ 124line 123 didn't jump to line 124 because the condition on line 123 was never true
124 print("Skipping %s as it is marked as untouchable" % suite.suite_name)
125 continue
127 print("Processing %s..." % (suite.suite_name), file=sys.stderr)
128 override_suite = suite.overridecodename or suite.codename
130 for component in session.scalars(select(Component)).all():
131 for otype in session.scalars(select(OverrideType)).all():
132 otype_name = otype.overridetype
133 cname = component.component_name
135 # TODO: Stick suffix info in database (or get rid of it)
136 if otype_name == "deb":
137 suffix = ""
138 elif otype_name == "udeb":
139 if cname == "contrib":
140 continue # Ick2
141 suffix = ".debian-installer"
142 elif otype_name == "dsc": 142 ↛ 145line 142 didn't jump to line 145 because the condition on line 142 was always true
143 suffix = ".src"
144 else:
145 utils.fubar("Don't understand OverrideType %s" % otype.overridetype)
147 cname = cname.replace("/", "_")
148 filename = os.path.join(
149 cnf["Dir::Override"],
150 "override.%s.%s%s" % (override_suite, cname, suffix),
151 )
153 with open(filename, "w") as output_file:
154 do_list(output_file, suite, component, otype, session)