]> git.decadent.org.uk Git - dak.git/blob - dak/make_changelog.py
First implementation of make-changelog command
[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 from daklib.queue import Upload
57
58 ################################################################################
59
60 suites = {'proposed-updates': 'proposedupdates',
61           'oldstable-proposed-updates': 'oldproposedupdates'}
62
63 def usage (exit_code=0):
64     print """Usage: make-changelog -s <suite> -b <base_suite> [OPTION]...
65 Generate changelog between two suites
66
67 Options:
68
69   -h, --help                show this help and exit
70   -s, --suite               suite providing packages to compare
71   -b, --base-suite          suite to be taken as reference for comparison"""
72
73     sys.exit(exit_code)
74
75 def get_new_packages(suite, base_suite):
76     """
77     Returns a dict of sources and versions where version is newer in base.
78     """
79
80     suite_sources = dict()
81     base_suite_sources = dict()
82     new_in_suite = dict()
83     session = DBConn().session()
84
85     # Get source details from given suites
86     for i in get_all_sources_in_suite(suite, session):
87         suite_sources[i[0]] = i[1]
88     for i in get_all_sources_in_suite(base_suite, session):
89         base_suite_sources[i[0]] = i[1]
90
91     # Compare if version in suite is greater than the base_suite one
92     for i in suite_sources.keys():
93         if i not in suite_sources.keys():
94             new_in_suite[i] = (suite_sources[i], 0)
95         elif apt_pkg.VersionCompare(suite_sources[i], base_suite_sources[i]) > 0:
96             new_in_suite[i] = (suite_sources[i], base_suite_sources[i])
97
98     return new_in_suite
99
100 def generate_changelog(suite, source, versions):
101     """
102     Generates changelog data returned from changelogs table
103     """
104     query = """
105     SELECT changelog FROM changelogs
106     WHERE suite = :suite
107     AND source = :source
108     AND version > :base
109     AND version <= :current
110     ORDER BY source, version DESC"""
111     session = DBConn().session()
112
113     result = session.execute(query, {'suite': suites[suite], 'source': source, \
114                              'base': versions[1], 'current': versions[0]})
115     session.commit()
116     for r in result.fetchall():
117         for i in range(0, len(r)):
118             print r[i]
119
120 def main():
121     Cnf = utils.get_conf()
122     Arguments = [('h','help','Make-Changelog::Options::Help'),
123                  ('s','suite','Make-Changelog::Options::Suite', 'HasArg'),
124                  ('b','base-suite','Make-Changelog::Options::Base-Suite', 'HasArg')]
125
126     for i in ['help', 'suite', 'base-suite']:
127         if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
128             Cnf['Make-Changelog::Options::%s' % (i)] = ''
129
130     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
131     Options = Cnf.SubTree('Make-Changelog::Options')
132     suite = Cnf['Make-Changelog::Options::Suite']
133     base_suite = Cnf['Make-Changelog::Options::Base-Suite']
134
135     if Options['help'] or not (suite and base_suite):
136         usage()
137
138     for s in suite, base_suite:
139         if not get_suite(s):
140             utils.fubar('Invalid suite "%s"' % s)
141
142     new_packages = get_new_packages(suite, base_suite)
143     for package in sorted(new_packages.keys()):
144         generate_changelog(suite, package, new_packages[package])
145
146 if __name__ == '__main__':
147     main()