1#! /usr/bin/env python3 

2""" 

3Create all the contents files 

4 

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

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

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

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

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

10""" 

11 

12################################################################################ 

13 

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

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

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

17# (at your option) any later version. 

18 

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

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

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

22# GNU General Public License for more details. 

23 

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

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

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

27 

28################################################################################ 

29 

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

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

32# <Ganneff> having more info. 

33 

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

35 

36################################################################################ 

37 

38import sys 

39 

40import apt_pkg 

41 

42from daklib import daklog, utils 

43from daklib.config import Config 

44from daklib.contents import BinaryContentsScanner, ContentsWriter, SourceContentsScanner 

45 

46################################################################################ 

47 

48 

49def usage(exit_code=0): 

50 print( 

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

52 

53SUBCOMMANDS 

54 generate 

55 generate Contents-$arch.gz files 

56 

57 scan-source 

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

59 the src_contents table 

60 

61 scan-binary 

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

63 bin_contents table 

64 

65OPTIONS 

66 -h, --help 

67 show this help and exit 

68 

69OPTIONS for generate 

70 -a, --archive=ARCHIVE 

71 only operate on suites in the specified archive 

72 

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

74 only operate on specified suite names 

75 

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

77 only operate on specified components 

78 

79 -f, --force 

80 write Contents files for suites marked as untouchable, too 

81 

82OPTIONS for scan-source and scan-binary 

83 -l, --limit=NUMBER 

84 maximum number of packages to scan 

85""" 

86 ) 

87 sys.exit(exit_code) 

88 

89 

90################################################################################ 

91 

92 

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

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

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

96 Logger.close() 

97 

98 

99################################################################################ 

100 

101 

102def binary_scan_all(cnf, limit): 

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

104 result = BinaryContentsScanner.scan_all(limit) 

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

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

107 Logger.log([processed, remaining]) 

108 Logger.close() 

109 

110 

111################################################################################ 

112 

113 

114def source_scan_all(cnf, limit): 

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

116 result = SourceContentsScanner.scan_all(limit) 

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

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

119 Logger.log([processed, remaining]) 

120 Logger.close() 

121 

122 

123################################################################################ 

124 

125 

126def main(): 

127 cnf = Config() 

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

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

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

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

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

133 arguments = [ 

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

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

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

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

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

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

140 ] 

141 args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv) 

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

143 

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

145 usage() 

146 

147 limit = None 

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

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

150 

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

152 source_scan_all(cnf, limit) 

153 return 

154 

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

156 binary_scan_all(cnf, limit) 

157 return 

158 

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

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

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

162 

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

164 

165 if args[0] == "generate": 165 ↛ 169line 165 didn't jump to line 169, because the condition on line 165 was never false

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

167 return 

168 

169 usage() 

170 

171 

172if __name__ == "__main__": 

173 main()