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 ################################################################################
27 # Ganneff> Please go and try to lock mhy now. After than try to lock NEW.
29 # dak> twerner: You suck, this is already locked by Ganneff
30 # Ganneff> now try with NEW
32 # dak> twerner: also locked NEW
33 # mhy> Ganneff: oy, stop using me for locks and highlighting me you tall muppet
36 ################################################################################
38 from daklib.dbconn import *
39 from daklib.config import Config
40 from daklib import utils
41 import apt_pkg, os, sys
43 def fetch(query, args, session):
44 return [path + filename for (path, filename) in \
45 session.execute(query, args).fetchall()]
47 def getSources(suite, component, session):
50 FROM srcfiles_suite_component
51 WHERE suite = :suite AND component = :component
54 args = { 'suite': suite.suite_id,
55 'component': component.component_id }
56 return fetch(query, args, session)
58 def getBinaries(suite, component, architecture, type, session):
60 CREATE TEMP TABLE gf_candidates (
67 INSERT INTO gf_candidates (filename, path, architecture, src, source)
68 SELECT f.filename, l.path, b.architecture, b.source as src, s.source
70 JOIN bin_associations ba ON b.id = ba.bin
71 JOIN source s ON b.source = s.id
72 JOIN files f ON b.file = f.id
73 JOIN location l ON f.location = l.id
74 WHERE ba.suite = :suite AND b.type = :type AND
75 l.component = :component AND b.architecture IN (2, :architecture);
79 (SELECT path, filename FROM gf_candidates
80 WHERE architecture > 2),
83 (SELECT path, filename FROM gf_candidates
84 WHERE architecture = 2 AND
85 src IN (SELECT src FROM gf_candidates WHERE architecture > 2)),
87 arch_all_without_any AS
88 (SELECT path, filename FROM gf_candidates
89 WHERE architecture = 2 AND
90 source NOT IN (SELECT DISTINCT source FROM gf_candidates WHERE architecture > 2)),
93 (SELECT * FROM arch_any
95 SELECT * FROM arch_all_with_any
97 SELECT * FROM arch_all_without_any)
99 SELECT * FROM filelist ORDER BY filename
101 args = { 'suite': suite.suite_id,
102 'component': component.component_id,
103 'architecture': architecture.arch_id,
105 return fetch(query, args, session)
107 def listPath(suite, component, architecture = None, type = None):
108 """returns full path to the list file"""
109 suffixMap = { 'deb': "binary-",
110 'udeb': "debian-installer_binary-" }
112 suffix = suffixMap[type] + architecture.arch_string
115 filename = "%s_%s_%s.list" % \
116 (suite.suite_name, component.component_name, suffix)
117 pathname = os.path.join(Config()["Dir::Lists"], filename)
118 return utils.open_file(pathname, "w")
120 def writeSourceList(suite, component):
121 file = listPath(suite, component)
122 session = DBConn().session()
123 for filename in getSources(suite, component, session):
124 file.write(filename + '\n')
128 def writeBinaryList(suite, component, architecture, type):
129 file = listPath(suite, component, architecture, type)
130 session = DBConn().session()
131 for filename in getBinaries(suite, component, architecture, type, session):
132 file.write(filename + '\n')
137 print """Usage: dak generate_filelist [OPTIONS]
138 Create filename lists for apt-ftparchive.
140 -s, --suite=SUITE act on this suite
141 -c, --component=COMPONENT act on this component
142 -a, --architecture=ARCH act on this architecture
143 -h, --help show this help and exit
145 ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g.
146 --suite=testing,unstable"""
151 Arguments = [('h', "help", "Filelist::Options::Help"),
152 ('s', "suite", "Filelist::Options::Suite", "HasArg"),
153 ('c', "component", "Filelist::Options::Component", "HasArg"),
154 ('a', "architecture", "Filelist::Options::Architecture", "HasArg")]
155 query_suites = DBConn().session().query(Suite)
156 suites = [suite.suite_name for suite in query_suites.all()]
157 if not cnf.has_key('Filelist::Options::Suite'):
158 cnf['Filelist::Options::Suite'] = ','.join(suites)
159 # we can ask the database for components if 'mixed' is gone
160 if not cnf.has_key('Filelist::Options::Component'):
161 cnf['Filelist::Options::Component'] = 'main,contrib,non-free'
162 query_architectures = DBConn().session().query(Architecture)
164 [architecture.arch_string for architecture in query_architectures.all()]
165 if not cnf.has_key('Filelist::Options::Architecture'):
166 cnf['Filelist::Options::Architecture'] = ','.join(architectures)
167 cnf['Filelist::Options::Help'] = ''
168 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
169 Options = cnf.SubTree("Filelist::Options")
172 session = DBConn().session()
173 suite_arch = session.query(SuiteArchitecture)
174 for suite_name in utils.split_args(Options['Suite']):
175 suite = query_suites.filter_by(suite_name = suite_name).one()
176 join = suite_arch.filter_by(suite_id = suite.suite_id)
177 for component_name in utils.split_args(Options['Component']):
178 component = session.query(Component).\
179 filter_by(component_name = component_name).one()
180 for architecture_name in utils.split_args(Options['Architecture']):
181 architecture = query_architectures.\
182 filter_by(arch_string = architecture_name).one()
184 join.filter_by(arch_id = architecture.arch_id).one()
185 if architecture_name == 'source':
186 writeSourceList(suite, component)
187 elif architecture_name != 'all':
188 writeBinaryList(suite, component, architecture, 'deb')
189 writeBinaryList(suite, component, architecture, 'udeb')
192 # this script doesn't change the database
195 if __name__ == '__main__':