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>
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ################################################################################
32 from tempfile import mkstemp, mkdtemp
34 from multiprocessing import Pool
36 from daklib import daklog
37 from daklib.dbconn import *
38 from daklib.config import Config
40 ################################################################################
42 Options = None #: Commandline arguments parsed into this
43 Logger = None #: Our logging object
45 ################################################################################
47 def usage (exit_code=0):
48 print """Usage: dak generate-packages-sources [OPTIONS]
49 Generate the Packages/Sources files
51 -s, --suite=SUITE(s) process this suite
52 Default: All suites not marked 'untouchable'
53 -f, --force Allow processing of untouchable suites
54 CAREFUL: Only to be used at point release time!
55 -h, --help show this help and exit
57 SUITE can be a space seperated list, e.g.
58 --suite=unstable testing
63 ################################################################################
65 def generate_packages_sources(arch, suite, tmppath):
67 Generate Packages/Sources files with apt-ftparchive for the given suite/arch
70 @param suite: Suite name
73 @param arch: Architecture name
76 @param tmppath: The temporary path to work ing
82 ArchiveDir "/srv/ftp-master.debian.org/ftp/";
83 OverrideDir "/srv/ftp-master.debian.org/scripts/override/";
84 CacheDir "/srv/ftp-master.debian.org/database/";
89 Packages::Compress "bzip2 gzip";
90 Sources::Compress "bzip2 gzip";
91 Contents::Compress "gzip";
93 MaxContentsChange 25000;
99 Contents::Header "/srv/ftp-master.debian.org/dak/config/debian/Contents.top";
106 apt_trees["testing"]="""
109 FakeDI "dists/unstable";
110 FileList "/srv/ftp-master.debian.org/database/dists/testing_$(SECTION)_binary-$(ARCH).list";
111 SourceFileList "/srv/ftp-master.debian.org/database/dists/testing_$(SECTION)_source.list";
112 Sections "main contrib non-free";
113 Architectures "%(arch)s";
114 BinOverride "override.squeeze.$(SECTION)";
115 ExtraOverride "override.squeeze.extra.$(SECTION)";
116 SrcOverride "override.squeeze.$(SECTION).src";
119 apt_trees["di"]["testing"]="""
120 tree "dists/testing/main"
122 FileList "/srv/ftp-master.debian.org/database/dists/testing_main_$(SECTION)_binary-$(ARCH).list";
123 Sections "debian-installer";
124 Architectures "%(arch)s";
125 BinOverride "override.squeeze.main.$(SECTION)";
126 SrcOverride "override.squeeze.main.src";
127 BinCacheDB "packages-debian-installer-$(ARCH).db";
128 Packages::Extensions ".udeb";
132 tree "dists/testing/non-free"
134 FileList "/srv/ftp-master.debian.org/database/dists/testing_non-free_$(SECTION)_binary-$(ARCH).list";
135 Sections "debian-installer";
136 Architectures "%(arch)s";
137 BinOverride "override.squeeze.main.$(SECTION)";
138 SrcOverride "override.squeeze.main.src";
139 BinCacheDB "packages-debian-installer-$(ARCH).db";
140 Packages::Extensions ".udeb";
145 apt_trees["unstable"]="""
146 tree "dists/unstable"
148 FileList "/srv/ftp-master.debian.org/database/dists/unstable_$(SECTION)_binary-$(ARCH).list";
149 SourceFileList "/srv/ftp-master.debian.org/database/dists/unstable_$(SECTION)_source.list";
150 Sections "main contrib non-free";
151 Architectures "%(arch)s";
152 BinOverride "override.sid.$(SECTION)";
153 ExtraOverride "override.sid.extra.$(SECTION)";
154 SrcOverride "override.sid.$(SECTION).src";
157 apt_trees["di"]["unstable"]="""
158 tree "dists/unstable/main"
160 FileList "/srv/ftp-master.debian.org/database/dists/unstable_main_$(SECTION)_binary-$(ARCH).list";
161 Sections "debian-installer";
162 Architectures "%(arch)s";
163 BinOverride "override.sid.main.$(SECTION)";
164 SrcOverride "override.sid.main.src";
165 BinCacheDB "packages-debian-installer-$(ARCH).db";
166 Packages::Extensions ".udeb";
170 tree "dists/unstable/non-free"
172 FileList "/srv/ftp-master.debian.org/database/dists/unstable_non-free_$(SECTION)_binary-$(ARCH).list";
173 Sections "debian-installer";
174 Architectures "%(arch)s";
175 BinOverride "override.sid.main.$(SECTION)";
176 SrcOverride "override.sid.main.src";
177 BinCacheDB "packages-debian-installer-$(ARCH).db";
178 Packages::Extensions ".udeb";
183 apt_trees["experimental"]="""
184 tree "dists/experimental"
186 FileList "/srv/ftp-master.debian.org/database/dists/experimental_$(SECTION)_binary-$(ARCH).list";
187 SourceFileList "/srv/ftp-master.debian.org/database/dists/experimental_$(SECTION)_source.list";
188 Sections "main contrib non-free";
189 Architectures "%(arch)s";
190 BinOverride "override.sid.$(SECTION)";
191 SrcOverride "override.sid.$(SECTION).src";
194 apt_trees["di"]["experimental"]="""
195 tree "dists/experimental/main"
197 FileList "/srv/ftp-master.debian.org/database/dists/experimental_main_$(SECTION)_binary-$(ARCH).list";
198 Sections "debian-installer";
199 Architectures "%(arch)s";
200 BinOverride "override.sid.main.$(SECTION)";
201 SrcOverride "override.sid.main.src";
202 BinCacheDB "packages-debian-installer-$(ARCH).db";
203 Packages::Extensions ".udeb";
207 tree "dists/experimental/non-free"
209 FileList "/srv/ftp-master.debian.org/database/dists/experimental_non-free_$(SECTION)_binary-$(ARCH).list";
210 Sections "debian-installer";
211 Architectures "%(arch)s";
212 BinOverride "override.sid.main.$(SECTION)";
213 SrcOverride "override.sid.main.src";
214 BinCacheDB "packages-debian-installer-$(ARCH).db";
215 Packages::Extensions ".udeb";
220 apt_trees["testing-proposed-updates"]="""
221 tree "dists/testing-proposed-updates"
223 FileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_$(SECTION)_binary-$(ARCH).list";
224 SourceFileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_$(SECTION)_source.list";
225 Sections "main contrib non-free";
226 Architectures "%(arch)s";
227 BinOverride "override.squeeze.$(SECTION)";
228 ExtraOverride "override.squeeze.extra.$(SECTION)";
229 SrcOverride "override.squeeze.$(SECTION).src";
233 apt_trees["di"]["testing-proposed-updates"]="""
234 tree "dists/testing-proposed-updates/main"
236 FileList "/srv/ftp-master.debian.org/database/dists/testing-proposed-updates_main_$(SECTION)_binary-$(ARCH).list";
237 Sections "debian-installer";
238 Architectures "%(arch)s";
239 BinOverride "override.squeeze.main.$(SECTION)";
240 SrcOverride "override.squeeze.main.src";
241 BinCacheDB "packages-debian-installer-$(ARCH).db";
242 Packages::Extensions ".udeb";
247 apt_trees["proposed-updates"]="""
248 tree "dists/proposed-updates"
250 FileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_$(SECTION)_binary-$(ARCH).list";
251 SourceFileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_$(SECTION)_source.list";
252 Sections "main contrib non-free";
253 Architectures "%(arch)s";
254 BinOverride "override.lenny.$(SECTION)";
255 ExtraOverride "override.lenny.extra.$(SECTION)";
256 SrcOverride "override.lenny.$(SECTION).src";
260 apt_trees["di"]["proposed-updates"]="""
261 tree "dists/proposed-updates/main"
263 FileList "/srv/ftp-master.debian.org/database/dists/proposed-updates_main_$(SECTION)_binary-$(ARCH).list";
264 Sections "debian-installer";
265 Architectures "%(arch)s";
266 BinOverride "override.lenny.main.$(SECTION)";
267 SrcOverride "override.lenny.main.src";
268 BinCacheDB "packages-debian-installer-$(ARCH).db";
269 Packages::Extensions ".udeb";
277 (ac_fd, ac_name) = mkstemp(dir=tmppath, suffix=suite, prefix=arch)
278 os.write(ac_fd, DAILY_APT_CONF)
279 # here we want to generate the tree entries
280 os.write(ac_fd, apt_trees[suite] % {'arch': arch})
281 # this special casing needs to go away, but this whole thing may just want an
282 # aptconfig class anyways
284 if arch == 'hurd-i386' and suite == 'experimental':
288 os.write(ac_fd, apt_trees["di"][suite] %
289 {'arch': arch, 'contentsline': 'Contents "$(DIST)/../Contents-udeb";'})
291 os.write(ac_fd, apt_trees["di"][suite] % {'arch': arch, 'contentsline': ''})
294 print "Going to run apt-ftparchive for %s/%s" % (arch, suite)
295 # Run apt-ftparchive generate
296 # We dont want to add a -q or -qq here, this output should go into our logs, sometimes
297 # it has errormessages we like to see
298 os.environ['GZIP'] = '--rsyncable'
300 (result, output) = commands.getstatusoutput('apt-ftparchive generate %s' % os.path.basename(ac_name))
301 sn="a-f %s,%s: " % (suite, arch)
302 print sn + output.replace('\n', '\n%s' % (sn))
304 # Clean up any left behind files
319 return arch.arch_string
321 ########################################################################
322 ########################################################################
325 global Options, Logger
329 for i in ["Help", "Suite", "Force"]:
330 if not cnf.has_key("Generate-Packages-Sources::Options::%s" % (i)):
331 cnf["Generate-Packages-Sources::Options::%s" % (i)] = ""
333 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
334 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
335 ('f',"force","Generate-Packages-Sources::Options::Force")]
337 suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
338 Options = cnf.SubTree("Generate-Packages-Sources::Options")
343 Logger = daklog.Logger(cnf, 'generate-packages-sources')
345 session = DBConn().session()
350 for s in suite_names:
351 suite = get_suite(s.lower(), session)
355 print "cannot find suite %s" % s
356 Logger.log(['cannot find suite %s' % s])
358 suites=session.query(Suite).filter(Suite.untouchable == False).all()
360 startdir = os.getcwd()
361 os.chdir(cnf["Dir::TempPath"])
363 # For each given suite, each architecture, run one apt-ftparchive
365 # Setup a multiprocessing Pool. As many workers as we have CPU cores.
367 arch_list=get_suite_architectures(s.suite_name, skipsrc=False, skipall=True, session=session)
368 Logger.log(['generating output for Suite %s, Architectures %s' % (s.suite_name, map(sname, arch_list))])
370 pool.apply_async(generate_packages_sources, (a.arch_string, s.suite_name, cnf["Dir::TempPath"]))
372 # No more work will be added to our pool, close it and then wait for all to finish
377 # this script doesn't change the database
381 #######################################################################################
383 if __name__ == '__main__':