4 Generate Packages/Sources files
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2011 Ansgar Burchardt <ansgar@debian.org>
8 @copyright: Based on daklib/lists.py and dak/generate_filelist.py:
9 2009-2011 Torsten Werner <twerner@debian.org>
10 @copyright: Based on dak/generate_packages_sources.py:
11 2000, 2001, 2002, 2006 James Troup <james@nocrew.org>
12 2009 Mark Hymers <mhy@debian.org>
13 2010 Joerg Jaspert <joerg@debian.org>
14 @license: GNU General Public License version 2 or later
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 print """Usage: dak generate-packages-sources2 [OPTIONS]
35 Generate the Packages/Sources files
37 -a, --archive=ARCHIVE process suites in ARCHIVE
38 -s, --suite=SUITE process this suite
39 Default: All suites not marked 'untouchable'
40 -f, --force Allow processing of untouchable suites
41 CAREFUL: Only to be used at point release time!
42 -h, --help show this help and exit
44 SUITE can be a space seperated list, e.g.
45 --suite=unstable testing
49 #############################################################################
58 WHEN key = 'Source' THEN E'Package\: '
59 WHEN key = 'Files' THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
60 WHEN key = 'Checksums-Sha1' THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
61 WHEN key = 'Checksums-Sha256' THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
63 END || value, E'\n' ORDER BY mk.ordering, mk.key)
66 JOIN metadata_keys mk ON mk.key_id = sm.key_id
71 WHEN src_associations_full.extra_source THEN E'\nExtra-Source-Only\: yes'
75 E'\nDirectory\: pool/' || :component_name || '/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z')
77 E'\nPriority\: ' || COALESCE(pri.priority, 'extra')
79 E'\nSection\: ' || COALESCE(sec.section, 'misc')
84 JOIN src_associations_full ON src_associations_full.suite = :suite AND s.id = src_associations_full.source
85 JOIN files f ON s.file=f.id
86 JOIN files_archive_map fam
88 AND fam.archive_id = (SELECT archive_id FROM suite WHERE id = :suite)
89 AND fam.component_id = :component
90 LEFT JOIN override o ON o.package = s.source
91 AND o.suite = :overridesuite
92 AND o.component = :component
93 AND o.type = :dsc_type
94 LEFT JOIN section sec ON o.section = sec.id
95 LEFT JOIN priority pri ON o.priority = pri.id
98 (src_associations_full.extra_source OR o.suite IS NOT NULL)
104 def generate_sources(suite_id, component_id):
105 global _sources_query
106 from daklib.filewriter import SourcesFileWriter
107 from daklib.dbconn import Component, DBConn, OverrideType, Suite
108 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
110 session = DBConn().session()
111 dsc_type = session.query(OverrideType).filter_by(overridetype='dsc').one().overridetype_id
113 suite = session.query(Suite).get(suite_id)
114 component = session.query(Component).get(component_id)
116 overridesuite_id = suite.get_overridesuite().suite_id
119 'archive': suite.archive.path,
120 'suite': suite.suite_name,
121 'component': component.component_name
123 if suite.indices_compression is not None:
124 writer_args['compression'] = suite.indices_compression
125 writer = SourcesFileWriter(**writer_args)
126 output = writer.open()
128 # run query and write Sources
129 r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "component_name": component.component_name, "dsc_type": dsc_type, "overridesuite": overridesuite_id})
131 print >>output, stanza
136 message = ["generate sources", suite.suite_name, component.component_name]
138 return (PROC_STATUS_SUCCESS, message)
140 #############################################################################
142 # Here be large dragons.
143 _packages_query = R"""
149 b.package AS package,
150 b.version AS version,
151 b.architecture AS architecture,
152 b.source AS source_id,
154 f.filename AS filename,
157 f.sha1sum AS sha1sum,
158 f.sha256sum AS sha256sum,
159 (SELECT value FROM binaries_metadata
161 AND key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Priority'))
162 AS fallback_priority,
163 (SELECT value FROM binaries_metadata
165 AND key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Section'))
169 JOIN bin_associations ba ON b.id = ba.bin
170 JOIN files f ON f.id = b.file
171 JOIN files_archive_map fam ON f.id = fam.file_id AND fam.archive_id = :archive_id
172 JOIN source s ON b.source = s.id
174 (b.architecture = :arch_all OR b.architecture = :arch) AND b.type = :type_name
175 AND ba.suite = :suite
176 AND fam.component_id = :component
181 STRING_AGG(key || E'\: ' || value, E'\n' ORDER BY ordering, key)
183 (SELECT key, ordering,
184 CASE WHEN :include_long_description = 'false' AND key = 'Description'
185 THEN SUBSTRING(value FROM E'\\A[^\n]*')
190 JOIN metadata_keys mk ON mk.key_id = bm.key_id
192 bm.bin_id = tmp.binary_id
193 AND key != ALL (:metadata_skip)
196 || COALESCE(E'\n' || (SELECT
197 STRING_AGG(key || E'\: ' || value, E'\n' ORDER BY key)
198 FROM external_overrides eo
200 eo.package = tmp.package
201 AND eo.suite = :overridesuite AND eo.component = :component
203 || E'\nSection\: ' || COALESCE(sec.section, tmp.fallback_section)
204 || E'\nPriority\: ' || COALESCE(pri.priority, tmp.fallback_priority)
205 || E'\nFilename\: pool/' || :component_name || '/' || tmp.filename
206 || E'\nSize\: ' || tmp.size
207 || E'\nMD5sum\: ' || tmp.md5sum
208 || E'\nSHA1\: ' || tmp.sha1sum
209 || E'\nSHA256\: ' || tmp.sha256sum
213 LEFT JOIN override o ON o.package = tmp.package
214 AND o.type = :type_id
215 AND o.suite = :overridesuite
216 AND o.component = :component
217 LEFT JOIN section sec ON sec.id = o.section
218 LEFT JOIN priority pri ON pri.id = o.priority
222 architecture <> :arch_all
224 (architecture = :arch_all AND source_id IN (SELECT source_id FROM tmp WHERE architecture <> :arch_all))
226 (architecture = :arch_all AND source NOT IN (SELECT DISTINCT source FROM tmp WHERE architecture <> :arch_all))
229 ORDER BY tmp.source, tmp.package, tmp.version
232 def generate_packages(suite_id, component_id, architecture_id, type_name):
233 global _packages_query
234 from daklib.filewriter import PackagesFileWriter
235 from daklib.dbconn import Architecture, Component, DBConn, OverrideType, Suite
236 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
238 session = DBConn().session()
239 arch_all_id = session.query(Architecture).filter_by(arch_string='all').one().arch_id
240 type_id = session.query(OverrideType).filter_by(overridetype=type_name).one().overridetype_id
242 suite = session.query(Suite).get(suite_id)
243 component = session.query(Component).get(component_id)
244 architecture = session.query(Architecture).get(architecture_id)
246 overridesuite_id = suite.get_overridesuite().suite_id
247 include_long_description = suite.include_long_description
249 # We currently filter out the "Tag" line. They are set by external
250 # overrides and NOT by the maintainer. And actually having it set by
251 # maintainer means we output it twice at the moment -> which breaks
253 metadata_skip = ["Section", "Priority", "Tag"]
254 if include_long_description:
255 metadata_skip.append("Description-md5")
258 'archive': suite.archive.path,
259 'suite': suite.suite_name,
260 'component': component.component_name,
261 'architecture': architecture.arch_string,
264 if suite.indices_compression is not None:
265 writer_args['compression'] = suite.indices_compression
266 writer = PackagesFileWriter(**writer_args)
267 output = writer.open()
269 r = session.execute(_packages_query, {"archive_id": suite.archive.archive_id,
270 "suite": suite_id, "component": component_id, 'component_name': component.component_name,
271 "arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id,
272 "overridesuite": overridesuite_id, "metadata_skip": metadata_skip,
273 "include_long_description": 'true' if include_long_description else 'false'})
275 print >>output, stanza
280 message = ["generate-packages", suite.suite_name, component.component_name, architecture.arch_string]
282 return (PROC_STATUS_SUCCESS, message)
284 #############################################################################
286 _translations_query = """
291 COALESCE(os.id, s.id) AS overridesuite_id
292 FROM suite AS s LEFT JOIN suite AS os ON s.overridesuite = os.suite_name)
295 E'Package\: ' || b.package
296 || E'\nDescription-md5\: ' || bm_description_md5.value
297 || E'\nDescription-en\: ' || bm_description.value
300 -- join tables for suite and component
301 JOIN bin_associations ba ON b.id = ba.bin
302 JOIN override_suite os ON os.id = ba.suite
303 JOIN override o ON b.package = o.package AND o.suite = os.overridesuite_id AND o.type = (SELECT id FROM override_type WHERE type = 'deb')
305 -- join tables for Description and Description-md5
306 JOIN binaries_metadata bm_description ON b.id = bm_description.bin_id AND bm_description.key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Description')
307 JOIN binaries_metadata bm_description_md5 ON b.id = bm_description_md5.bin_id AND bm_description_md5.key_id = (SELECT key_id FROM metadata_keys WHERE key = 'Description-md5')
309 -- we want to sort by source name
310 JOIN source s ON b.source = s.id
312 WHERE ba.suite = :suite AND o.component = :component
313 GROUP BY b.package, bm_description_md5.value, bm_description.value
314 ORDER BY MIN(s.source), b.package, bm_description_md5.value
317 def generate_translations(suite_id, component_id):
318 global _translations_query
319 from daklib.filewriter import TranslationFileWriter
320 from daklib.dbconn import DBConn, Suite, Component
321 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
323 session = DBConn().session()
324 suite = session.query(Suite).get(suite_id)
325 component = session.query(Component).get(component_id)
328 'archive': suite.archive.path,
329 'suite': suite.suite_name,
330 'component': component.component_name,
333 if suite.i18n_compression is not None:
334 writer_args['compression'] = suite.i18n_compression
335 writer = TranslationFileWriter(**writer_args)
336 output = writer.open()
338 r = session.execute(_translations_query, {"suite": suite_id, "component": component_id})
340 print >>output, stanza
344 message = ["generate-translations", suite.suite_name, component.component_name]
346 return (PROC_STATUS_SUCCESS, message)
348 #############################################################################
351 from daklib.config import Config
352 from daklib import daklog
356 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
357 ('a','archive','Generate-Packages-Sources::Options::Archive','HasArg'),
358 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
359 ('f',"force","Generate-Packages-Sources::Options::Force"),
360 ('o','option','','ArbItem')]
362 suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
364 Options = cnf.subtree("Generate-Packages-Sources::Options")
368 if Options.has_key("Help"):
371 from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
372 pool = DakProcessPool()
374 logger = daklog.Logger('generate-packages-sources2')
376 from daklib.dbconn import Component, DBConn, get_suite, Suite, Archive
377 session = DBConn().session()
378 session.execute("SELECT add_missing_description_md5()")
381 if Options.has_key("Suite"):
383 for s in suite_names:
384 suite = get_suite(s.lower(), session)
388 print "I: Cannot find suite %s" % s
389 logger.log(['Cannot find suite %s' % s])
391 query = session.query(Suite).filter(Suite.untouchable == False)
392 if 'Archive' in Options:
393 query = query.join(Suite.archive).filter(Archive.archive_name==Options['Archive'])
396 force = Options.has_key("Force") and Options["Force"]
399 def parse_results(message):
400 # Split out into (code, msg)
402 if code == PROC_STATUS_SUCCESS:
404 elif code == PROC_STATUS_SIGNALRAISED:
405 logger.log(['E: Subprocess recieved signal ', msg])
407 logger.log(['E: ', msg])
409 # Lock tables so that nobody can change things underneath us
410 session.execute("LOCK TABLE src_associations IN SHARE MODE")
411 session.execute("LOCK TABLE bin_associations IN SHARE MODE")
414 component_ids = [ c.component_id for c in s.components ]
415 if s.untouchable and not force:
417 daklib.utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
418 for c in component_ids:
419 pool.apply_async(generate_sources, [s.suite_id, c], callback=parse_results)
420 if not s.include_long_description:
421 pool.apply_async(generate_translations, [s.suite_id, c], callback=parse_results)
422 for a in s.architectures:
425 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'deb'], callback=parse_results)
426 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'udeb'], callback=parse_results)
431 # this script doesn't change the database
436 sys.exit(pool.overall_status())
438 if __name__ == '__main__':