From: Mark Hymers Date: Sun, 29 Nov 2009 18:30:34 +0000 (+0000) Subject: add initial version of process-policy X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ca2e460d9fa00978b8eecd880b9dd7efcecf493;p=dak add initial version of process-policy Signed-off-by: Mark Hymers --- diff --git a/dak/process_policy.py b/dak/process_policy.py new file mode 100755 index 00000000..824df26f --- /dev/null +++ b/dak/process_policy.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# vim:set et ts=4 sw=4: + +""" Handles packages from policy queues + +@contact: Debian FTP Master +@copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup +@copyright: 2009 Joerg Jaspert +@copyright: 2009 Frank Lichtenheld +@copyright: 2009 Mark Hymers +@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 + +################################################################################ + +# So how do we handle that at the moment? +# Probably incorrectly. + +################################################################################ + +import os +import copy +import sys +import apt_pkg + +from daklib.dbconn import * +from daklib.queue import * +from daklib import daklog +from daklib import utils +from daklib.dak_exceptions import CantOpenError, AlreadyLockedError, CantGetLockError +from daklib.config import Config +from daklib.changesutils import * + +# Globals +Options = None +Logger = None + +################################################################################ + +def do_comments(dir, srcqueue, opref, npref, line, fn, session): + for comm in [ x for x in os.listdir(dir) if x.startswith(opref) ]: + print comm + lines = open("%s/%s" % (dir, comm)).readlines() + if len(lines) == 0 or lines[0] != line + "\n": continue + changes_files = [ x for x in os.listdir(".") if x.startswith(comm[7:]+"_") + and x.endswith(".changes") ] + print changes_files + changes_files = sort_changes(changes_files, session) + for f in changes_files: + print " Changes file: %s" % f + f = utils.validate_changes_file_arg(f, 0) + if not f: + print "Couldn't validate changes file %s" % f + continue + print "\n" + f + fn(f, srcqueue, "".join(lines[1:]), session) + + if opref != npref and not Options["No-Action"]: + newcomm = npref + comm[len(opref):] + os.rename("%s/%s" % (dir, comm), "%s/%s" % (dir, newcomm)) + +################################################################################ + +def comment_accept(changes_file, srcqueue, comments, session): + print "*** Accept for %s (%s)" % (changes_file, comments) + + u = Upload() + u.pkg.changes_file = changes_file + u.load_changes(changes_file) + u.update_subst() + + if not Options["No-Action"]: + destqueue = get_policy_queue('newstage', session) + changes_to_queue(upload, srcqueue, destqueue, session) + + Logger.log(["Policy Queue Accept: %s: %s" % (srcqueue.queue_name, upload.pkg.changes_file)]) + +################################################################################ + +def comment_reject(changes_file, srcqueue, comments, session): + print "Reject for %s (%s)" % (changes_file, comments) + + u = Upload() + u.pkg.changes_file = changes_file + u.load_changes(changes_file) + u.update_subst() + + u.rejects.append(comments) + + print "REJECT\n" + '\n'.join(u.rejects) + if not Options["No-Action"]: + u.do_reject(manual=0, reject_message='\n'.join(u.rejects)) + u.pkg.remove_known_changes(session=session) + + Logger.log(["Policy Queue Reject: %s: %s" % (srcqueue.queue_name, upload.pkg.changes_file)]) + + +################################################################################ + +def main(): + global Options, Logger + + cnf = Config() + session = DBConn().session() + + Arguments = [('h',"help","Process-Policy::Options::Help"), + ('n',"no-action","Process-Policy::Options::No-Action")] + + for i in ["help", "no-action"]: + if not cnf.has_key("Process-Policy::Options::%s" % (i)): + cnf["Process-Policy::Options::%s" % (i)] = "" + + queue_name = apt_pkg.ParseCommandLine(cnf.Cnf,Arguments,sys.argv) + + if len(queue_name) != 1: + print "E: Specify exactly one policy queue" + sys.exit(1) + + queue_name = queue_name[0] + + Options = cnf.SubTree("Process-Policy::Options") + + if Options["Help"]: + usage() + + if not Options["No-Action"]: + try: + Logger = daklog.Logger(cnf, "process-new") + except CantOpenError, e: + Logger = None + + # Find policy queue + session.query(PolicyQueue) + + try: + pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one() + commentsdir = os.path.join(pq.path, 'COMMENTS') + # The comments stuff relies on being in the right directory + os.chdir(pq.path) + do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session) + do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session) + except NoResultFound: + print "E: Cannot find policy queue %s" % queue_name + sys.exit(1) + +################################################################################ + +if __name__ == '__main__': + main()