From: Joerg Jaspert Date: Tue, 14 Apr 2009 22:55:45 +0000 (+0200) Subject: NEW X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a59ca3145f204083ffcf5edf322d5b6ee2c4e0f8;p=dak NEW stop storing NEW comments in .dak files and instead put them into the database Signed-off-by: Joerg Jaspert --- diff --git a/dak/dakdb/update11.py b/dak/dakdb/update11.py new file mode 100755 index 00000000..53f1572a --- /dev/null +++ b/dak/dakdb/update11.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# coding=utf8 + +""" +Adding process-new comments to the DB + +@contact: Debian FTP Master +@copyright: 2009 Joerg Jaspert +@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 +import time + +################################################################################ + +def do_update(self): + print "Adding process-new comments to the DB" + + try: + c = self.db.cursor() + c.execute("""CREATE TABLE new_comments ( + id SERIAL PRIMARY KEY NOT NULL, + package TEXT NOT NULL, + version TEXT NOT NULL, + comment TEXT NOT NULL, + author TEXT NOT NULL + )""") + + c.execute("GRANT SELECT ON new_comments TO ftptrainee;") + c.execute("GRANT INSERT ON new_comments TO ftptrainee;") + c.execute("GRANT UPDATE ON new_comments TO ftptrainee;") + c.execute("GRANT SELECT ON new_comments TO ftpteam;") + c.execute("GRANT INSERT ON new_comments TO ftpteam;") + c.execute("GRANT UPDATE ON new_comments TO ftpteam;") + c.execute("GRANT ALL ON new_comments TO ftpmaster;") + + c.execute("UPDATE config SET value = '11' WHERE name = 'db_revision'") + self.db.commit() + + except psycopg2.ProgrammingError, msg: + self.db.rollback() + raise DBUpdateError, "Unable to apply process-new comments update, rollback issued. Error message : %s" % (str(msg)) diff --git a/dak/process_new.py b/dak/process_new.py index 9ecfcdc6..a4cb0171 100755 --- a/dak/process_new.py +++ b/dak/process_new.py @@ -5,6 +5,7 @@ @contact: Debian FTP Master @copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup +@copyright: 2009 Joerg Jaspert @license: GNU General Public License version 2 or later """ # This program is free software; you can redistribute it and/or modify @@ -219,7 +220,7 @@ def sort_changes(changes_files): mtime = os.stat(d["filename"])[stat.ST_MTIME] if mtime < oldest: oldest = mtime - have_note += (d.has_key("process-new note")) + have_note += (database.has_new_comment(d["source"], d["version"]) per_source[source]["oldest"] = oldest if not have_note: per_source[source]["note_state"] = 0; # none @@ -301,11 +302,10 @@ def print_new (new, indexed, file=sys.stdout): line = "%-20s %-20s %-20s" % (pkg, priority, section) line = line.strip()+'\n' file.write(line) - note = Upload.pkg.changes.get("process-new note") - if note: - print "*"*75 - print note - print "*"*75 + note = database.get_new_comments(Upload.pkg.changes.get("source")) + if len(note) > 0: + for line in note: + print line return broken, note ################################################################################ @@ -494,8 +494,7 @@ def edit_note(note): elif answer == 'Q': end() sys.exit(0) - Upload.pkg.changes["process-new note"] = note - Upload.dump_vars(Cnf["Dir::Queue::New"]) + database.add_new_comment(Upload.pkg.changes["source"], Upload.pkg.changes["version"], note, utils.whoami()) ################################################################################ @@ -692,13 +691,13 @@ def do_new(): os.unlink(Upload.pkg.changes_file[:-8]+".dak") done = 1 elif answer == 'N': - edit_note(changes.get("process-new note", "")) + edit_note(database.get_new_comments(changes.get("source", ""))) elif answer == 'P': prod_maintainer() elif answer == 'R': confirm = utils.our_raw_input("Really clear note (y/N)? ").lower() if confirm == "y": - del changes["process-new note"] + database.delete_new_comments(changes.get("source"), changes.get("version")) elif answer == 'S': done = 1 elif answer == 'Q': diff --git a/dak/queue_report.py b/dak/queue_report.py index cc59a9f8..341e0ff3 100755 --- a/dak/queue_report.py +++ b/dak/queue_report.py @@ -38,6 +38,7 @@ import copy, glob, os, stat, sys, time import apt_pkg import cgi from daklib import queue +from daklib import database from daklib import utils from daklib.dak_exceptions import * @@ -45,6 +46,7 @@ Cnf = None Upload = None direction = [] row_number = 0 +projectB = None ################################################################################ @@ -327,7 +329,7 @@ def process_changes_files(changes_files, type, log): else: if mtime < oldest: oldest = mtime - have_note += (d.has_key("process-new note")) + have_note += (database.has_new_comment(d["source"], d["version"]) per_source[source]["oldest"] = oldest if not have_note: per_source[source]["note_state"] = 0; # none @@ -531,6 +533,7 @@ def main(): usage() Upload = queue.Upload(Cnf) + projectB = Upload.projectB if Cnf.has_key("Queue-Report::Options::New"): header() diff --git a/daklib/database.py b/daklib/database.py index 93d9ad53..b66f3d83 100755 --- a/daklib/database.py +++ b/daklib/database.py @@ -4,8 +4,9 @@ @group readonly: get_suite_id, get_section_id, get_priority_id, get_override_type_id, get_architecture_id, get_archive_id, get_component_id, get_location_id, get_source_id, get_suite_version, get_files_id, get_maintainer, get_suites, - get_suite_architectures + get_suite_architectures, get_new_comments, has_new_comment @group read/write: get_or_set*, set_files_id +@group writeonly: add_new_comment, delete_new_comments @contact: Debian FTP Master @copyright: 2000, 2001, 2002, 2003, 2004, 2006 James Troup @@ -838,6 +839,87 @@ def get_suites(pkgname, src=False): ################################################################################ +def get_new_comments(package): + """ + Returns all the possible comments attached to C{package} in NEW. All versions. + + @type package: string + @param package: name of the package + + @rtype: list + @return: list of strings containing comments for all versions from all authors for package + """ + + comments = [] + query = projectB.query(""" SELECT version, comment, author + FROM new_comments + WHERE package = '%s' """ % (package)) + + for row in query.getresult(): + comments.append("\nAuthor: %s\nVersion: %s\n\n%s\n" % (row[2], row[0], row[1])) + comments.append("-"*72) + + return comments + +def has_new_comment(package, version): + """ + Returns true if the given combination of C{package}, C{version} has a comment. + + @type package: string + @param package: name of the package + + @type version: string + @param version: package version + + @rtype: boolean + @return: true/false + """ + + exists = projectB.query("""SELECT 1 FROM new_comments + WHERE package='%s' + AND version='%s' + LIMIT 1""" + % (package, version) ).getresult() + + if not exists: + return false + else: + return true + +def add_new_comment(package, version, comment, author): + """ + Add a new comment for C{package}, C{version} written by C{author} + + @type package: string + @param package: name of the package + + @type version: string + @param version: package version + + @type comment: string + @param comment: the comment + + @type author: string + @param author: the authorname + """ + + projectB.query(""" INSERT INTO new_comments (package, version, comment, author) + VALUES ('%s', '%s', '%s', '%s') + """ % (package, version, comment, author) ) + + return + +def delete_new_comments(package, version): + """ + Delete a comment for C{package}, C{version}, if one exists + """ + + projectB.query(""" DELETE FROM new_comments + WHERE package = '%s' AND version = '%s' + """ % (package, version)) + return + +################################################################################ def copy_temporary_contents(package, version, arch, deb, reject): """ copy the previously stored contents from the temp table to the permanant one