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.threadpool import ThreadPool
41 from daklib import utils
42 import apt_pkg, os, stat, sys
44 from daklib.lists import getSources, getBinaries
46 def listPath(suite, component, architecture = None, type = None,
47 incremental_mode = False):
48 """returns full path to the list file"""
49 suffixMap = { 'deb': "binary-",
50 'udeb': "debian-installer_binary-" }
52 suffix = suffixMap[type] + architecture.arch_string
55 filename = "%s_%s_%s.list" % \
56 (suite.suite_name, component.component_name, suffix)
57 pathname = os.path.join(Config()["Dir::Lists"], filename)
58 file = utils.open_file(pathname, "a")
61 timestamp = os.fstat(file.fileno())[stat.ST_MTIME]
65 return (file, timestamp)
67 def writeSourceList(args):
68 (suite, component, incremental_mode) = args
69 (file, timestamp) = listPath(suite, component,
70 incremental_mode = incremental_mode)
71 session = DBConn().session()
72 for _, filename in getSources(suite, component, session, timestamp):
73 file.write(filename + '\n')
77 def writeBinaryList(args):
78 (suite, component, architecture, type, incremental_mode) = args
79 (file, timestamp) = listPath(suite, component, architecture, type,
81 session = DBConn().session()
82 for _, filename in getBinaries(suite, component, architecture, type,
84 file.write(filename + '\n')
89 print """Usage: dak generate_filelist [OPTIONS]
90 Create filename lists for apt-ftparchive.
92 -s, --suite=SUITE act on this suite
93 -c, --component=COMPONENT act on this component
94 -a, --architecture=ARCH act on this architecture
95 -h, --help show this help and exit
96 -i, --incremental activate incremental mode
98 ARCH, COMPONENT and SUITE can be comma (or space) separated list, e.g.
99 --suite=testing,unstable
101 Incremental mode appends only newer files to existing lists."""
106 Arguments = [('h', "help", "Filelist::Options::Help"),
107 ('s', "suite", "Filelist::Options::Suite", "HasArg"),
108 ('c', "component", "Filelist::Options::Component", "HasArg"),
109 ('a', "architecture", "Filelist::Options::Architecture", "HasArg"),
110 ('i', "incremental", "Filelist::Options::Incremental")]
111 session = DBConn().session()
112 query_suites = session.query(Suite)
113 suites = [suite.suite_name for suite in query_suites]
114 if not cnf.has_key('Filelist::Options::Suite'):
115 cnf['Filelist::Options::Suite'] = ','.join(suites).encode()
116 query_components = session.query(Component)
118 [component.component_name for component in query_components]
119 if not cnf.has_key('Filelist::Options::Component'):
120 cnf['Filelist::Options::Component'] = ','.join(components).encode()
121 query_architectures = session.query(Architecture)
123 [architecture.arch_string for architecture in query_architectures]
124 if not cnf.has_key('Filelist::Options::Architecture'):
125 cnf['Filelist::Options::Architecture'] = ','.join(architectures).encode()
126 cnf['Filelist::Options::Help'] = ''
127 cnf['Filelist::Options::Incremental'] = ''
128 apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
129 Options = cnf.SubTree("Filelist::Options")
132 threadpool = ThreadPool()
133 query_suites = query_suites. \
134 filter(Suite.suite_name.in_(utils.split_args(Options['Suite'])))
135 query_components = query_components. \
136 filter(Component.component_name.in_(utils.split_args(Options['Component'])))
137 query_architectures = query_architectures. \
138 filter(Architecture.arch_string.in_(utils.split_args(Options['Architecture'])))
139 for suite in query_suites:
140 for component in query_components:
141 for architecture in query_architectures:
142 if architecture not in suite.architectures:
144 elif architecture.arch_string == 'source':
145 threadpool.queueTask(writeSourceList,
146 (suite, component, Options['Incremental']))
147 elif architecture.arch_string != 'all':
148 threadpool.queueTask(writeBinaryList,
149 (suite, component, architecture, 'deb',
150 Options['Incremental']))
151 threadpool.queueTask(writeBinaryList,
152 (suite, component, architecture, 'udeb',
153 Options['Incremental']))
155 # this script doesn't change the database
158 if __name__ == '__main__':