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
30 from daklib import utils
31 from daklib.dbconn import *
32 from daklib.config import Config
34 ###############################################################################
36 # q-unapproved hax0ring
38 "New": { "is": is_new, "process": acknowledge_new },
39 "Autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
40 "Byhand" : { "is": is_byhand, "process": do_byhand },
41 "OldStableUpdate" : { "is": is_oldstableupdate,
42 "process": do_oldstableupdate },
43 "StableUpdate" : { "is": is_stableupdate, "process": do_stableupdate },
44 "Unembargo" : { "is": is_unembargo, "process": queue_unembargo },
45 "Embargo" : { "is": is_embargo, "process": queue_embargo },
48 def determine_target(u):
51 queues = [ "New", "Autobyhand", "Byhand" ]
52 if cnf.FindB("Dinstall::SecurityQueueHandling"):
53 queues += [ "Unembargo", "Embargo" ]
55 queues += [ "OldStableUpdate", "StableUpdate" ]
59 if QueueInfo[q]["is"](u):
65 ################################################################################
67 def package_to_suite(u, suite):
68 if not u.pkg.changes["distribution"].has_key(suite):
73 if not u.pkg.changes["architecture"].has_key("source"):
74 s = DBConn().session()
75 q = s.query(SrcAssociation.sa_id)
76 q = q.join(Suite).filter_by(suite_name=suite)
77 q = q.join(DBSource).filter_by(source=u.pkg.changes['source'])
78 q = q.filter_by(version=u.pkg.changes['version']).limit(1)
80 # NB: Careful, this logic isn't what you would think it is
81 # Source is already in {old-,}proposed-updates so no need to hold
82 # Instead, we don't move to the holding area, we just do an ACCEPT
90 def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, announce=None):
92 dir = cnf["Dir::Queue::%s" % queue]
94 print "Moving to %s holding area" % queue.upper()
95 u.logger.log(["Moving to %s" % queue, u.pkg.changes_file])
97 u.move_to_dir(dir, perms=perms)
99 get_or_set_queue(queue.lower()).autobuild_upload(u.pkg, dir)
101 # Check for override disparities
104 # Send accept mail, announce to lists and close bugs
105 if announce and not cnf["Dinstall::Options::No-Mail"]:
106 template = os.path.join(cnf["Dir::Templates"], announce)
108 u.Subst["__SUITE__"] = ""
109 mail_message = utils.TemplateSubst(u.Subst, template)
110 utils.send_mail(mail_message)
111 u.announce(short_summary, True)
113 ################################################################################
116 session = DBConn().session()
119 q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
125 os.chdir(cnf["Dir::Queue::Disembargo"])
131 if u.pkg.directory == disdir:
132 if u.pkg.changes["architecture"].has_key("source"):
133 session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)", u.pkg.changes)
142 def queue_unembargo(u, summary, short_summary):
143 return package_to_queue(u, summary, short_summary, "Unembargoed",
144 perms=0660, build=True, announce='process-unchecked.accepted')
146 ################################################################################
149 # if embargoed queues are enabled always embargo
152 def queue_embargo(u, summary, short_summary):
153 return package_to_queue(u, summary, short_summary, "Unembargoed",
154 perms=0660, build=True, announce='process-unchecked.accepted')
156 ################################################################################
158 def is_stableupdate(u):
159 return package_to_suite(u, 'proposed-updates')
161 def do_stableupdate(u, summary, short_summary):
162 return package_to_queue(u, summary, short_summary, "ProposedUpdates",
163 perms=0664, build=False, announce=None)
165 ################################################################################
167 def is_oldstableupdate(u):
168 return package_to_suite(u, 'oldstable-proposed-updates')
170 def do_oldstableupdate(u, summary, short_summary):
171 return package_to_queue(u, summary, short_summary, "OldProposedUpdates",
172 perms=0664, build=False, announce=None)
174 ################################################################################
176 def is_autobyhand(u):
181 for f in u.pkg.files.keys():
182 if u.pkg.files[f].has_key("byhand"):
185 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
186 # don't contain underscores, and ARCH doesn't contain dots.
187 # further VER matches the .changes Version:, and ARCH should be in
188 # the .changes Architecture: list.
193 (pckg, ver, archext) = f.split("_", 2)
194 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
198 ABH = cnf.SubTree("AutomaticByHandPackages")
199 if not ABH.has_key(pckg) or \
200 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
201 print "not match %s %s" % (pckg, u.pkg.changes["source"])
205 (arch, ext) = archext.split(".", 1)
206 if arch not in u.pkg.changes["architecture"]:
210 u.pkg.files[f]["byhand-arch"] = arch
211 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
213 return any_auto and all_auto
215 def do_autobyhand(u, summary, short_summary):
216 print "Attempting AUTOBYHAND."
218 for f, entry in u.pkg.files.items():
221 if not entry.has_key("byhand"):
224 if not entry.has_key("byhand-script"):
228 os.system("ls -l %s" % byhandfile)
230 result = os.system("%s %s %s %s %s" % (
231 entry["byhand-script"],
233 u.pkg.changes["version"],
234 entry["byhand-arch"],
235 os.path.abspath(u.pkg.changes_file)))
238 os.unlink(byhandfile)
241 print "Error processing %s, left as byhand." % (f)
245 do_byhand(u, summary, short_summary)
247 u.accept(summary, short_summary)
249 # XXX: We seem to be missing a u.remove() here
250 # This might explain why we get byhand leftovers in unchecked - mhy
252 ################################################################################
255 for f in u.pkg.files.keys():
256 if u.pkg.files[f].has_key("byhand"):
260 def do_byhand(u, summary, short_summary):
261 return package_to_queue(u, summary, short_summary, "Byhand",
262 perms=0660, build=False, announce=None)
264 ################################################################################
267 for f in u.pkg.files.keys():
268 if u.pkg.files[f].has_key("new"):
272 def acknowledge_new(u, summary, short_summary):
275 print "Moving to NEW holding area."
276 u.logger.log(["Moving to new", u.pkg.changes_file])
278 u.move_to_dir(cnf["Dir::Queue::New"], perms=0640, changesperms=0644)
280 if not Options["No-Mail"]:
281 print "Sending new ack."
282 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
284 u.Subst["__SUMMARY__"] = summary
285 new_ack_message = utils.TemplateSubst(u.Subst, template)
286 utils.send_mail(new_ack_message)