]> git.decadent.org.uk Git - dak.git/commitdiff
Merge remote branch 'drkranz/make-changelog' into merge
authorJoerg Jaspert <joerg@debian.org>
Tue, 22 Jun 2010 19:22:43 +0000 (21:22 +0200)
committerJoerg Jaspert <joerg@debian.org>
Tue, 22 Jun 2010 19:22:43 +0000 (21:22 +0200)
* 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 <joerg@debian.org>
dak/dak.py
dak/dakdb/update33.py [new file with mode: 0644]
dak/make_changelog.py [new file with mode: 0755]
dak/update_db.py
daklib/queue.py

index 8d7776a5ce0a2404ac43318d38fe898c200f52c1..4ad59579aa954c4d4a0c3c6f635fd862bfc47706 100755 (executable)
@@ -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 (file)
index 0000000..9624ba6
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# coding=utf8
+
+"""
+Implement changelogs related tables
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2010 Luca Falavigna <dktrkranz@debian.org>
+@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 (executable)
index 0000000..acd23c2
--- /dev/null
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+
+"""
+Generate changelog entry between two suites
+
+@contact: Debian FTP Master <ftpmaster@debian.org>
+@copyright: 2010 Luca Falavigna <dktrkranz@debian.org>
+@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
+
+################################################################################
+
+# <bdefreese> !dinstall
+# <dak> bdefreese: I guess the next dinstall will be in 0hr 1min 35sec
+# <bdefreese> Wow I have great timing
+# <DktrKranz> dating with dinstall, part II
+# <bdefreese> heh
+# <Ganneff> dating with that monster? do you have good combat armor?
+# <bdefreese> +5 Plate :)
+# <Ganneff> not a good one then
+# <Ganneff> so you wont even manage to bypass the lesser monster in front, unchecked
+# <DktrKranz> asbesto belt
+# <Ganneff> helps only a step
+# <DktrKranz> the Ultimate Weapon: cron_turned_off
+# <bdefreese> heh
+# <Ganneff> thats debadmin limited
+# <Ganneff> no option for you
+# <DktrKranz> bdefreese: it seems ftp-masters want dinstall to sexual harass us, are you good in running?
+# <Ganneff> you can run but you can not hide
+# <bdefreese> No, I'm old and fat :)
+# <Ganneff> you can roll but you can not hide
+# <Ganneff> :)
+# <bdefreese> haha
+# <DktrKranz> 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 <suite> -b <base_suite> [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()
index 685927854c4c3b6156b73ba364263c4306d41bbc..49ea9a567a4b60deaf41add1da6f892061dcd035 100755 (executable)
@@ -45,7 +45,7 @@ from daklib.dak_exceptions import DBUpdateError
 ################################################################################
 
 Cnf = None
-required_database_schema = 32
+required_database_schema = 33
 
 ################################################################################
 
index c177602c3c55bf627af9258048419ecfc6f03861..58fdf7f3115acc306807405457aa88386cf87881 100755 (executable)
@@ -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()