From d9daaa0b74845853a09b34cd930f6f2879bc1254 Mon Sep 17 00:00:00 2001 From: Luca Falavigna Date: Tue, 16 Mar 2010 10:59:45 +0000 Subject: [PATCH] First implementation of make-changelog command Signed-off-by: Luca Falavigna --- dak/dak.py | 2 + dak/dakdb/update33.py | 50 ++++++++++++++ dak/make_changelog.py | 147 ++++++++++++++++++++++++++++++++++++++++++ dak/process_policy.py | 18 ++++++ dak/update_db.py | 2 +- daklib/dbconn.py | 24 +++++++ 6 files changed, 242 insertions(+), 1 deletion(-) create mode 100644 dak/dakdb/update33.py create mode 100644 dak/make_changelog.py 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..28e5a28a --- /dev/null +++ b/dak/dakdb/update33.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Implement changelogs table + +@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('CREATE TABLE changelogs (source text, version debversion, suite text, changelog text)') + 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 32, rollback issued. Error message : %s' % (str(msg)) diff --git a/dak/make_changelog.py b/dak/make_changelog.py new file mode 100644 index 00000000..e7505a1c --- /dev/null +++ b/dak/make_changelog.py @@ -0,0 +1,147 @@ +#!/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 +from daklib.queue import Upload + +################################################################################ + +suites = {'proposed-updates': 'proposedupdates', + 'oldstable-proposed-updates': 'oldproposedupdates'} + +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""" + + sys.exit(exit_code) + +def get_new_packages(suite, base_suite): + """ + Returns a dict of sources and versions where version is newer in base. + """ + + suite_sources = dict() + base_suite_sources = dict() + new_in_suite = dict() + session = DBConn().session() + + # Get source details from given suites + for i in get_all_sources_in_suite(suite, session): + suite_sources[i[0]] = i[1] + for i in get_all_sources_in_suite(base_suite, session): + base_suite_sources[i[0]] = i[1] + + # Compare if version in suite is greater than the base_suite one + for i in suite_sources.keys(): + if i not in suite_sources.keys(): + new_in_suite[i] = (suite_sources[i], 0) + elif apt_pkg.VersionCompare(suite_sources[i], base_suite_sources[i]) > 0: + new_in_suite[i] = (suite_sources[i], base_suite_sources[i]) + + return new_in_suite + +def generate_changelog(suite, source, versions): + """ + Generates changelog data returned from changelogs table + """ + query = """ + SELECT changelog FROM changelogs + WHERE suite = :suite + AND source = :source + AND version > :base + AND version <= :current + ORDER BY source, version DESC""" + session = DBConn().session() + + result = session.execute(query, {'suite': suites[suite], 'source': source, \ + 'base': versions[1], 'current': versions[0]}) + session.commit() + for r in result.fetchall(): + for i in range(0, len(r)): + print r[i] + +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')] + + for i in ['help', 'suite', 'base-suite']: + 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'] + + 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) + + new_packages = get_new_packages(suite, base_suite) + for package in sorted(new_packages.keys()): + generate_changelog(suite, package, new_packages[package]) + +if __name__ == '__main__': + main() diff --git a/dak/process_policy.py b/dak/process_policy.py index d1377b97..83ee19b5 100755 --- a/dak/process_policy.py +++ b/dak/process_policy.py @@ -65,6 +65,9 @@ def do_comments(dir, srcqueue, opref, npref, line, fn, session): continue fn(f, srcqueue, "".join(lines[1:]), session) + if len(changes_files) and not Options["No-Action"]: + store_changelog(changes_files[0], srcqueue) + if opref != npref and not Options["No-Action"]: newcomm = npref + comm[len(opref):] os.rename("%s/%s" % (dir, comm), "%s/%s" % (dir, newcomm)) @@ -113,6 +116,21 @@ def comment_reject(changes_file, srcqueue, comments, session): ################################################################################ +def store_changelog(changes_file, srcqueue): + Cnf = Config() + u = Upload() + u.pkg.changes_file = os.path.join(Cnf['Dir::Queue::Newstage'], changes_file) + u.load_changes(u.pkg.changes_file) + u.update_subst() + query = """INSERT INTO changelogs (source, version, suite, changelog) + VALUES (:source, :version, :suite, :changelog)""" + session = DBConn().session() + session.execute(query, {'source': u.pkg.changes['source'], 'version': u.pkg.changes['version'], \ + 'suite': srcqueue.queue_name, 'changelog': u.pkg.changes['changes']}) + session.commit() + +################################################################################ + def main(): global Options, Logger 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/dbconn.py b/daklib/dbconn.py index ea11a145..fbebec50 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -2212,6 +2212,30 @@ def get_source_in_suite(source, suite, session=None): __all__.append('get_source_in_suite') +@session_wrapper +def get_all_sources_in_suite(suitename, session=None): + """ + Returns list of sources and versions found in a given suite + + - B{suite} - a suite name, eg. I{unstable} + + @type suite: string + @param suite: the suite name + + @rtype: dictionary + @return: the version for I{source} in I{suite} + + """ + query = """SELECT source, version FROM source_suite + WHERE suite_name=:suitename + ORDER BY source""" + + vals = {'suitename': suitename} + + return session.execute(query, vals) + +__all__.append('get_all_sources_in_suite') + ################################################################################ @session_wrapper -- 2.39.2