1
2 """
3 Create 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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 import sys
39
40 import apt_pkg
41
42 from daklib import daklog, utils
43 from daklib.config import Config
44 from daklib.contents import BinaryContentsScanner, ContentsWriter, SourceContentsScanner
45
46
47
48
50 print(
51 """Usage: dak contents [options] subcommand
52
53 SUBCOMMANDS
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
65 OPTIONS
66 -h, --help
67 show this help and exit
68
69 OPTIONS 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
82 OPTIONS 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
93 -def write_all(cnf, archive_names=[], suite_names=[], component_names=[], force=None):
97
98
99
100
101
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
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
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:
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":
166 write_all(cnf, archive_names, suite_names, component_names, force)
167 return
168
169 usage()
170
171
172 if __name__ == "__main__":
173 main()
174