4 Generate file lists for apt-ftparchive.
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009 Torsten Werner <twerner@debian.org>
8 @license: GNU General Public License version 2 or later
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 from daklib.dbconn import *
26 from daklib.config import Config
27 from daklib import utils
28 import apt_pkg, os, sys
30 def fetch(query, args, session):
31 return [path + filename for (path, filename) in \
32 session.execute(query, args).fetchall()]
34 def getSources(suite, component, session):
37 FROM srcfiles_suite_component
38 WHERE suite = :suite AND component = :component
41 args = { 'suite': suite.suite_id,
42 'component': component.component_id }
43 return fetch(query, args, session)
45 def getBinaries(suite, component, architecture, type, session):
47 CREATE TEMP TABLE gf_candidates (
54 INSERT INTO gf_candidates (filename, path, architecture, src, source)
55 SELECT f.filename, l.path, b.architecture, b.source as src, s.source
57 JOIN bin_associations ba ON b.id = ba.bin
58 JOIN source s ON b.source = s.id
59 JOIN files f ON b.file = f.id
60 JOIN location l ON f.location = l.id
61 WHERE ba.suite = :suite AND b.type = :type AND
62 l.component = :component AND b.architecture IN (2, :architecture);
66 (SELECT path, filename FROM gf_candidates
67 WHERE architecture > 2),
70 (SELECT path, filename FROM gf_candidates
71 WHERE architecture = 2 AND
72 src IN (SELECT src FROM gf_candidates WHERE architecture > 2)),
74 arch_all_without_any AS
75 (SELECT path, filename FROM gf_candidates
76 WHERE architecture = 2 AND
77 source NOT IN (SELECT DISTINCT source FROM gf_candidates WHERE architecture > 2)),
80 (SELECT * FROM arch_any
82 SELECT * FROM arch_all_with_any
84 SELECT * FROM arch_all_without_any)
86 SELECT * FROM filelist ORDER BY filename
88 args = { 'suite': suite.suite_id,
89 'component': component.component_id,
90 'architecture': architecture.arch_id,
92 return fetch(query, args, session)
94 def listPath(suite, component, architecture = None, type = None):
95 """returns full path to the list file"""
96 suffixMap = { 'deb': "binary-",
97 'udeb': "debian-installer_binary-" }
99 suffix = suffixMap[type] + architecture.arch_string
102 filename = "%s_%s_%s.list" % \
103 (suite.suite_name, component.component_name, suffix)
104 pathname = os.path.join(Config()["Dir::Lists"], filename)
105 return utils.open_file(pathname, "w")
107 def writeSourceList(suite, component, session):
108 file = listPath(suite, component)
109 for filename in getSources(suite, component, session):
110 file.write(filename + '\n')
113 def writeBinaryList(suite, component, architecture, type):
114 file = listPath(suite, component, architecture, type)
115 session = DBConn().session()
116 for filename in getBinaries(suite, component, architecture, type, session):
117 file.write(filename + '\n')
122 print """Usage: dak generate_filelist [OPTIONS]
123 Create filename lists for apt-ftparchive.
125 -s, --suite=SUITE act on this suite
126 -c, --component=COMPONENT act on this component
127 -a, --architecture=ARCH act on this architecture
128 -h, --help show this help and exit
130 ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g.
131 --suite=testing,unstable"""
136 Arguments = [('h', "help", "Filelist::Options::Help"),
137 ('s', "suite", "Filelist::Options::Suite", "HasArg"),
138 ('c', "component", "Filelist::Options::Component", "HasArg"),
139 ('a', "architecture", "Filelist::Options::Architecture", "HasArg")]
140 query_suites = DBConn().session().query(Suite)
141 suites = [suite.suite_name for suite in query_suites.all()]
142 if not cnf.has_key('Filelist::Options::Suite'):
143 cnf['Filelist::Options::Suite'] = ','.join(suites)
144 # we can ask the database for components if 'mixed' is gone
145 if not cnf.has_key('Filelist::Options::Component'):
146 cnf['Filelist::Options::Component'] = 'main,contrib,non-free'
147 query_architectures = DBConn().session().query(Architecture)
149 [architecture.arch_string for architecture in query_architectures.all()]
150 if not cnf.has_key('Filelist::Options::Architecture'):
151 cnf['Filelist::Options::Architecture'] = ','.join(architectures)
152 cnf['Filelist::Options::Help'] = ''
153 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
154 Options = cnf.SubTree("Filelist::Options")
157 session = DBConn().session()
158 suite_arch = session.query(SuiteArchitecture)
159 for suite_name in utils.split_args(Options['Suite']):
160 suite = query_suites.filter_by(suite_name = suite_name).one()
161 join = suite_arch.filter_by(suite_id = suite.suite_id)
162 for component_name in utils.split_args(Options['Component']):
163 component = session.query(Component).\
164 filter_by(component_name = component_name).one()
165 for architecture_name in utils.split_args(Options['Architecture']):
166 architecture = query_architectures.\
167 filter_by(arch_string = architecture_name).one()
169 join.filter_by(arch_id = architecture.arch_id).one()
170 if architecture_name == 'source':
171 writeSourceList(suite, component, session)
172 elif architecture_name != 'all':
173 writeBinaryList(suite, component, architecture, 'deb')
174 writeBinaryList(suite, component, architecture, 'udeb')
177 # this script doesn't change the database
180 if __name__ == '__main__':