提交 a59ca314 编写于 作者: J Joerg Jaspert

NEW

stop storing NEW comments in .dak files and instead put them into the
database
Signed-off-by: NJoerg Jaspert <joerg@debian.org>
上级 886228a3
#!/usr/bin/env python
# coding=utf8
"""
Adding process-new comments to the DB
@contact: Debian FTP Master <ftpmaster@debian.org>
@copyright: 2009 Joerg Jaspert <joerg@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
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))
......@@ -5,6 +5,7 @@
@contact: Debian FTP Master <ftpmaster@debian.org>
@copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
@copyright: 2009 Joerg Jaspert <joerg@debian.org>
@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':
......
......@@ -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()
......
......@@ -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 <ftpmaster@debian.org>
@copyright: 2000, 2001, 2002, 2003, 2004, 2006 James Troup <james@nocrew.org>
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册