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
31 from daklib.dbconn import *
32 from daklib.config import Config
33 from daklib import utils, daklog
34 from daklib.dakmultiprocessing import Pool
35 import apt_pkg, os, stat, sys
38 print """Usage: dak generate-packages-sources2 [OPTIONS]
39 Generate the Packages/Sources files
41 -s, --suite=SUITE process this suite
42 Default: All suites not marked 'untouchable'
43 -f, --force Allow processing of untouchable suites
44 CAREFUL: Only to be used at point release time!
45 -h, --help show this help and exit
47 SUITE can be a space seperated list, e.g.
48 --suite=unstable testing
52 #############################################################################
61 WHEN key = 'Source' THEN 'Package\: '
62 WHEN key = 'Files' THEN E'Files\:\n ' || f.md5sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
63 WHEN key = 'Checksums-Sha1' THEN E'Checksums-Sha1\:\n ' || f.sha1sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
64 WHEN key = 'Checksums-Sha256' THEN E'Checksums-Sha256\:\n ' || f.sha256sum || ' ' || f.size || ' ' || SUBSTRING(f.filename FROM E'/([^/]*)\\Z')
66 END || value, E'\n' ORDER BY mk.ordering, mk.key)
69 JOIN metadata_keys mk ON mk.key_id = sm.key_id
73 E'\nDirectory\: pool/' || SUBSTRING(f.filename FROM E'\\A(.*)/[^/]*\\Z')
75 E'\nPriority\: ' || pri.priority
77 E'\nSection\: ' || sec.section
82 JOIN src_associations sa ON s.id = sa.source
83 JOIN files f ON s.file=f.id
84 JOIN override o ON o.package = s.source
85 JOIN section sec ON o.section = sec.id
86 JOIN priority pri ON o.priority = pri.id
90 AND o.suite = :suite AND o.component = :component AND o.type = :dsc_type
96 def open_sources(suite, component):
98 dest = os.path.join(cnf['Dir::Root'], 'dists', suite.suite_name, component.component_name, 'source', 'Sources')
100 # create queue if it does not exist yet
101 if os.path.exists(dest) and os.path.isdir(dest):
104 dest_dir = os.path.dirname(dest)
105 if not os.path.exists(dest_dir):
106 umask = os.umask(00000)
107 os.makedirs(dest_dir, 02775)
113 def generate_sources(suite_id, component_id):
114 global _sources_query
116 session = DBConn().session()
117 dsc_type = session.query(OverrideType).filter_by(overridetype='dsc').one().overridetype_id
119 suite = session.query(Suite).get(suite_id)
120 component = session.query(Component).get(component_id)
122 output = open_sources(suite, component)
124 # run query and write Sources
125 r = session.execute(_sources_query, {"suite": suite_id, "component": component_id, "dsc_type": dsc_type})
127 print >>output, stanza
130 message = ["generate sources", suite.suite_name, component.component_name]
134 #############################################################################
136 # Here be large dragons.
137 _packages_query = R"""
143 b.package AS package,
144 b.version AS version,
145 b.architecture AS architecture,
146 b.source AS source_id,
148 f.filename AS filename,
151 f.sha1sum AS sha1sum,
152 f.sha256sum AS sha256sum
155 JOIN bin_associations ba ON b.id = ba.bin
156 JOIN files f ON f.id = b.file
157 JOIN location l ON l.id = f.location
158 JOIN source s ON b.source = s.id
160 (b.architecture = :arch_all OR b.architecture = :arch) AND b.type = :type_name
161 AND ba.suite = :suite
162 AND l.component = :component
167 STRING_AGG(key || '\: ' || value, E'\n' ORDER BY mk.ordering, mk.key)
170 JOIN metadata_keys mk ON mk.key_id = bm.key_id
172 bm.bin_id = tmp.binary_id
173 AND key != 'Section' AND key != 'Priority'
175 || E'\nSection\: ' || sec.section
176 || E'\nPriority\: ' || pri.priority
177 || E'\nFilename\: pool/' || tmp.filename
178 || E'\nSize\: ' || tmp.size
179 || E'\nMD5sum\: ' || tmp.md5sum
180 || E'\nSHA1\: ' || tmp.sha1sum
181 || E'\nSHA256\: ' || tmp.sha256sum
185 JOIN override o ON o.package = tmp.package
186 JOIN section sec ON sec.id = o.section
187 JOIN priority pri ON pri.id = o.priority
191 architecture <> :arch_all
193 (architecture = :arch_all AND source_id IN (SELECT source_id FROM tmp WHERE architecture <> :arch_all))
195 (architecture = :arch_all AND source NOT IN (SELECT DISTINCT source FROM tmp WHERE architecture <> :arch_all))
198 o.type = :type_id AND o.suite = :suite AND o.component = :component
200 ORDER BY tmp.package, tmp.version
203 def open_packages(suite, component, architecture, type_name):
205 if type_name == 'udeb':
206 dest = os.path.join(cnf['Dir::Root'], 'dists', suite.suite_name, component.component_name, 'debian-installer', 'binary-%s' % architecture.arch_string, 'Packages')
208 dest = os.path.join(cnf['Dir::Root'], 'dists', suite.suite_name, component.component_name, 'binary-%s' % architecture.arch_string, 'Packages')
210 # create queue if it does not exist yet
211 if os.path.exists(dest) and os.path.isdir(dest):
214 dest_dir = os.path.dirname(dest)
215 if not os.path.exists(dest_dir):
216 umask = os.umask(00000)
217 os.makedirs(dest_dir, 02775)
223 def generate_packages(suite_id, component_id, architecture_id, type_name):
224 global _packages_query
226 session = DBConn().session()
227 arch_all_id = session.query(Architecture).filter_by(arch_string='all').one().arch_id
228 type_id = session.query(OverrideType).filter_by(overridetype=type_name).one().overridetype_id
230 suite = session.query(Suite).get(suite_id)
231 component = session.query(Component).get(component_id)
232 architecture = session.query(Architecture).get(architecture_id)
234 output = open_packages(suite, component, architecture, type_name)
236 r = session.execute(_packages_query, {"suite": suite_id, "component": component_id,
237 "arch": architecture_id, "type_id": type_id, "type_name": type_name, "arch_all": arch_all_id})
239 print >>output, stanza
242 message = ["generate-packages", suite.suite_name, component.component_name, architecture.arch_string]
246 #############################################################################
251 Arguments = [('h',"help","Generate-Packages-Sources::Options::Help"),
252 ('s',"suite","Generate-Packages-Sources::Options::Suite"),
253 ('f',"force","Generate-Packages-Sources::Options::Force")]
255 suite_names = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
257 Options = cnf.SubTree("Generate-Packages-Sources::Options")
261 if Options.has_key("Help"):
264 logger = daklog.Logger(cnf, 'generate-packages-sources2')
266 session = DBConn().session()
268 if Options.has_key("Suite"):
270 for s in suite_names:
271 suite = get_suite(s.lower(), session)
275 print "I: Cannot find suite %s" % s
276 logger.log(['Cannot find suite %s' % s])
278 suites = session.query(Suite).filter(Suite.untouchable == False).all()
280 force = Options.has_key("Force") and Options["Force"]
282 component_ids = [ c.component_id for c in session.query(Component).all() ]
289 if s.untouchable and not force:
290 utils.fubar("Refusing to touch %s (untouchable and not forced)" % s.suite_name)
291 for c in component_ids:
292 pool.apply_async(generate_sources, [s.suite_id, c], callback=log)
293 for a in s.architectures:
294 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'deb'], callback=log)
295 pool.apply_async(generate_packages, [s.suite_id, c, a.arch_id, 'udeb'], callback=log)
299 # this script doesn't change the database
302 if __name__ == '__main__':