X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdatabase.py;h=826e0441954ce8515968e07ee010e15900be840f;hb=d733acb0b123077f9c1f899130ef24ed4d74bc7a;hp=a995378b3db78116c967bd205a9086e828c9ef5d;hpb=48e5e5ee12f7c36e3272ec8d3dc0d6c43625d984;p=dak.git diff --git a/daklib/database.py b/daklib/database.py index a995378b..826e0441 100755 --- a/daklib/database.py +++ b/daklib/database.py @@ -34,6 +34,7 @@ import sys import time import types import utils +import pg from binary import Binary ################################################################################ @@ -858,14 +859,15 @@ def get_new_comments(package): """ % (package)) for row in query.getresult(): - comments.append("\nAuthor: %s\nVersion: %s\nTimestamp: %s\n\n%s\n" % (row[2], row[0], row[4], row[1])) + comments.append("\nAuthor: %s\nVersion: %s\nTimestamp: %s\n\n%s\n" % (row[2], row[0], row[3], row[1])) comments.append("-"*72) return comments -def has_new_comment(package, version): +def has_new_comment(package, version, ignore_trainee=False): """ Returns true if the given combination of C{package}, C{version} has a comment. + If C{ignore_trainee} is true, comments from a trainee are ignored. @type package: string @param package: name of the package @@ -873,22 +875,30 @@ def has_new_comment(package, version): @type version: string @param version: package version + @type version: boolean + @param version: ignore trainee comments + @rtype: boolean @return: true/false """ + trainee="" + if ignore_trainee: + trainee='AND trainee=false' + exists = projectB.query("""SELECT 1 FROM new_comments WHERE package='%s' AND version='%s' + %s LIMIT 1""" - % (package, version) ).getresult() + % (package, version, trainee) ).getresult() if not exists: return False else: return True -def add_new_comment(package, version, comment, author): +def add_new_comment(package, version, comment, author, trainee=False): """ Add a new comment for C{package}, C{version} written by C{author} @@ -903,11 +913,14 @@ def add_new_comment(package, version, comment, author): @type author: string @param author: the authorname + + @type trainee: boolean + @param trainee: trainee comment """ - projectB.query(""" INSERT INTO new_comments (package, version, comment, author) - VALUES ('%s', '%s', '%s', '%s') - """ % (package, version, comment, author) ) + projectB.query(""" INSERT INTO new_comments (package, version, comment, author, trainee) + VALUES ('%s', '%s', '%s', '%s', '%s') + """ % (package, version, pg.escape_string(comment), pg.escape_string(author), trainee)) return @@ -921,6 +934,16 @@ def delete_new_comments(package, version): """ % (package, version)) return +def delete_all_new_comments(package): + """ + Delete all comments for C{package}, if they exist + """ + + projectB.query(""" DELETE FROM new_comments + WHERE package = '%s' + """ % (package)) + return + ################################################################################ def copy_temporary_contents(package, version, arch, deb, reject): """