3 """ Generate Packages/Sources files
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2000, 2001, 2002, 2006 James Troup <james@nocrew.org>
7 @copyright: 2009 Mark Hymers <mhy@debian.org>
8 @copyright: 2010 Joerg Jaspert <joerg@debian.org>
9 @license: GNU General Public License version 2 or later
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 ################################################################################
33 from tempfile import mkstemp, mkdtemp
35 from multiprocessing import Pool, TimeoutError
37 from daklib import daklog
38 from daklib.dbconn import *
39 from daklib.config import Config
41 ################################################################################
43 Options = None #: Commandline arguments parsed into this
44 Logger = None #: Our logging object
45 results = [] #: Results of the subprocesses
47 ################################################################################
49 def usage (exit_code=0):
50 print """Usage: dak generate-packages-sources [OPTIONS]
51 Generate the Packages/Sources files
53 -s, --suite=SUITE(s) process this suite
54 Default: All suites not marked 'untouchable'
55 -f, --force Allow processing of untouchable suites
56 CAREFUL: Only to be used at point release time!
57 -h, --help show this help and exit
59 SUITE can be a space seperated list, e.g.
60 --suite=unstable testing
65 ################################################################################
67 def generate_packages_sources(arch, suite, tmppath):
69 Generate Packages/Sources files with apt-ftparchive for the given suite/arch
72 @param suite: Suite name
75 @param arch: Architecture name
78 @param tmppath: The temporary path to work ing
84 ArchiveDir "/srv/ftp-master.debian.org/ftp/";
85 OverrideDir "/srv/ftp-master.debian.org/scripts/override/";
86 CacheDir "/srv/ftp-master.debian.org/database/";
91 Packages::Compress "bzip2 gzip";
92 Sources::Compress "bzip2 gzip";
93 Contents::Compress "gzip";
95 MaxContentsChange 25000;
101 Contents::Header "/srv/ftp-master.debian.org/dak/config/debian/Contents.top";
108 apt_trees["testing"]="""
111 FakeDI "dists/unstable";
112 FileList "/srv/ftp-master.debian.org/database/dists/testing_$(SECTION)_binary-$(ARCH).list";
113 SourceFileList "/srv/ftp-master.debian.org/database/dists/testing_$(SECTION)_source.list";
114 Sections "main contrib non-free";
115 Architectures "%(arch)s";
116 BinOverride "override.wheezy.$(SECTION)";
117 ExtraOverride "override.wheezy.extra.$(SECTION)";
118 SrcOverride "override.wheezy.$(SECTION).src";
122 apt_trees["squeeze-updates"]="""
123 tree "dists/squeeze-updates"
125 FileList "/srv/ftp-master.debian.org/database/dists/squeeze-updates_$(SECTION)_binary-$(ARCH).list";
126 SourceFileList "/srv/ftp-master.debian.org/database/dists/squeeze-updates_$(SECTION)_source.list";
127 Sections "main contrib non-free";
128 Architectures "%(arch)s";
129 BinOverride "override.squeeze.$(SECTION)";
130 ExtraOverride "override.squeeze.extra.$(SECTION)";
131 SrcOverride "override.squeeze.$(SECTION).src";
136 apt_trees["di"]["testing"]="""
137 tree "dists/testing/main"
139 FileList "/srv/ftp-master.debian.org/database/dists/testing_main_$(SECTION)_binary-$(ARCH).list";
140 Sections "debian-installer";
141 Architectures "%(arch)s";
142 BinOverride "override.wheezy.main.$(SECTION)";
143 SrcOverride "override.wheezy.main.src";
144 BinCacheDB "packages-debian-installer-$(ARCH).db";
145 Packages::Extensions ".udeb";
149 tree "dists/testing/non-free"
151 FileList "/srv/ftp-master.debian.org/database/dists/testing_non-free_$(SECTION)_binary-$(ARCH).list";
152 Sections "debian-installer";
153 Architectures "%(arch)s";
154 BinOverride "override.wheezy.main.$(SECTION)";
155 SrcOverride "override.wheezy.main.src";
156 BinCacheDB "packages-debian-installer-$(ARCH).db";
157 Packages::Extensions ".udeb";
162 apt_trees["unstable"]="""
163 tree "dists/unstable"
165 FileList "/srv/ftp-master.debian.org/database/dists/unstable_$(SECTION)_binary-$(ARCH).list";
166 SourceFileList "/srv/ftp-master.debian.org/database/dists/unstable_$(SECTION)_source.list";
167 Sections "main contrib non-free";
168 Architectures "%(arch)s";
169 BinOverride "override.sid.$(SECTION)";
170 ExtraOverride "override.sid.extra.$(SECTION)";
171 SrcOverride "override.sid.$(SECTION).src";
174 apt_trees["di"]["unstable"]="""
175 tree "dists/unstable/main"
177 FileList "/srv/ftp-master.debian.org/database/dists/unstable_main_$(SECTION)_binary-$(ARCH).list";
178 Sections "debian-installer";
179 Architectures "%(arch)s";
180 BinOverride "override.sid.main.$(SECTION)";
181 SrcOverride "override.sid.main.src";
182 BinCacheDB "packages-debian-installer-$(ARCH).db";
183 Packages::Extensions ".udeb";
187 tree "dists/unstable/non-free"
189 FileList "/srv/ftp-master.debian.org/database/dists/unstable_non-free_$(SECTION)_binary-$(ARCH).list";
190 Sections "debian-installer";
191 Architectures "%(arch)s";
192 BinOverride "override.sid.main.$(SECTION)";
193 SrcOverride "override.sid.main.src";
194 BinCacheDB "packages-debian-installer-$(ARCH).db";
195 Packages::Extensions ".udeb";
200 apt_trees["experimental"]="""
201 tree "dists/experimental"
203 FileList "/srv/ftp-master.debian.org/database/dists/experimental_$(SECTION)_binary-$(ARCH).list";
204 SourceFileList "/srv/ftp-master.debian.org/database/dists/experimental_$(SECTION)_source.list";
205 Sections "main contrib non-free";
206 Architectures "%(arch)s";
207 BinOverride "override.sid.$(SECTION)";
208 SrcOverride "override.sid.$(SECTION).src";
211 apt_trees["di"]["experimental"]="""
212 tree "dists/experimental/main"
214 FileList "/srv/ftp-master.debian.org/database/dists/experimental_main_$(SECTION)_binary-$(ARCH).list";
215 Sections "debian-installer";
216 Architectures "%(arch)s";
217 BinOverride "override.sid.main.$(SECTION)";
218 SrcOverride "override.sid.main.src";
219 BinCacheDB "packages-debian-installer-$(ARCH).db";
220 Packages::Extensions ".udeb";
224 tree "dists/experimental/non-free"
226 FileList "/srv/ftp-master.debian.org/database/dists/experimental_non-free_$(SECTION)_binary-$(ARCH).list";
227 Sections "debian-installer";
228 Architectures "%(arch)s";
229 BinOverride "override.sid.main.$(SECTION)";
230 SrcOverride "override.sid.main.src";
231 BinCacheDB "packages-debian-installer-$(ARCH).db";
232 Packages::Extensions ".udeb";
237 apt_trees["testing-proposed-updates"]="""
238 tree "dists/testing-proposed-updates"
240 FileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_$(SECTION)_binary-$(ARCH).list";
241 SourceFileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_$(SECTION)_source.list";
242 Sections "main contrib non-free";
243 Architectures "%(arch)s";
244 BinOverride "override.wheezy.$(SECTION)";
245 ExtraOverride "override.wheezy.extra.$(SECTION)";
246 SrcOverride "override.wheezy.$(SECTION).src";
250 apt_trees["di"]["testing-proposed-updates"]="""
251 tree "dists/testing-proposed-updates/main"
253 FileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_main_$(SECTION)_binary-$(ARCH).list";
254 Sections "debian-installer";
255 Architectures "%(arch)s";
256 BinOverride "override.wheezy.main.$(SECTION)";
257 SrcOverride "override.wheezy.main.src";
258 BinCacheDB "packages-debian-installer-$(ARCH).db";
259 Packages::Extensions ".udeb";
264 apt_trees["proposed-updates"]="""
265 tree "dists/proposed-updates"
267 FileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_$(SECTION)_binary-$(ARCH).list";
268 SourceFileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_$(SECTION)_source.list";
269 Sections "main contrib non-free";
270 Architectures "%(arch)s";
271 BinOverride "override.squeeze.$(SECTION)";
272 ExtraOverride "override.squeeze.extra.$(SECTION)";
273 SrcOverride "override.squeeze.$(SECTION).src";
277 apt_trees["di"]["proposed-updates"]="""
278 tree "dists/proposed-updates/main"
280 FileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_main_$(SECTION)_binary-$(ARCH).list";
281 Sections "debian-installer";
282 Architectures "%(arch)s";
283 BinOverride "override.squeeze.main.$(SECTION)";
284 SrcOverride "override.squeeze.main.src";
285 BinCacheDB "packages-debian-installer-$(ARCH).db";
286 Packages::Extensions ".udeb";
290 apt_trees["oldstable-proposed-updates"]="""
291 tree "dists/oldstable-proposed-updates"
293 FileList "/srv/ftp-master.debian.org/database/dists/oldstable-proposed-updates_$(SECTION)_binary-$(ARCH).list";
294 SourceFileList "/srv/ftp-master.debian.org/database/dists/oldstable-proposed-updates_$(SECTION)_source.list";
295 Sections "main contrib non-free";
296 Architectures "%(arch)s";
297 BinOverride "override.lenny.$(SECTION)";
298 ExtraOverride "override.lenny.extra.$(SECTION)";
299 SrcOverride "override.lenny.$(SECTION).src";
303 apt_trees["di"]["oldstable-proposed-updates"]="""
304 tree "dists/oldstable-proposed-updates/main"
306 FileList "/srv/ftp-master.debian.org/database/dists/oldstable-proposed-updates_main_$(SECTION)_binary-$(ARCH).list";
307 Sections "debian-installer";
308 Architectures "%(arch)s";
309 BinOverride "override.lenny.main.$(SECTION)";
310 SrcOverride "override.lenny.main.src";
311 BinCacheDB "packages-debian-installer-$(ARCH).db";
312 Packages::Extensions ".udeb";
320 (ac_fd, ac_name) = mkstemp(dir=tmppath, suffix=suite, prefix=arch)
321 os.write(ac_fd, DAILY_APT_CONF)
322 # here we want to generate the tree entries
323 os.write(ac_fd, apt_trees[suite] % {'arch': arch})
324 # this special casing needs to go away, but this whole thing may just want an
325 # aptconfig class anyways
327 if arch == 'hurd-i386' and suite == 'experimental':
329 elif apt_trees["di"].has_key(suite):
331 os.write(ac_fd, apt_trees["di"][suite] %
332 {'arch': arch, 'contentsline': 'Contents "$(DIST)/../Contents-udeb";'})
334 os.write(ac_fd, apt_trees["di"][suite] % {'arch': arch, 'contentsline': ''})
337 print "Going to run apt-ftparchive for %s/%s" % (arch, suite)
338 # Run apt-ftparchive generate
339 # We dont want to add a -q or -qq here, this output should go into our logs, sometimes
340 # it has errormessages we like to see
341 os.environ['GZIP'] = '--rsyncable'
343 (result, output) = commands.getstatusoutput('apt-ftparchive -o APT::FTPArchive::Contents=off generate %s' % os.path.basename(ac_name))
344 sn="a-f %s,%s: " % (suite, arch)
345 print sn + output.replace('\n', '\n%s' % (sn))
348 # Clean up any left behind files
363 return arch.arch_string
370 ########################################################################
371 ########################################################################
374 global Options, Logger, results
378 for i in ["Help", "Suite", "Force"]:
379 if not cnf.has_key("Generate-Packages-Sources::Options::%s" % (i)):
380 cnf["Generate-Packages-Sources::Options::%s" % (i)] = ""
382 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
383 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
384 ('f',"force","Generate-Packages-Sources::Options::Force")]
386 suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
387 Options = cnf.SubTree("Generate-Packages-Sources::Options")
392 Logger = daklog.Logger(cnf, 'generate-packages-sources')
394 session = DBConn().session()
399 for s in suite_names:
400 suite = get_suite(s.lower(), session)
404 print "cannot find suite %s" % s
405 Logger.log(['cannot find suite %s' % s])
407 suites=session.query(Suite).filter(Suite.untouchable == False).all()
409 startdir = os.getcwd()
410 os.chdir(cnf["Dir::TempPath"])
413 # For each given suite, each architecture, run one apt-ftparchive
416 # Setup a multiprocessing Pool. As many workers as we have CPU cores.
418 arch_list=get_suite_architectures(s.suite_name, skipsrc=False, skipall=True, session=session)
419 Logger.log(['generating output for Suite %s, Architectures %s' % (s.suite_name, map(sname, arch_list))])
421 pool.apply_async(generate_packages_sources, (a.arch_string, s.suite_name, cnf["Dir::TempPath"]), callback=get_result)
423 # No more work will be added to our pool, close it and then wait for all to finish
428 Logger.log(['Trouble, something with a-f broke, resultcodes: %s' % (results)])
429 print "Trouble, something with a-f broke, resultcodes: %s" % (results)
433 # this script doesn't change the database
437 #######################################################################################
439 if __name__ == '__main__':