2 # vim:set et ts=4 sw=4:
4 """ Handles packages from policy queues
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
8 @copyright: 2009 Joerg Jaspert <joerg@debian.org>
9 @copyright: 2009 Frank Lichtenheld <djpig@debian.org>
10 @copyright: 2009 Mark Hymers <mhy@debian.org>
11 @license: GNU General Public License version 2 or later
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ################################################################################
29 # <mhy> So how do we handle that at the moment?
30 # <stew> Probably incorrectly.
32 ################################################################################
39 from daklib.dbconn import *
40 from daklib.queue import *
41 from daklib import daklog
42 from daklib import utils
43 from daklib.dak_exceptions import CantOpenError, AlreadyLockedError, CantGetLockError
44 from daklib.config import Config
45 from daklib.changesutils import *
51 ################################################################################
53 def do_comments(dir, srcqueue, opref, npref, line, fn, session):
54 for comm in [ x for x in os.listdir(dir) if x.startswith(opref) ]:
56 lines = open("%s/%s" % (dir, comm)).readlines()
57 if len(lines) == 0 or lines[0] != line + "\n": continue
58 changes_files = [ x for x in os.listdir(".") if x.startswith(comm[7:]+"_")
59 and x.endswith(".changes") ]
61 changes_files = sort_changes(changes_files, session)
62 for f in changes_files:
63 print " Changes file: %s" % f
64 f = utils.validate_changes_file_arg(f, 0)
66 print "Couldn't validate changes file %s" % f
69 fn(f, srcqueue, "".join(lines[1:]), session)
71 if opref != npref and not Options["No-Action"]:
72 newcomm = npref + comm[len(opref):]
73 os.rename("%s/%s" % (dir, comm), "%s/%s" % (dir, newcomm))
75 ################################################################################
77 def comment_accept(changes_file, srcqueue, comments, session):
78 print "*** Accept for %s (%s)" % (changes_file, comments)
81 u.pkg.changes_file = changes_file
82 u.load_changes(changes_file)
85 if not Options["No-Action"]:
86 destqueue = get_policy_queue('newstage', session)
87 changes_to_queue(u, srcqueue, destqueue, session)
89 Logger.log(["Policy Queue Accept: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)])
91 ################################################################################
93 def comment_reject(changes_file, srcqueue, comments, session):
94 print "Reject for %s (%s)" % (changes_file, comments)
97 u.pkg.changes_file = changes_file
98 u.load_changes(changes_file)
101 u.rejects.append(comments)
103 print "REJECT\n" + '\n'.join(u.rejects)
104 if not Options["No-Action"]:
105 u.do_reject(manual=0, reject_message='\n'.join(u.rejects))
106 u.pkg.remove_known_changes(session=session)
108 Logger.log(["Policy Queue Reject: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)])
111 ################################################################################
114 global Options, Logger
117 session = DBConn().session()
119 Arguments = [('h',"help","Process-Policy::Options::Help"),
120 ('n',"no-action","Process-Policy::Options::No-Action")]
122 for i in ["help", "no-action"]:
123 if not cnf.has_key("Process-Policy::Options::%s" % (i)):
124 cnf["Process-Policy::Options::%s" % (i)] = ""
126 queue_name = apt_pkg.ParseCommandLine(cnf.Cnf,Arguments,sys.argv)
128 if len(queue_name) != 1:
129 print "E: Specify exactly one policy queue"
132 queue_name = queue_name[0]
134 Options = cnf.SubTree("Process-Policy::Options")
139 if not Options["No-Action"]:
141 Logger = daklog.Logger(cnf, "process-new")
142 except CantOpenError, e:
146 session.query(PolicyQueue)
149 pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one()
150 commentsdir = os.path.join(pq.path, 'COMMENTS')
151 # The comments stuff relies on being in the right directory
153 do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session)
154 do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session)
155 except NoResultFound:
156 print "E: Cannot find policy queue %s" % queue_name
159 ################################################################################
161 if __name__ == '__main__':