Coverage for dak/make_overrides.py: 93%

55 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-01-04 16:18 +0000

1#! /usr/bin/env python3 

2 

3""" 

4Output 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 separate 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 

32import os 

33import sys 

34from typing import TextIO 

35 

36import apt_pkg 

37from sqlalchemy import sql 

38 

39from daklib import utils 

40from daklib.config import Config 

41from daklib.dbconn import Component, DBConn, OverrideType, Suite 

42 

43################################################################################ 

44 

45 

46def usage(exit_code=0): 

47 print( 

48 """Usage: dak make-overrides 

49Outputs the override tables to text files. 

50 

51 -h, --help show this help and exit.""" 

52 ) 

53 sys.exit(exit_code) 

54 

55 

56################################################################################ 

57 

58 

59def do_list( 

60 output_file: TextIO, 

61 suite: Suite, 

62 component: Component, 

63 otype: OverrideType, 

64 session, 

65): 

66 """ 

67 Fetch override data for suite from the database and dump it. 

68 

69 :param output_file: where to write the overrides to 

70 :param suite: A suite object describing the Suite 

71 :param component: The name of the component 

72 :param otype: object of type of override. deb/udeb/dsc 

73 :param session: the database session in use 

74 """ 

75 # Here's a nice example of why the object API isn't always the 

76 # right answer. On my laptop, the object version of the code 

77 # takes 1:45, the 'dumb' tuple-based one takes 0:16 - mhy 

78 

79 if otype.overridetype == "dsc": 

80 q = session.execute( 

81 sql.text( 

82 "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" 

83 ), 

84 { 

85 "suite": suite.suite_id, 

86 "component": component.component_id, 

87 "otype": otype.overridetype_id, 

88 }, 

89 ) 

90 for i in q.fetchall(): 

91 output_file.write(utils.result_join(i) + "\n") 

92 

93 else: 

94 q = session.execute( 

95 sql.text( 

96 "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" 

97 ), 

98 { 

99 "suite": suite.suite_id, 

100 "component": component.component_id, 

101 "otype": otype.overridetype_id, 

102 }, 

103 ) 

104 for i in q.fetchall(): 

105 output_file.write(utils.result_join(i) + "\n") 

106 

107 

108################################################################################ 

109 

110 

111def main(): 

112 cnf = Config() 

113 Arguments = [("h", "help", "Make-Overrides::Options::Help")] 

114 for i in ["help"]: 

115 key = "Make-Overrides::Options::%s" % i 

116 if key not in cnf: 116 ↛ 114line 116 didn't jump to line 114 because the condition on line 116 was always true

117 cnf[key] = "" 

118 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) # type: ignore[attr-defined] 

119 Options = cnf.subtree("Make-Overrides::Options") 

120 if Options["Help"]: 

121 usage() 

122 

123 d = DBConn() 

124 session = d.session() 

125 

126 for suite in session.query(Suite).filter( 

127 Suite.overrideprocess == True # noqa:E712 

128 ): 

129 if suite.untouchable: 129 ↛ 130line 129 didn't jump to line 130 because the condition on line 129 was never true

130 print("Skipping %s as it is marked as untouchable" % suite.suite_name) 

131 continue 

132 

133 print("Processing %s..." % (suite.suite_name), file=sys.stderr) 

134 override_suite = suite.overridecodename or suite.codename 

135 

136 for component in session.query(Component).all(): 

137 for otype in session.query(OverrideType).all(): 

138 otype_name = otype.overridetype 

139 cname = component.component_name 

140 

141 # TODO: Stick suffix info in database (or get rid of it) 

142 if otype_name == "deb": 

143 suffix = "" 

144 elif otype_name == "udeb": 

145 if cname == "contrib": 

146 continue # Ick2 

147 suffix = ".debian-installer" 

148 elif otype_name == "dsc": 148 ↛ 151line 148 didn't jump to line 151 because the condition on line 148 was always true

149 suffix = ".src" 

150 else: 

151 utils.fubar("Don't understand OverrideType %s" % otype.overridetype) 

152 

153 cname = cname.replace("/", "_") 

154 filename = os.path.join( 

155 cnf["Dir::Override"], 

156 "override.%s.%s%s" % (override_suite, cname, suffix), 

157 ) 

158 

159 with open(filename, "w") as output_file: 

160 do_list(output_file, suite, component, otype, session) 

161 

162 

163################################################################################ 

164 

165 

166if __name__ == "__main__": 

167 main()