4 Generate changelog entry between two suites
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2010 Luca Falavigna <dktrkranz@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 # <bdefreese> !dinstall
28 # <dak> bdefreese: I guess the next dinstall will be in 0hr 1min 35sec
29 # <bdefreese> Wow I have great timing
30 # <DktrKranz> dating with dinstall, part II
32 # <Ganneff> dating with that monster? do you have good combat armor?
33 # <bdefreese> +5 Plate :)
34 # <Ganneff> not a good one then
35 # <Ganneff> so you wont even manage to bypass the lesser monster in front, unchecked
36 # <DktrKranz> asbesto belt
37 # <Ganneff> helps only a step
38 # <DktrKranz> the Ultimate Weapon: cron_turned_off
40 # <Ganneff> thats debadmin limited
41 # <Ganneff> no option for you
42 # <DktrKranz> bdefreese: it seems ftp-masters want dinstall to sexual harass us, are you good in running?
43 # <Ganneff> you can run but you can not hide
44 # <bdefreese> No, I'm old and fat :)
45 # <Ganneff> you can roll but you can not hide
48 # <DktrKranz> damn dinstall, you racist bastard
50 ################################################################################
56 from shutil import rmtree
57 from daklib.dbconn import *
58 from daklib import utils
59 from daklib.config import Config
60 from daklib.contents import UnpackedSource
61 from daklib.regexes import re_no_epoch
63 ################################################################################
65 def usage (exit_code=0):
66 print """Generate changelog between two suites
69 make-changelog -s <suite> -b <base_suite> [OPTION]...
70 make-changelog -e -a <archive>
74 -h, --help show this help and exit
75 -s, --suite suite providing packages to compare
76 -b, --base-suite suite to be taken as reference for comparison
77 -n, --binnmu display binNMUs uploads instead of source ones
79 -e, --export export interesting files from source packages
80 -a, --archive archive to fetch data from"""
84 def get_source_uploads(suite, base_suite, session):
86 Returns changelogs for source uploads where version is newer than base.
89 query = """WITH base AS (
90 SELECT source, max(version) AS version
92 WHERE suite_name = :base_suite
94 UNION (SELECT source, CAST(0 AS debversion) AS version
96 WHERE suite_name = :suite
97 EXCEPT SELECT source, CAST(0 AS debversion) AS version
99 WHERE suite_name = :base_suite
102 SELECT source, max(version) AS version
104 WHERE suite_name = :suite
106 SELECT DISTINCT c.source, c.version, c.changelog
108 JOIN base b ON b.source = c.source
109 JOIN cur_suite cs ON cs.source = c.source
110 WHERE c.version > b.version
111 AND c.version <= cs.version
112 AND c.architecture LIKE '%source%'
113 ORDER BY c.source, c.version DESC"""
115 return session.execute(query, {'suite': suite, 'base_suite': base_suite})
117 def get_binary_uploads(suite, base_suite, session):
119 Returns changelogs for binary uploads where version is newer than base.
122 query = """WITH base as (
123 SELECT s.source, max(b.version) AS version, a.arch_string
125 JOIN binaries b ON b.source = s.id
126 JOIN bin_associations ba ON ba.bin = b.id
127 JOIN architecture a ON a.id = b.architecture
131 WHERE suite_name = :base_suite)
132 GROUP BY s.source, a.arch_string),
134 SELECT s.source, max(b.version) AS version, a.arch_string
136 JOIN binaries b ON b.source = s.id
137 JOIN bin_associations ba ON ba.bin = b.id
138 JOIN architecture a ON a.id = b.architecture
142 WHERE suite_name = :suite)
143 GROUP BY s.source, a.arch_string)
144 SELECT DISTINCT c.source, c.version, c.architecture, c.changelog
146 JOIN base b on b.source = c.source
147 JOIN cur_suite cs ON cs.source = c.source
148 WHERE c.version > b.version
149 AND c.version <= cs.version
150 AND c.architecture = b.arch_string
151 AND c.architecture = cs.arch_string
152 ORDER BY c.source, c.version DESC, c.architecture"""
154 return session.execute(query, {'suite': suite, 'base_suite': base_suite})
156 def display_changes(uploads, index):
158 for upload in uploads:
159 if prev_upload and prev_upload != upload[0]:
162 prev_upload = upload[0]
164 def export_files(session, archive, clpool):
166 Export interesting files from source packages.
168 pool = os.path.join(archive.path, 'pool')
172 files = ('changelog', 'copyright', 'NEWS.Debian', 'README.Debian')
173 stats = {'unpack': 0, 'created': 0, 'removed': 0, 'errors': 0, 'files': 0}
174 query = """SELECT DISTINCT s.source, su.suite_name AS suite, s.version, c.name || '/' || f.filename AS filename
176 JOIN newest_source n ON n.source = s.source AND n.version = s.version
177 JOIN src_associations sa ON sa.source = s.id
178 JOIN suite su ON su.id = sa.suite
179 JOIN files f ON f.id = s.file
180 JOIN files_archive_map fam ON f.id = fam.file_id AND fam.archive_id = su.archive_id
181 JOIN component c ON fam.component_id = c.id
182 WHERE su.archive_id = :archive_id
183 ORDER BY s.source, suite"""
185 for p in session.execute(query, {'archive_id': archive.archive_id}):
186 if not sources.has_key(p[0]):
188 sources[p[0]][p[1]] = (re_no_epoch.sub('', p[2]), p[3])
190 for p in sources.keys():
191 for s in sources[p].keys():
192 path = os.path.join(clpool, '/'.join(sources[p][s][1].split('/')[:-1]))
193 if not os.path.exists(path):
195 if not os.path.exists(os.path.join(path, \
196 '%s_%s.changelog' % (p, sources[p][s][0]))):
197 if not unpack.has_key(os.path.join(pool, sources[p][s][1])):
198 unpack[os.path.join(pool, sources[p][s][1])] = (path, set())
199 unpack[os.path.join(pool, sources[p][s][1])][1].add(s)
201 for file in glob('%s/%s_%s*' % (path, p, sources[p][s][0])):
202 link = '%s%s' % (s, file.split('%s_%s' \
203 % (p, sources[p][s][0]))[1])
205 os.unlink(os.path.join(path, link))
208 os.link(os.path.join(path, file), os.path.join(path, link))
210 for p in unpack.keys():
211 package = os.path.splitext(os.path.basename(p))[0].split('_')
213 unpacked = UnpackedSource(p)
214 tempdir = unpacked.get_root_directory()
217 for f in glob(os.path.join(tempdir, 'debian', '*%s' % file)):
218 for s in unpack[p][1]:
219 suite = os.path.join(unpack[p][0], '%s.%s' \
220 % (s, os.path.basename(f)))
221 version = os.path.join(unpack[p][0], '%s_%s.%s' % \
222 (package[0], package[1], os.path.basename(f)))
223 if not os.path.exists(version):
225 stats['created'] += 1
230 os.link(version, suite)
231 stats['created'] += 1
233 except Exception as e:
234 print 'make-changelog: unable to unpack %s\n%s' % (p, e)
237 for root, dirs, files in os.walk(clpool):
239 if root.split('/')[-1] not in sources.keys():
240 if os.path.exists(root):
242 stats['removed'] += 1
244 if os.path.exists(os.path.join(root, file)):
245 if os.stat(os.path.join(root, file)).st_nlink == 1:
246 os.unlink(os.path.join(root, file))
247 stats['removed'] += 1
249 for root, dirs, files in os.walk(clpool):
250 stats['files'] += len(files)
251 print 'make-changelog: file exporting finished'
252 print ' * New packages unpacked: %d' % stats['unpack']
253 print ' * New files created: %d' % stats['created']
254 print ' * New files removed: %d' % stats['removed']
255 print ' * Unpack errors: %d' % stats['errors']
256 print ' * Files available into changelog pool: %d' % stats['files']
259 Cnf = utils.get_conf()
261 Arguments = [('h','help','Make-Changelog::Options::Help'),
262 ('a','archive','Make-Changelog::Options::Archive','HasArg'),
263 ('s','suite','Make-Changelog::Options::Suite','HasArg'),
264 ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
265 ('n','binnmu','Make-Changelog::Options::binNMU'),
266 ('e','export','Make-Changelog::Options::export')]
268 for i in ['help', 'suite', 'base-suite', 'binnmu', 'export']:
269 if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
270 Cnf['Make-Changelog::Options::%s' % (i)] = ''
272 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
273 Options = Cnf.subtree('Make-Changelog::Options')
274 suite = Cnf['Make-Changelog::Options::Suite']
275 base_suite = Cnf['Make-Changelog::Options::Base-Suite']
276 binnmu = Cnf['Make-Changelog::Options::binNMU']
277 export = Cnf['Make-Changelog::Options::export']
279 if Options['help'] or not (suite and base_suite) and not export:
282 for s in suite, base_suite:
283 if not export and not get_suite(s):
284 utils.fubar('Invalid suite "%s"' % s)
286 session = DBConn().session()
290 archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
291 exportpath = os.path.join(Cnf['Dir::Export'], cnf.exportpath)
292 export_files(session, archive, exportpath)
294 utils.fubar('No changelog export path defined')
296 display_changes(get_binary_uploads(suite, base_suite, session), 3)
298 display_changes(get_source_uploads(suite, base_suite, session), 2)
302 if __name__ == '__main__':