5 Utility functions for process-upload
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2000, 2001, 2002, 2003, 2004, 2005, 2006 James Troup <james@nocrew.org>
9 @copyright: 2009 Joerg Jaspert <joerg@debian.org>
10 @copyright: 2009 Mark Hymers <mhy@debian.org>
11 @license: GNU General Public License version 2 or later
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 from shutil import copyfile
31 from daklib import utils
32 from daklib.dbconn import *
33 from daklib.config import Config
35 ################################################################################
37 def package_to_suite(u, suite_name, session):
38 if suite_name not in u.pkg.changes["distribution"]:
41 if 'source' in u.pkg.changes["architecture"]:
44 q = session.query(Suite).filter_by(suite_name = suite_name). \
45 filter(Suite.sources.any( \
46 source = u.pkg.changes['source'], \
47 version = u.pkg.changes['version']))
49 # NB: Careful, this logic isn't what you would think it is
50 # Source is already in the target suite so no need to go to policy
51 # Instead, we don't move to the policy area, we just do an ACCEPT
57 def package_to_queue(u, summary, short_summary, queue, chg, session, announce=None):
61 print "Moving to %s policy queue" % queue.queue_name.upper()
62 u.logger.log(["Moving to %s" % queue.queue_name, u.pkg.changes_file])
64 u.move_to_queue(queue)
65 chg.in_queue_id = queue.policy_queue_id
68 # send to build queues
69 if queue.send_to_build_queues:
70 for suite_name in u.pkg.changes["distribution"].keys():
71 suite = get_suite(suite_name, session)
72 for q in suite.copy_queues:
73 q.add_changes_from_policy_queue(queue, chg)
77 # Check for override disparities
80 # Send accept mail, announce to lists and close bugs
82 template = os.path.join(cnf["Dir::Templates"], announce)
84 mail_message = utils.TemplateSubst(u.Subst, template)
85 utils.send_mail(mail_message)
86 u.announce(short_summary, True)
88 ################################################################################
91 session = DBConn().session()
94 # If we dont have the disembargo queue we are not on security and so not interested
95 # in doing any security queue handling
96 if not get_policy_queue("disembargo"):
99 # If we already are in newstage, then it means this just got passed through and accepted
100 # by a security team member. Don't try to accept it for disembargo again
101 dbc = get_dbchange(u.pkg.changes_file, session)
102 if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
105 q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version",
106 {'source': u.pkg.changes["source"],
107 'version': u.pkg.changes["version"]})
113 os.chdir(cnf["Dir::Queue::Disembargo"])
119 if u.pkg.directory == disdir:
120 if u.pkg.changes["architecture"].has_key("source"):
121 session.execute("INSERT INTO disembargo (package, version) VALUES (:source, :version)",
122 {'source': u.pkg.changes["source"],
123 'version': u.pkg.changes["version"]})
132 def do_unembargo(u, summary, short_summary, chg, session=None):
133 polq=get_policy_queue('disembargo')
134 package_to_queue(u, summary, short_summary,
138 #################################################################################
141 # if we are the security archive, we always have a embargo queue and its the
142 # last in line, so if that exists, return true
143 # Of course do not return true when we accept from out of newstage, as that means
144 # it just left embargo and we want it in the archive
145 if get_policy_queue('embargo'):
146 session = DBConn().session()
147 dbc = get_dbchange(u.pkg.changes_file, session)
148 if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
153 def do_embargo(u, summary, short_summary, chg, session=None):
154 polq=get_policy_queue('embargo')
155 package_to_queue(u, summary, short_summary,
159 ################################################################################
161 def is_autobyhand(u):
166 for f in u.pkg.files.keys():
167 if u.pkg.files[f].has_key("byhand"):
170 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
171 # don't contain underscores, and ARCH doesn't contain dots.
172 # further VER matches the .changes Version:, and ARCH should be in
173 # the .changes Architecture: list.
178 (pckg, ver, archext) = f.split("_", 2)
179 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
183 ABH = cnf.SubTree("AutomaticByHandPackages")
184 if not ABH.has_key(pckg) or \
185 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
186 print "not match %s %s" % (pckg, u.pkg.changes["source"])
190 (arch, ext) = archext.split(".", 1)
191 if arch not in u.pkg.changes["architecture"]:
195 u.pkg.files[f]["byhand-arch"] = arch
196 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
198 return any_auto and all_auto
200 def do_autobyhand(u, summary, short_summary, chg, session):
201 print "Attempting AUTOBYHAND."
203 for f, entry in u.pkg.files.items():
206 if not entry.has_key("byhand"):
209 if not entry.has_key("byhand-script"):
213 os.system("ls -l %s" % byhandfile)
215 result = os.system("%s %s %s %s %s" % (
216 entry["byhand-script"],
218 u.pkg.changes["version"],
219 entry["byhand-arch"],
220 os.path.abspath(u.pkg.changes_file)))
223 os.unlink(byhandfile)
226 print "Error processing %s, left as byhand." % (f)
230 do_byhand(u, summary, short_summary, chg, session)
232 u.accept(summary, short_summary, session)
235 ################################################################################
238 for f in u.pkg.files.keys():
239 if u.pkg.files[f].has_key("byhand"):
243 def do_byhand(u, summary, short_summary, chg, session):
244 return package_to_queue(u, summary, short_summary,
245 get_policy_queue('byhand'), chg, session,
248 ################################################################################
251 for f in u.pkg.files.keys():
252 if u.pkg.files[f].has_key("new"):
256 def acknowledge_new(u, summary, short_summary, chg, session):
259 print "Moving to NEW queue."
260 u.logger.log(["Moving to new", u.pkg.changes_file])
262 q = get_policy_queue('new', session)
265 chg.in_queue_id = q.policy_queue_id
269 print "Sending new ack."
270 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
272 u.Subst["__SUMMARY__"] = summary
273 new_ack_message = utils.TemplateSubst(u.Subst, template)
274 utils.send_mail(new_ack_message)
276 ################################################################################
278 # FIXME: queues should be able to get autobuild
279 # the current logic doesnt allow this, as buildd stuff is AFTER accept...
280 # embargo/disembargo use a workaround due to this
281 # q-unapproved hax0ring
283 "new": { "is": is_new, "process": acknowledge_new },
284 "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
285 "byhand" : { "is": is_byhand, "process": do_byhand },
286 "embargoed" : { "is": is_embargo, "process": do_embargo },
287 "unembargoed" : { "is": is_unembargo, "process": do_unembargo },
290 def determine_target(u):
293 # Statically handled queues
296 for q in ["autobyhand", "byhand", "new", "unembargoed", "embargoed"]:
297 if QueueInfo[q]["is"](u):
303 ###############################################################################