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) ]:
55 lines = open("%s/%s" % (dir, comm)).readlines()
56 if len(lines) == 0 or lines[0] != line + "\n": continue
57 changes_files = [ x for x in os.listdir(".") if x.startswith(comm[7:]+"_")
58 and x.endswith(".changes") ]
59 changes_files = sort_changes(changes_files, session)
60 for f in changes_files:
61 print "Processing changes file: %s" % f
62 f = utils.validate_changes_file_arg(f, 0)
64 print "Couldn't validate changes file %s" % f
66 fn(f, srcqueue, "".join(lines[1:]), session)
68 if opref != npref and not Options["No-Action"]:
69 newcomm = npref + comm[len(opref):]
70 os.rename("%s/%s" % (dir, comm), "%s/%s" % (dir, newcomm))
72 ################################################################################
74 def comment_accept(changes_file, srcqueue, comments, session):
76 u.pkg.changes_file = changes_file
77 u.load_changes(changes_file)
80 if not Options["No-Action"]:
81 destqueue = get_policy_queue('newstage', session)
82 if changes_to_queue(u, srcqueue, destqueue, session):
84 Logger.log(["Policy Queue ACCEPT: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)])
86 print "E: Failed to migrate %s" % u.pkg.changes_file
88 ################################################################################
90 def comment_reject(changes_file, srcqueue, comments, session):
92 u.pkg.changes_file = changes_file
93 u.load_changes(changes_file)
96 u.rejects.append(comments)
99 bcc = "X-DAK: dak process-policy"
100 if cnf.has_key("Dinstall::Bcc"):
101 u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
103 u.Subst["__BCC__"] = bcc
105 if not Options["No-Action"]:
106 u.do_reject(manual=0, reject_message='\n'.join(u.rejects))
107 u.pkg.remove_known_changes(session=session)
111 Logger.log(["Policy Queue REJECT: %s: %s" % (srcqueue.queue_name, u.pkg.changes_file)])
114 ################################################################################
117 global Options, Logger
120 session = DBConn().session()
122 Arguments = [('h',"help","Process-Policy::Options::Help"),
123 ('n',"no-action","Process-Policy::Options::No-Action")]
125 for i in ["help", "no-action"]:
126 if not cnf.has_key("Process-Policy::Options::%s" % (i)):
127 cnf["Process-Policy::Options::%s" % (i)] = ""
129 queue_name = apt_pkg.ParseCommandLine(cnf.Cnf,Arguments,sys.argv)
131 if len(queue_name) != 1:
132 print "E: Specify exactly one policy queue"
135 queue_name = queue_name[0]
137 Options = cnf.SubTree("Process-Policy::Options")
142 if not Options["No-Action"]:
144 Logger = daklog.Logger(cnf, "process-policy")
145 except CantOpenError, e:
149 session.query(PolicyQueue)
152 pq = session.query(PolicyQueue).filter_by(queue_name=queue_name).one()
153 except NoResultFound:
154 print "E: Cannot find policy queue %s" % queue_name
157 commentsdir = os.path.join(pq.path, 'COMMENTS')
158 # The comments stuff relies on being in the right directory
160 do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK", comment_accept, session)
161 do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK", comment_reject, session)
164 ################################################################################
166 if __name__ == '__main__':