Coverage for dak/contents.py: 94%
55 statements
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
« prev ^ index » next coverage.py v7.6.0, created at 2026-08-03 16:46 +0000
1"""
2Create all the contents files
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"""
11################################################################################
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.
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.
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
27################################################################################
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.
33# <Ganneff> of course that wont help for now where we need to generate them :)
35################################################################################
37import sys
39import apt_pkg
41from daklib import daklog, utils
42from daklib.config import Config
43from daklib.contents import BinaryContentsScanner, ContentsWriter, SourceContentsScanner
45################################################################################
48def usage(exit_code=0):
49 print(
50 """Usage: dak contents [options] subcommand
52SUBCOMMANDS
53 generate
54 generate Contents-$arch.gz files
56 scan-source
57 scan the source packages in the existing pool and load contents into
58 the src_contents table
60 scan-binary
61 scan the (u)debs in the existing pool and load contents into the
62 bin_contents table
64OPTIONS
65 -h, --help
66 show this help and exit
68OPTIONS for generate
69 -a, --archive=ARCHIVE
70 only operate on suites in the specified archive
72 -s, --suite={stable,testing,unstable,...}
73 only operate on specified suite names
75 -c, --component={main,contrib,non-free}
76 only operate on specified components
78 -f, --force
79 write Contents files for suites marked as untouchable, too
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)
89################################################################################
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()
98################################################################################
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()
110################################################################################
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()
122################################################################################
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")
143 if (len(args) != 1) or options["Help"]:
144 usage()
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"])
150 if args[0] == "scan-source":
151 source_scan_all(cnf, limit)
152 return
154 if args[0] == "scan-binary":
155 binary_scan_all(cnf, limit)
156 return
158 archive_names = utils.split_args(options["Archive"])
159 suite_names = utils.split_args(options["Suite"])
160 component_names = utils.split_args(options["Component"])
162 force = bool(options["Force"])
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
168 usage()