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 ################################################################################
55 from commands import getstatusoutput
58 from shutil import rmtree
59 from daklib.dbconn import *
60 from daklib import utils
62 ################################################################################
64 def usage (exit_code=0):
65 print """Generate changelog between two suites
68 make-changelog -s <suite> -b <base_suite> [OPTION]...
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
81 -T, --testing display changes entering testing"""
85 def get_source_uploads(suite, base_suite, session):
87 Returns changelogs for source uploads where version is newer than base.
90 query = """WITH base AS (
91 SELECT source, max(version) AS version
93 WHERE suite_name = :base_suite
95 UNION (SELECT source, CAST(0 AS debversion) AS version
97 WHERE suite_name = :suite
98 EXCEPT SELECT source, CAST(0 AS debversion) AS version
100 WHERE suite_name = :base_suite
103 SELECT source, max(version) AS version
105 WHERE suite_name = :suite
107 SELECT DISTINCT c.source, c.version, c.changelog
109 JOIN base b ON b.source = c.source
110 JOIN cur_suite cs ON cs.source = c.source
111 WHERE c.version > b.version
112 AND c.version <= cs.version
113 AND c.architecture LIKE '%source%'
114 ORDER BY c.source, c.version DESC"""
116 return session.execute(query, {'suite': suite, 'base_suite': base_suite})
118 def get_binary_uploads(suite, base_suite, session):
120 Returns changelogs for binary uploads where version is newer than base.
123 query = """WITH base as (
124 SELECT s.source, max(b.version) AS version, a.arch_string
126 JOIN binaries b ON b.source = s.id
127 JOIN bin_associations ba ON ba.bin = b.id
128 JOIN architecture a ON a.id = b.architecture
132 WHERE suite_name = :base_suite)
133 GROUP BY s.source, a.arch_string),
135 SELECT s.source, max(b.version) AS version, a.arch_string
137 JOIN binaries b ON b.source = s.id
138 JOIN bin_associations ba ON ba.bin = b.id
139 JOIN architecture a ON a.id = b.architecture
143 WHERE suite_name = :suite)
144 GROUP BY s.source, a.arch_string)
145 SELECT DISTINCT c.source, c.version, c.architecture, c.changelog
147 JOIN base b on b.source = c.source
148 JOIN cur_suite cs ON cs.source = c.source
149 WHERE c.version > b.version
150 AND c.version <= cs.version
151 AND c.architecture = b.arch_string
152 AND c.architecture = cs.arch_string
153 ORDER BY c.source, c.version DESC, c.architecture"""
155 return session.execute(query, {'suite': suite, 'base_suite': base_suite})
157 def testing_summary(summary, session):
159 Returns changes introduced in packages entering testing.
162 query = 'SELECT source, changelog FROM changelogs WHERE'
163 fd = open(summary, 'r')
164 for package in fd.read().splitlines():
165 package = package.split()
166 if package[1] != package[2]:
167 if package[1] == '(not_in_testing)':
169 query += " source = '%s' AND version > '%s' AND version <= '%s'" \
170 % (package[0], package[1], package[2])
171 query += " AND architecture LIKE '%source%' OR"
173 query += ' False ORDER BY source, version DESC;'
175 return session.execute(query)
177 def display_changes(uploads, index):
179 for upload in uploads:
180 if prev_upload and prev_upload != upload[0]:
183 prev_upload = upload[0]
185 def export_files(session, pool, clpool):
187 Export interesting files from source packages.
191 query = """SELECT s.source, su.suite_name AS suite, s.version, f.filename
193 JOIN src_associations sa ON sa.source = s.id
194 JOIN suite su ON su.id = sa.suite
195 JOIN files f ON f.id = s.file
196 ORDER BY s.source, suite"""
198 for p in session.execute(query):
199 if not sources.has_key(p[0]):
201 sources[p[0]][p[1]] = (p[2], p[3])
203 tempdir = utils.temp_dirname()
206 for p in sources.keys():
207 for s in sources[p].keys():
208 files = (('changelog', True),
210 ('NEWS.Debian', False),
211 ('README.Debian', False))
212 path = os.path.join(clpool, sources[p][s][1].split('/')[0], \
213 split('(^lib\S|^\S)', p)[1], p)
214 if not os.path.exists(path):
217 for f in glob(os.path.join(path, s + '.*')):
221 t = os.path.join(path, '%s_%s.*%s' % (p, sources[p][s][0], file[0]))
222 if file[1] and not glob(t):
226 os.link(f, os.path.join(path, '%s.%s' % \
227 (s, os.path.basename(f).split('%s_%s.' \
228 % (p, sources[p][s][0]))[1])))
230 cmd = 'dpkg-source --no-check --no-copy -x %s %s' \
231 % (os.path.join(pool, sources[p][s][1]), tempdir)
232 (result, output) = getstatusoutput(cmd)
236 for f in glob(os.path.join(tempdir, 'debian', '*' + file[0])):
237 for dest in os.path.join(path, '%s_%s.%s' \
238 % (p, sources[p][s][0], os.path.basename(f))), \
239 os.path.join(path, '%s.%s' % (s, os.path.basename(f))):
240 if not os.path.exists(dest):
243 print 'make-changelog: unable to extract %s for %s_%s' \
244 % (os.path.basename(f), p, sources[p][s][0])
246 print 'make-changelog: unable to unpack %s_%s' % (p, sources[p][s][0])
251 for root, dirs, files in os.walk(clpool):
253 if root.split('/')[-1] not in sources.keys():
254 if os.path.exists(root):
257 if os.path.exists(os.path.join(root, file)):
258 if os.stat(os.path.join(root, file)).st_nlink == 1:
259 os.unlink(os.path.join(root, file))
262 Cnf = utils.get_conf()
263 Arguments = [('h','help','Make-Changelog::Options::Help'),
264 ('s','suite','Make-Changelog::Options::Suite','HasArg'),
265 ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
266 ('n','binnmu','Make-Changelog::Options::binNMU'),
267 ('e','export','Make-Changelog::Options::export'),
268 ('T', 'testing','Make-Changelog::Options::Testing')]
270 for i in ['help', 'suite', 'base-suite', 'binnmu', 'export', 'testing']:
271 if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
272 Cnf['Make-Changelog::Options::%s' % (i)] = ''
274 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
275 Options = Cnf.SubTree('Make-Changelog::Options')
276 suite = Cnf['Make-Changelog::Options::Suite']
277 base_suite = Cnf['Make-Changelog::Options::Base-Suite']
278 binnmu = Cnf['Make-Changelog::Options::binNMU']
279 export = Cnf['Make-Changelog::Options::export']
280 testing = Cnf['Make-Changelog::Options::Testing']
282 if Options['help'] or not (suite and base_suite) and not testing and not export:
285 for s in suite, base_suite:
286 if not testing and not export and not get_suite(s):
287 utils.fubar('Invalid suite "%s"' % s)
289 session = DBConn().session()
292 display_changes(testing_summary(Cnf['Changelogs::Testing'], session), 1)
294 export_files(session, Cnf['Dir::Pool'], Cnf['Changelogs::Export'])
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__':