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 -s, --suite=SUITE process this suite
38 Default: All suites not marked 'untouchable'
39 -f, --force Allow processing of untouchable suites
40 CAREFUL: Only to be used at point release time!
41 -h, --help show this help and exit
43 SUITE can be a space seperated list, e.g.
44 --suite=unstable testing
48 #############################################################################
57 WHEN key = 'Source' THEN 'Package\: '
58 WHEN key = 'Files' THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
59 WHEN key = 'Checksums-Sha1' THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
60 WHEN key = 'Checksums-Sha256' THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
62 END || value, E'\n' ORDER BY mk.ordering, mk.key)
65 JOIN metadata_keys mk ON mk.key_id = sm.key_id
69 E'\nDirectory\: pool/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z')
71 E'\nPriority\: ' || pri.priority
73 E'\nSection\: ' || sec.section
78 JOIN src_associations sa ON s.id = sa.source
79 JOIN files f ON s.file=f.id
80 JOIN override o ON o.package = s.source
81 JOIN section sec ON o.section = sec.id
82 JOIN priority pri ON o.priority = pri.id
86 AND o.suite = :overridesuite AND o.component = :component AND o.type = :dsc_type
92 def generate_sources(suite_id, component_id):
94 from daklib.filewriter import SourcesFileWriter
95 from daklib.dbconn import Component, DBConn, OverrideType, Suite
96 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
98 session = DBConn().session()
99 dsc_type = session.query(OverrideType).filter_by(overridetype='dsc').one().overridetype_id
101 suite = session.query(Suite).get(suite_id)
102 component = session.query(Component).get(component_id)
104 overridesuite_id = suite.get_overridesuite().suite_id
106 writer = SourcesFileWriter(suite=suite.suite_name, component=component.component_name)
107 output = writer.open()
109 # run query and write Sources
110 r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "dsc_type": dsc_type, "overridesuite": overridesuite_id})
112 print >>output, stanza
117 message = ["generate sources", suite.suite_name, component.component_name]
119 return (PROC_STATUS_SUCCESS, message)
121 #############################################################################
123 # Here be large dragons.
124 _packages_query = R"""
130 b.package AS package,
131 b.version AS version,
132 b.architecture AS architecture,
133 b.source AS source_id,
135 f.filename AS filename,
138 f.sha1sum AS sha1sum,
139 f.sha256sum AS sha256sum
142 JOIN bin_associations ba ON b.id = ba.bin
143 JOIN files f ON f.id = b.file
144 JOIN location l ON l.id = f.location
145 JOIN source s ON b.source = s.id
147 (b.architecture = :arch_all OR b.architecture = :arch) AND b.type = :type_name
148 AND ba.suite = :suite
149 AND l.component = :component
154 STRING_AGG(key || '\: ' || value, E'\n' ORDER BY mk.ordering, mk.key)
157 JOIN metadata_keys mk ON mk.key_id = bm.key_id
159 bm.bin_id = tmp.binary_id
160 AND key != ALL (:metadata_skip)
162 || COALESCE(E'\n' || (SELECT
163 STRING_AGG(key || '\: ' || value, E'\n' ORDER BY key)
164 FROM external_overrides eo
166 eo.package = tmp.package
167 AND eo.suite = :overridesuite AND eo.component = :component
169 || E'\nSection\: ' || sec.section
170 || E'\nPriority\: ' || pri.priority
171 || E'\nFilename\: pool/' || tmp.filename
172 || E'\nSize\: ' || tmp.size
173 || E'\nMD5sum\: ' || tmp.md5sum
174 || E'\nSHA1\: ' || tmp.sha1sum
175 || E'\nSHA256\: ' || tmp.sha256sum
179 JOIN override o ON o.package = tmp.package
180 JOIN section sec ON sec.id = o.section
181 JOIN priority pri ON pri.id = o.priority
185 architecture <> :arch_all
187 (architecture = :arch_all AND source_id IN (SELECT source_id FROM tmp WHERE architecture <> :arch_all))
189 (architecture = :arch_all AND source NOT IN (SELECT DISTINCT source FROM tmp WHERE architecture <> :arch_all))
192 o.type = :type_id AND o.suite = :overridesuite AND o.component = :component
194 ORDER BY tmp.source, tmp.package, tmp.version
197 def generate_packages(suite_id, component_id, architecture_id, type_name):
198 global _packages_query
199 from daklib.filewriter import PackagesFileWriter
200 from daklib.dbconn import Architecture, Component, DBConn, OverrideType, Suite
201 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
203 session = DBConn().session()
204 arch_all_id = session.query(Architecture).filter_by(arch_string='all').one().arch_id
205 type_id = session.query(OverrideType).filter_by(overridetype=type_name).one().overridetype_id
207 suite = session.query(Suite).get(suite_id)
208 component = session.query(Component).get(component_id)
209 architecture = session.query(Architecture).get(architecture_id)
211 overridesuite_id = suite.get_overridesuite().suite_id
213 # We currently filter out the "Tag" line. They are set by external
214 # overrides and NOT by the maintainer. And actually having it set by
215 # maintainer means we output it twice at the moment -> which breaks
217 metadata_skip = ["Section", "Priority", "Tag"]
218 if suite.include_long_description:
219 metadata_skip.append("Description-md5")
221 metadata_skip.append("Description")
223 writer = PackagesFileWriter(suite=suite.suite_name, component=component.component_name,
224 architecture=architecture.arch_string, debtype=type_name)
225 output = writer.open()
227 r = session.execute(_packages_query, {"suite": suite_id, "component": component_id,
228 "arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id,
229 "overridesuite": overridesuite_id, "metadata_skip": metadata_skip})
231 print >>output, stanza
236 message = ["generate-packages", suite.suite_name, component.component_name, architecture.arch_string]
238 return (PROC_STATUS_SUCCESS, message)
240 #############################################################################
242 _translations_query = """
244 'Package\: ' || b.package
245 || E'\nDescription-md5\: ' || bm_description_md5.value
246 || E'\nDescription-en\: ' || bm_description.value
249 -- join tables for suite and component
250 JOIN bin_associations ba ON b.id = ba.bin
251 JOIN override o ON b.package = o.package AND o.suite = :suite AND o.type = (SELECT id FROM override_type WHERE type = 'deb')
253 -- join tables for Description and Description-md5
254 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')
255 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')
257 -- we want to sort by source name
258 JOIN source s ON b.source = s.id
260 WHERE ba.suite = :suite AND o.component = :component
261 GROUP BY s.source, b.package, bm_description_md5.value, bm_description.value
262 ORDER BY s.source, b.package, bm_description_md5.value
265 def generate_translations(suite_id, component_id):
266 global _translations_query
267 from daklib.filewriter import TranslationFileWriter
268 from daklib.dbconn import DBConn, Suite, Component
269 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
271 session = DBConn().session()
272 suite = session.query(Suite).get(suite_id)
273 component = session.query(Component).get(component_id)
275 writer = TranslationFileWriter(suite=suite.suite_name, component=component.component_name, language="en")
276 output = writer.open()
278 r = session.execute(_translations_query, {"suite": suite_id, "component": component_id})
280 print >>output, stanza
284 message = ["generate-translations", suite.suite_name, component.component_name]
286 return (PROC_STATUS_SUCCESS, message)
288 #############################################################################
291 from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
292 pool = DakProcessPool()
294 from daklib.dbconn import Component, DBConn, get_suite, Suite
295 from daklib.config import Config
296 from daklib import daklog
300 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
301 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
302 ('f',"force","Generate-Packages-Sources::Options::Force")]
304 suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
306 Options = cnf.SubTree("Generate-Packages-Sources::Options")
310 if Options.has_key("Help"):
313 logger = daklog.Logger('generate-packages-sources2')
315 session = DBConn().session()
316 session.execute("SELECT add_missing_description_md5()")
319 if Options.has_key("Suite"):
321 for s in suite_names:
322 suite = get_suite(s.lower(), session)
326 print "I: Cannot find suite %s" % s
327 logger.log(['Cannot find suite %s' % s])
329 suites = session.query(Suite).filter(Suite.untouchable == False).all()
331 force = Options.has_key("Force") and Options["Force"]
333 component_ids = [ c.component_id for c in session.query(Component).all() ]
335 def parse_results(message):
336 # Split out into (code, msg)
338 if code == PROC_STATUS_SUCCESS:
340 elif code == PROC_STATUS_SIGNALRAISED:
341 logger.log(['E: Subprocess recieved signal ', msg])
343 logger.log(['E: ', msg])
346 if s.untouchable and not force:
347 utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
348 for c in component_ids:
349 pool.apply_async(generate_sources, [s.suite_id, c], callback=parse_results)
350 pool.apply_async(generate_translations, [s.suite_id, c], callback=parse_results)
351 for a in s.architectures:
354 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'deb'], callback=parse_results)
355 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'udeb'], callback=parse_results)
360 # this script doesn't change the database
365 sys.exit(pool.overall_status())
367 if __name__ == '__main__':