Coverage for dak/contents.py: 94%

55 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2026-08-03 16:46 +0000

1""" 

2Create all the contents files 

3 

4@contact: Debian FTPMaster <ftpmaster@debian.org> 

5@copyright: 2008, 2009 Michael Casadevall <mcasadevall@debian.org> 

6@copyright: 2009 Mike O'Connor <stew@debian.org> 

7@copyright: 2011 Torsten Werner <twerner@debian.org> 

8@license: GNU General Public License version 2 or later 

9""" 

10 

11################################################################################ 

12 

13# This program is free software; you can redistribute it and/or modify 

14# it under the terms of the GNU General Public License as published by 

15# the Free Software Foundation; either version 2 of the License, or 

16# (at your option) any later version. 

17 

18# This program is distributed in the hope that it will be useful, 

19# but WITHOUT ANY WARRANTY; without even the implied warranty of 

20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

21# GNU General Public License for more details. 

22 

23# You should have received a copy of the GNU General Public License 

24# along with this program; if not, write to the Free Software 

25# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

26 

27################################################################################ 

28 

29# <Ganneff> there is the idea to slowly replace contents files 

30# <Ganneff> with a new generation of such files. 

31# <Ganneff> having more info. 

32 

33# <Ganneff> of course that wont help for now where we need to generate them :) 

34 

35################################################################################ 

36 

37import sys 

38 

39import apt_pkg 

40 

41from daklib import daklog, utils 

42from daklib.config import Config 

43from daklib.contents import BinaryContentsScanner, ContentsWriter, SourceContentsScanner 

44 

45################################################################################ 

46 

47 

48def usage(exit_code=0): 

49 print( 

50 """Usage: dak contents [options] subcommand 

51 

52SUBCOMMANDS 

53 generate 

54 generate Contents-$arch.gz files 

55 

56 scan-source 

57 scan the source packages in the existing pool and load contents into 

58 the src_contents table 

59 

60 scan-binary 

61 scan the (u)debs in the existing pool and load contents into the 

62 bin_contents table 

63 

64OPTIONS 

65 -h, --help 

66 show this help and exit 

67 

68OPTIONS for generate 

69 -a, --archive=ARCHIVE 

70 only operate on suites in the specified archive 

71 

72 -s, --suite={stable,testing,unstable,...} 

73 only operate on specified suite names 

74 

75 -c, --component={main,contrib,non-free} 

76 only operate on specified components 

77 

78 -f, --force 

79 write Contents files for suites marked as untouchable, too 

80 

81OPTIONS for scan-source and scan-binary 

82 -l, --limit=NUMBER 

83 maximum number of packages to scan 

84""" 

85 ) 

86 sys.exit(exit_code) 

87 

88 

89################################################################################ 

90 

91 

92def write_all(cnf, archive_names=[], suite_names=[], component_names=[], force=None): 

93 Logger = daklog.Logger("contents generate") 

94 ContentsWriter.write_all(Logger, archive_names, suite_names, component_names, force) 

95 Logger.close() 

96 

97 

98################################################################################ 

99 

100 

101def binary_scan_all(cnf, limit): 

102 Logger = daklog.Logger("contents scan-binary") 

103 result = BinaryContentsScanner.scan_all(limit) 

104 processed = "%(processed)d packages processed" % result 

105 remaining = "%(remaining)d packages remaining" % result 

106 Logger.log([processed, remaining]) 

107 Logger.close() 

108 

109 

110################################################################################ 

111 

112 

113def source_scan_all(cnf, limit): 

114 Logger = daklog.Logger("contents scan-source") 

115 result = SourceContentsScanner.scan_all(limit) 

116 processed = "%(processed)d packages processed" % result 

117 remaining = "%(remaining)d packages remaining" % result 

118 Logger.log([processed, remaining]) 

119 Logger.close() 

120 

121 

122################################################################################ 

123 

124 

125def main(): 

126 cnf = Config() 

127 cnf["Contents::Options::Help"] = "" 

128 cnf["Contents::Options::Suite"] = "" 

129 cnf["Contents::Options::Component"] = "" 

130 cnf["Contents::Options::Limit"] = "" 

131 cnf["Contents::Options::Force"] = "" 

132 arguments = [ 

133 ("h", "help", "Contents::Options::Help"), 

134 ("a", "archive", "Contents::Options::Archive", "HasArg"), 

135 ("s", "suite", "Contents::Options::Suite", "HasArg"), 

136 ("c", "component", "Contents::Options::Component", "HasArg"), 

137 ("l", "limit", "Contents::Options::Limit", "HasArg"), 

138 ("f", "force", "Contents::Options::Force"), 

139 ] 

140 args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) # type: ignore[attr-defined] 

141 options = cnf.subtree("Contents::Options") 

142 

143 if (len(args) != 1) or options["Help"]: 

144 usage() 

145 

146 limit = None 

147 if len(options["Limit"]) > 0: 147 ↛ 148line 147 didn't jump to line 148 because the condition on line 147 was never true

148 limit = int(options["Limit"]) 

149 

150 if args[0] == "scan-source": 

151 source_scan_all(cnf, limit) 

152 return 

153 

154 if args[0] == "scan-binary": 

155 binary_scan_all(cnf, limit) 

156 return 

157 

158 archive_names = utils.split_args(options["Archive"]) 

159 suite_names = utils.split_args(options["Suite"]) 

160 component_names = utils.split_args(options["Component"]) 

161 

162 force = bool(options["Force"]) 

163 

164 if args[0] == "generate": 164 ↛ 168line 164 didn't jump to line 168 because the condition on line 164 was always true

165 write_all(cnf, archive_names, suite_names, component_names, force) 

166 return 

167 

168 usage()