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 

34import apt_pkg 

35from typing import TextIO 

36 

37from daklib.dbconn import * 

38from daklib.config import Config 

39from daklib import utils 

40 

41################################################################################ 

42 

43 

44def usage(exit_code=0): 

45 print("""Usage: dak make-overrides 

46Outputs the override tables to text files. 

47 

48 -h, --help show this help and exit.""") 

49 sys.exit(exit_code) 

50 

51################################################################################ 

52 

53 

54def do_list(output_file: TextIO, suite: Suite, component: Component, otype: OverrideType, session): 

55 """ 

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

57 

58 :param output_file: where to write the overrides to 

59 :param suite: A suite object describing the Suite 

60 :param component: The name of the component 

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

62 :param session: the database session in use 

63 """ 

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

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

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

67 

68 if otype.overridetype == "dsc": 

69 q = session.execute("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", 

70 {'suite': suite.suite_id, 'component': component.component_id, 'otype': otype.overridetype_id}) 

71 for i in q.fetchall(): 

72 output_file.write(utils.result_join(i) + '\n') 

73 

74 else: 

75 q = session.execute("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", 

76 {'suite': suite.suite_id, 'component': component.component_id, 'otype': otype.overridetype_id}) 

77 for i in q.fetchall(): 

78 output_file.write(utils.result_join(i) + '\n') 

79 

80################################################################################ 

81 

82 

83def main(): 

84 cnf = Config() 

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

86 for i in ["help"]: 

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

88 if key not in cnf: 88 ↛ 86line 88 didn't jump to line 86, because the condition on line 88 was never false

89 cnf[key] = "" 

90 apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv) 

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

92 if Options["Help"]: 

93 usage() 

94 

95 d = DBConn() 

96 session = d.session() 

97 

98 for suite in session.query(Suite).filter(Suite.overrideprocess == True): # noqa:E712 

99 if suite.untouchable: 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true

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

101 continue 

102 

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

104 override_suite = suite.overridecodename or suite.codename 

105 

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

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

108 otype_name = otype.overridetype 

109 cname = component.component_name 

110 

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

112 if otype_name == "deb": 

113 suffix = "" 

114 elif otype_name == "udeb": 

115 if cname == "contrib": 

116 continue # Ick2 

117 suffix = ".debian-installer" 

118 elif otype_name == "dsc": 118 ↛ 121line 118 didn't jump to line 121, because the condition on line 118 was never false

119 suffix = ".src" 

120 else: 

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

122 

123 cname = cname.replace('/', '_') 

124 filename = os.path.join(cnf["Dir::Override"], "override.%s.%s%s" % (override_suite, cname, suffix)) 

125 

126 with open(filename, 'w') as output_file: 

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

128 

129################################################################################ 

130 

131 

132if __name__ == '__main__': 

133 main()