]> git.decadent.org.uk Git - dak.git/blob - dak/make_changelog.py
Merge remote branch 'drkranz/master' into merge
[dak.git] / dak / make_changelog.py
1 #!/usr/bin/env python
2
3 """
4 Generate changelog entry between two suites
5
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
9 """
10
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.
15
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.
20
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
24
25 ################################################################################
26
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
31 # <bdefreese> heh
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
39 # <bdefreese> heh
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
46 # <Ganneff> :)
47 # <bdefreese> haha
48 # <DktrKranz> damn dinstall, you racist bastard
49
50 ################################################################################
51
52 import sys
53 import apt_pkg
54 from daklib.dbconn import *
55 from daklib import utils
56
57 ################################################################################
58
59 def usage (exit_code=0):
60     print """Usage: make-changelog -s <suite> -b <base_suite> [OPTION]...
61 Generate changelog between two suites
62
63 Options:
64
65   -h, --help                show this help and exit
66   -s, --suite               suite providing packages to compare
67   -b, --base-suite          suite to be taken as reference for comparison
68   -n, --binnmu              display binNMUs uploads instead of source ones"""
69
70     sys.exit(exit_code)
71
72 def get_source_uploads(suite, base_suite, session):
73     """
74     Returns changelogs for source uploads where version is newer than base.
75     """
76
77     query = """WITH base AS (
78                  SELECT source, max(version) AS version
79                  FROM source_suite
80                  WHERE suite_name = :base_suite
81                  GROUP BY source
82                  UNION (SELECT source, CAST(0 AS debversion) AS version
83                  FROM source_suite
84                  WHERE suite_name = :suite
85                  EXCEPT SELECT source, CAST(0 AS debversion) AS version
86                  FROM source_suite
87                  WHERE suite_name = :base_suite
88                  ORDER BY source)),
89                cur_suite AS (
90                  SELECT source, max(version) AS version
91                  FROM source_suite
92                  WHERE suite_name = :suite
93                  GROUP BY source)
94                SELECT DISTINCT c.source, c.version, c.changelog
95                FROM changelogs c
96                JOIN base b ON b.source = c.source
97                JOIN cur_suite cs ON cs.source = c.source
98                WHERE c.version > b.version
99                AND c.version <= cs.version
100                AND c.architecture LIKE '%source%'
101                ORDER BY c.source, c.version DESC"""
102
103     return session.execute(query, {'suite': suite, 'base_suite': base_suite})
104
105 def get_binary_uploads(suite, base_suite, session):
106     """
107     Returns changelogs for binary uploads where version is newer than base.
108     """
109
110     query = """WITH base as (
111                  SELECT s.source, max(b.version) AS version, a.arch_string
112                  FROM source s
113                  JOIN binaries b ON b.source = s.id
114                  JOIN bin_associations ba ON ba.bin = b.id
115                  JOIN architecture a ON a.id = b.architecture
116                  WHERE ba.suite = (
117                    SELECT id
118                    FROM suite
119                    WHERE suite_name = :base_suite)
120                  GROUP BY s.source, a.arch_string),
121                cur_suite as (
122                  SELECT s.source, max(b.version) AS version, a.arch_string
123                  FROM source s
124                  JOIN binaries b ON b.source = s.id
125                  JOIN bin_associations ba ON ba.bin = b.id
126                  JOIN architecture a ON a.id = b.architecture
127                  WHERE ba.suite = (
128                    SELECT id
129                    FROM suite
130                    WHERE suite_name = :suite)
131                  GROUP BY s.source, a.arch_string)
132                SELECT DISTINCT c.source, c.version, c.architecture, c.changelog
133                FROM changelogs c
134                JOIN base b on b.source = c.source
135                JOIN cur_suite cs ON cs.source = c.source
136                WHERE c.version > b.version
137                AND c.version <= cs.version
138                AND c.architecture = b.arch_string
139                AND c.architecture = cs.arch_string
140                ORDER BY c.source, c.version DESC, c.architecture"""
141
142     return session.execute(query, {'suite': suite, 'base_suite': base_suite})
143
144 def main():
145     Cnf = utils.get_conf()
146     Arguments = [('h','help','Make-Changelog::Options::Help'),
147                  ('s','suite','Make-Changelog::Options::Suite','HasArg'),
148                  ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
149                  ('n','binnmu','Make-Changelog::Options::binNMU')]
150
151     for i in ['help', 'suite', 'base-suite', 'binnmu']:
152         if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
153             Cnf['Make-Changelog::Options::%s' % (i)] = ''
154
155     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
156     Options = Cnf.SubTree('Make-Changelog::Options')
157     suite = Cnf['Make-Changelog::Options::Suite']
158     base_suite = Cnf['Make-Changelog::Options::Base-Suite']
159     binnmu = Cnf['Make-Changelog::Options::binNMU']
160
161     if Options['help'] or not (suite and base_suite):
162         usage()
163
164     for s in suite, base_suite:
165         if not get_suite(s):
166             utils.fubar('Invalid suite "%s"' % s)
167
168     session = DBConn().session()
169
170     if binnmu:
171         uploads = get_binary_uploads(suite, base_suite, session)
172         session.commit()
173         for upload in uploads:
174             print upload[3] + "\n"
175     else:
176         uploads = get_source_uploads(suite, base_suite, session)
177         session.commit()
178         for upload in uploads:
179             print upload[2] + "\n"
180
181 if __name__ == '__main__':
182     main()