From: Joerg Jaspert Date: Tue, 22 Jun 2010 19:22:43 +0000 (+0200) Subject: Merge remote branch 'drkranz/make-changelog' into merge X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=f63c8b5ea1b8a059bc70fa323ec836af1402be2c;hp=be2458cb021ea7bda7c5647b86c3be1eb6afcca5;p=dak.git Merge remote branch 'drkranz/make-changelog' into merge * drkranz/make-changelog: Fix indentation Implement changelogs for binNMUss too Refactorize make-changelog handling, only for source uploads ATM First implementation of make-changelog command Signed-off-by: Joerg Jaspert --- diff --git a/dak/dak.py b/dak/dak.py index 8d7776a5..4ad59579 100755 --- a/dak/dak.py +++ b/dak/dak.py @@ -144,6 +144,8 @@ def init(): "import old changes files into known_changes table"), ("add-user", "Add a user to the archive"), + ("make-changelog", + "Generate changelog between two suites"), ] return functionality diff --git a/dak/dakdb/update33.py b/dak/dakdb/update33.py new file mode 100644 index 00000000..9624ba62 --- /dev/null +++ b/dak/dakdb/update33.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Implement changelogs related tables + +@contact: Debian FTP Master +@copyright: 2010 Luca Falavigna +@license: GNU General Public License version 2 or later +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + + +################################################################################ + +import psycopg2 +from daklib.dak_exceptions import DBUpdateError + +################################################################################ +def do_update(self): + """ + Implement changelogs table + """ + print __doc__ + try: + c = self.db.cursor() + c.execute('ALTER TABLE changes ADD COLUMN changelog_id integer') + c.execute('CREATE TABLE changelogs_text (id serial PRIMARY KEY NOT NULL, changelog text)') + c.execute("GRANT SELECT ON changelogs_text TO public") + c.execute("GRANT ALL ON changelogs_text TO ftpmaster") + c.execute('CREATE VIEW changelogs AS SELECT cl.id, source, CAST(version AS debversion), architecture, changelog \ + FROM changes c JOIN changelogs_text cl ON cl.id = c.changelog_id') + c.execute("GRANT SELECT ON changelogs TO public") + c.execute("GRANT ALL ON changelogs TO ftpmaster") + c.execute("UPDATE config SET value = '33' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError, msg: + self.db.rollback() + raise DBUpdateError, 'Unable to apply build_queue update 33, rollback issued. Error message : %s' % (str(msg)) diff --git a/dak/make_changelog.py b/dak/make_changelog.py new file mode 100755 index 00000000..acd23c2b --- /dev/null +++ b/dak/make_changelog.py @@ -0,0 +1,182 @@ +#!/usr/bin/env python + +""" +Generate changelog entry between two suites + +@contact: Debian FTP Master +@copyright: 2010 Luca Falavigna +@license: GNU General Public License version 2 or later +""" + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +# !dinstall +# bdefreese: I guess the next dinstall will be in 0hr 1min 35sec +# Wow I have great timing +# dating with dinstall, part II +# heh +# dating with that monster? do you have good combat armor? +# +5 Plate :) +# not a good one then +# so you wont even manage to bypass the lesser monster in front, unchecked +# asbesto belt +# helps only a step +# the Ultimate Weapon: cron_turned_off +# heh +# thats debadmin limited +# no option for you +# bdefreese: it seems ftp-masters want dinstall to sexual harass us, are you good in running? +# you can run but you can not hide +# No, I'm old and fat :) +# you can roll but you can not hide +# :) +# haha +# damn dinstall, you racist bastard + +################################################################################ + +import sys +import apt_pkg +from daklib.dbconn import * +from daklib import utils + +################################################################################ + +def usage (exit_code=0): + print """Usage: make-changelog -s -b [OPTION]... +Generate changelog between two suites + +Options: + + -h, --help show this help and exit + -s, --suite suite providing packages to compare + -b, --base-suite suite to be taken as reference for comparison + -n, --binnmu display binNMUs uploads instead of source ones""" + + sys.exit(exit_code) + +def get_source_uploads(suite, base_suite, session): + """ + Returns changelogs for source uploads where version is newer than base. + """ + + query = """WITH base AS ( + SELECT source, max(version) AS version + FROM source_suite + WHERE suite_name = :base_suite + GROUP BY source + UNION (SELECT source, CAST(0 AS debversion) AS version + FROM source_suite + WHERE suite_name = :suite + EXCEPT SELECT source, CAST(0 AS debversion) AS version + FROM source_suite + WHERE suite_name = :base_suite + ORDER BY source)), + cur_suite AS ( + SELECT source, max(version) AS version + FROM source_suite + WHERE suite_name = :suite + GROUP BY source) + SELECT DISTINCT c.source, c.version, c.changelog + FROM changelogs c + JOIN base b ON b.source = c.source + JOIN cur_suite cs ON cs.source = c.source + WHERE c.version > b.version + AND c.version <= cs.version + AND c.architecture LIKE '%source%' + ORDER BY c.source, c.version DESC""" + + return session.execute(query, {'suite': suite, 'base_suite': base_suite}) + +def get_binary_uploads(suite, base_suite, session): + """ + Returns changelogs for binary uploads where version is newer than base. + """ + + query = """WITH base as ( + SELECT s.source, max(b.version) AS version, a.arch_string + FROM source s + JOIN binaries b ON b.source = s.id + JOIN bin_associations ba ON ba.bin = b.id + JOIN architecture a ON a.id = b.architecture + WHERE ba.suite = ( + SELECT id + FROM suite + WHERE suite_name = :base_suite) + GROUP BY s.source, a.arch_string), + cur_suite as ( + SELECT s.source, max(b.version) AS version, a.arch_string + FROM source s + JOIN binaries b ON b.source = s.id + JOIN bin_associations ba ON ba.bin = b.id + JOIN architecture a ON a.id = b.architecture + WHERE ba.suite = ( + SELECT id + FROM suite + WHERE suite_name = :suite) + GROUP BY s.source, a.arch_string) + SELECT DISTINCT c.source, c.version, c.architecture, c.changelog + FROM changelogs c + JOIN base b on b.source = c.source + JOIN cur_suite cs ON cs.source = c.source + WHERE c.version > b.version + AND c.version <= cs.version + AND c.architecture = b.arch_string + AND c.architecture = cs.arch_string + ORDER BY c.source, c.version DESC, c.architecture""" + + return session.execute(query, {'suite': suite, 'base_suite': base_suite}) + +def main(): + Cnf = utils.get_conf() + Arguments = [('h','help','Make-Changelog::Options::Help'), + ('s','suite','Make-Changelog::Options::Suite','HasArg'), + ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'), + ('n','binnmu','Make-Changelog::Options::binNMU')] + + for i in ['help', 'suite', 'base-suite', 'binnmu']: + if not Cnf.has_key('Make-Changelog::Options::%s' % (i)): + Cnf['Make-Changelog::Options::%s' % (i)] = '' + + apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) + Options = Cnf.SubTree('Make-Changelog::Options') + suite = Cnf['Make-Changelog::Options::Suite'] + base_suite = Cnf['Make-Changelog::Options::Base-Suite'] + binnmu = Cnf['Make-Changelog::Options::binNMU'] + + if Options['help'] or not (suite and base_suite): + usage() + + for s in suite, base_suite: + if not get_suite(s): + utils.fubar('Invalid suite "%s"' % s) + + session = DBConn().session() + + if binnmu: + uploads = get_binary_uploads(suite, base_suite, session) + session.commit() + for upload in uploads: + print upload[3] + else: + uploads = get_source_uploads(suite, base_suite, session) + session.commit() + for upload in uploads: + print upload[2] + +if __name__ == '__main__': + main() diff --git a/dak/update_db.py b/dak/update_db.py index 68592785..49ea9a56 100755 --- a/dak/update_db.py +++ b/dak/update_db.py @@ -45,7 +45,7 @@ from daklib.dak_exceptions import DBUpdateError ################################################################################ Cnf = None -required_database_schema = 32 +required_database_schema = 33 ################################################################################ diff --git a/daklib/queue.py b/daklib/queue.py index c177602c..58fdf7f3 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -1899,6 +1899,9 @@ distribution.""" # Make sure that our source object is up-to-date session.expire(source) + # Add changelog information to the database + self.store_changelog() + # Install the files into the pool for newfile, entry in self.pkg.files.items(): destination = os.path.join(cnf["Dir::Pool"], entry["pool name"], newfile) @@ -2672,3 +2675,26 @@ distribution.""" os.chdir(cwd) return too_new + + def store_changelog(self): + + # Skip binary-only upload if it is not a bin-NMU + if not self.pkg.changes['architecture'].has_key('source'): + from daklib.regexes import re_bin_only_nmu + if not re_bin_only_nmu.search(self.pkg.changes['version']): + return + + session = DBConn().session() + + # Add current changelog text into changelogs_text table, return created ID + query = "INSERT INTO changelogs_text (changelog) VALUES (:changelog) RETURNING id" + ID = session.execute(query, {'changelog': self.pkg.changes['changes']}).fetchone()[0] + + # Link ID to the upload available in changes table + query = """UPDATE changes SET changelog_id = :id WHERE source = :source + AND version = :version AND architecture = :architecture""" + session.execute(query, {'id': ID, 'source': self.pkg.changes['source'], \ + 'version': self.pkg.changes['version'], \ + 'architecture': " ".join(self.pkg.changes['architecture'].keys())}) + + session.commit()