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 -5, --description-md5 Allow to use Description-md5 instead of
42 Description for Packages index and generate
44 NOTE: suite.include_long_descriptions needs to
45 be set to false for this.
46 -h, --help show this help and exit
48 SUITE can be a space seperated list, e.g.
49 --suite=unstable testing
53 #############################################################################
62 WHEN key = 'Source' THEN 'Package\: '
63 WHEN key = 'Files' THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
64 WHEN key = 'Checksums-Sha1' THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
65 WHEN key = 'Checksums-Sha256' THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
67 END || value, E'\n' ORDER BY mk.ordering, mk.key)
70 JOIN metadata_keys mk ON mk.key_id = sm.key_id
74 E'\nDirectory\: pool/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z')
76 E'\nPriority\: ' || pri.priority
78 E'\nSection\: ' || sec.section
83 JOIN src_associations sa ON s.id = sa.source
84 JOIN files f ON s.file=f.id
85 JOIN override o ON o.package = s.source
86 JOIN section sec ON o.section = sec.id
87 JOIN priority pri ON o.priority = pri.id
91 AND o.suite = :overridesuite AND o.component = :component AND o.type = :dsc_type
97 def generate_sources(suite_id, component_id):
99 from daklib.filewriter import SourcesFileWriter
100 from daklib.dbconn import Component, DBConn, OverrideType, Suite
101 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
103 session = DBConn().session()
104 dsc_type = session.query(OverrideType).filter_by(overridetype='dsc').one().overridetype_id
106 suite = session.query(Suite).get(suite_id)
107 component = session.query(Component).get(component_id)
109 overridesuite_id = suite.get_overridesuite().suite_id
111 writer = SourcesFileWriter(suite=suite.suite_name, component=component.component_name)
112 output = writer.open()
114 # run query and write Sources
115 r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "dsc_type": dsc_type, "overridesuite": overridesuite_id})
117 print >>output, stanza
122 message = ["generate sources", suite.suite_name, component.component_name]
124 return (PROC_STATUS_SUCCESS, message)
126 #############################################################################
128 # Here be large dragons.
129 _packages_query = R"""
135 b.package AS package,
136 b.version AS version,
137 b.architecture AS architecture,
138 b.source AS source_id,
140 f.filename AS filename,
143 f.sha1sum AS sha1sum,
144 f.sha256sum AS sha256sum
147 JOIN bin_associations ba ON b.id = ba.bin
148 JOIN files f ON f.id = b.file
149 JOIN location l ON l.id = f.location
150 JOIN source s ON b.source = s.id
152 (b.architecture = :arch_all OR b.architecture = :arch) AND b.type = :type_name
153 AND ba.suite = :suite
154 AND l.component = :component
159 STRING_AGG(key || '\: ' || value, E'\n' ORDER BY ordering, key)
161 (SELECT key, ordering,
162 CASE WHEN :include_long_description = 'false' AND key = 'Description'
163 THEN SUBSTRING(value FROM E'\\A[^\n]*')
168 JOIN metadata_keys mk ON mk.key_id = bm.key_id
170 bm.bin_id = tmp.binary_id
171 AND key != ALL (:metadata_skip)
174 || COALESCE(E'\n' || (SELECT
175 STRING_AGG(key || '\: ' || value, E'\n' ORDER BY key)
176 FROM external_overrides eo
178 eo.package = tmp.package
179 AND eo.suite = :overridesuite AND eo.component = :component
181 || E'\nSection\: ' || sec.section
182 || E'\nPriority\: ' || pri.priority
183 || E'\nFilename\: pool/' || tmp.filename
184 || E'\nSize\: ' || tmp.size
185 || E'\nMD5sum\: ' || tmp.md5sum
186 || E'\nSHA1\: ' || tmp.sha1sum
187 || E'\nSHA256\: ' || tmp.sha256sum
191 JOIN override o ON o.package = tmp.package
192 JOIN section sec ON sec.id = o.section
193 JOIN priority pri ON pri.id = o.priority
197 architecture <> :arch_all
199 (architecture = :arch_all AND source_id IN (SELECT source_id FROM tmp WHERE architecture <> :arch_all))
201 (architecture = :arch_all AND source NOT IN (SELECT DISTINCT source FROM tmp WHERE architecture <> :arch_all))
204 o.type = :type_id AND o.suite = :overridesuite AND o.component = :component
206 ORDER BY tmp.source, tmp.package, tmp.version
209 def generate_packages(suite_id, component_id, architecture_id, type_name, use_description_md5):
210 global _packages_query
211 from daklib.filewriter import PackagesFileWriter
212 from daklib.dbconn import Architecture, Component, DBConn, OverrideType, Suite
213 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
215 session = DBConn().session()
216 arch_all_id = session.query(Architecture).filter_by(arch_string='all').one().arch_id
217 type_id = session.query(OverrideType).filter_by(overridetype=type_name).one().overridetype_id
219 suite = session.query(Suite).get(suite_id)
220 component = session.query(Component).get(component_id)
221 architecture = session.query(Architecture).get(architecture_id)
223 overridesuite_id = suite.get_overridesuite().suite_id
224 include_long_description = suite.include_long_description or not use_description_md5
226 # We currently filter out the "Tag" line. They are set by external
227 # overrides and NOT by the maintainer. And actually having it set by
228 # maintainer means we output it twice at the moment -> which breaks
230 metadata_skip = ["Section", "Priority", "Tag"]
231 if include_long_description:
232 metadata_skip.append("Description-md5")
234 writer = PackagesFileWriter(suite=suite.suite_name, component=component.component_name,
235 architecture=architecture.arch_string, debtype=type_name)
236 output = writer.open()
238 r = session.execute(_packages_query, {"suite": suite_id, "component": component_id,
239 "arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id,
240 "overridesuite": overridesuite_id, "metadata_skip": metadata_skip,
241 "include_long_description": 'true' if include_long_description else 'false'})
243 print >>output, stanza
248 message = ["generate-packages", suite.suite_name, component.component_name, architecture.arch_string]
250 return (PROC_STATUS_SUCCESS, message)
252 #############################################################################
254 _translations_query = """
259 COALESCE(os.id, s.id) AS overridesuite_id
260 FROM suite AS s LEFT JOIN suite AS os ON s.overridesuite = os.suite_name)
263 'Package\: ' || b.package
264 || E'\nDescription-md5\: ' || bm_description_md5.value
265 || E'\nDescription-en\: ' || bm_description.value
268 -- join tables for suite and component
269 JOIN bin_associations ba ON b.id = ba.bin
270 JOIN override_suite os ON os.id = ba.suite
271 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')
273 -- join tables for Description and Description-md5
274 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')
275 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')
277 -- we want to sort by source name
278 JOIN source s ON b.source = s.id
280 WHERE ba.suite = :suite AND o.component = :component
281 GROUP BY s.source, b.package, bm_description_md5.value, bm_description.value
282 ORDER BY s.source, b.package, bm_description_md5.value
285 def generate_translations(suite_id, component_id):
286 global _translations_query
287 from daklib.filewriter import TranslationFileWriter
288 from daklib.dbconn import DBConn, Suite, Component
289 from daklib.dakmultiprocessing import PROC_STATUS_SUCCESS
291 session = DBConn().session()
292 suite = session.query(Suite).get(suite_id)
293 component = session.query(Component).get(component_id)
295 writer = TranslationFileWriter(suite=suite.suite_name, component=component.component_name, language="en")
296 output = writer.open()
298 r = session.execute(_translations_query, {"suite": suite_id, "component": component_id})
300 print >>output, stanza
304 message = ["generate-translations", suite.suite_name, component.component_name]
306 return (PROC_STATUS_SUCCESS, message)
308 #############################################################################
311 from daklib.config import Config
312 from daklib import daklog
316 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
317 ('5','description-md5',"Generate-Packages-Sources::Options::Description-md5"),
318 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
319 ('f',"force","Generate-Packages-Sources::Options::Force"),
320 ('o','option','','ArbItem')]
322 suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
324 Options = cnf.SubTree("Generate-Packages-Sources::Options")
328 if Options.has_key("Help"):
331 from daklib.dakmultiprocessing import DakProcessPool, PROC_STATUS_SUCCESS, PROC_STATUS_SIGNALRAISED
332 pool = DakProcessPool()
334 logger = daklog.Logger('generate-packages-sources2')
336 from daklib.dbconn import Component, DBConn, get_suite, Suite
337 session = DBConn().session()
338 session.execute("SELECT add_missing_description_md5()")
341 if Options.has_key("Suite"):
343 for s in suite_names:
344 suite = get_suite(s.lower(), session)
348 print "I: Cannot find suite %s" % s
349 logger.log(['Cannot find suite %s' % s])
351 suites = session.query(Suite).filter(Suite.untouchable == False).all()
353 use_description_md5 = Options.has_key("Description-md5") and Options["Description-md5"]
354 force = Options.has_key("Force") and Options["Force"]
356 component_ids = [ c.component_id for c in session.query(Component).all() ]
358 def parse_results(message):
359 # Split out into (code, msg)
361 if code == PROC_STATUS_SUCCESS:
363 elif code == PROC_STATUS_SIGNALRAISED:
364 logger.log(['E: Subprocess recieved signal ', msg])
366 logger.log(['E: ', msg])
369 if s.untouchable and not force:
370 utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
371 for c in component_ids:
372 pool.apply_async(generate_sources, [s.suite_id, c], callback=parse_results)
373 if use_description_md5 and not s.include_long_description:
374 pool.apply_async(generate_translations, [s.suite_id, c], callback=parse_results)
375 for a in s.architectures:
378 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'deb', use_description_md5], callback=parse_results)
379 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'udeb', use_description_md5], callback=parse_results)
384 # this script doesn't change the database
389 sys.exit(pool.overall_status())
391 if __name__ == '__main__':