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 def determine_target(u):
39 queues = [ "New", "Autobyhand", "Byhand" ]
40 if cnf.FindB("Dinstall::SecurityQueueHandling"):
41 queues += [ "Unembargo", "Embargo" ]
43 queues += [ "OldStableUpdate", "StableUpdate" ]
47 if QueueInfo[q]["is"](u):
53 ################################################################################
55 def package_to_suite(u, suite):
56 if not u.pkg.changes["distribution"].has_key(suite):
61 if not u.pkg.changes["architecture"].has_key("source"):
62 s = DBConn().session()
63 q = s.query(SrcAssociation.sa_id)
64 q = q.join(Suite).filter_by(suite_name=suite)
65 q = q.join(DBSource).filter_by(source=u.pkg.changes['source'])
66 q = q.filter_by(version=u.pkg.changes['version']).limit(1)
68 # NB: Careful, this logic isn't what you would think it is
69 # Source is already in {old-,}proposed-updates so no need to hold
70 # Instead, we don't move to the holding area, we just do an ACCEPT
78 def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, announce=None):
80 dir = cnf["Dir::Queue::%s" % queue]
82 print "Moving to %s holding area" % queue.upper()
83 u.logger.log(["Moving to %s" % queue, u.pkg.changes_file])
85 u.move_to_dir(dir, perms=perms)
87 get_or_set_queue(queue.lower()).autobuild_upload(u.pkg, dir)
89 # Check for override disparities
92 # Send accept mail, announce to lists and close bugs
93 if announce and not cnf["Dinstall::Options::No-Mail"]:
94 template = os.path.join(cnf["Dir::Templates"], announce)
96 u.Subst["__SUITE__"] = ""
97 mail_message = utils.TemplateSubst(u.Subst, template)
98 utils.send_mail(mail_message)
99 u.announce(short_summary, True)
101 ################################################################################
104 session = DBConn().session()
107 q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
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 (:package, :version)", u.pkg.changes)
130 def queue_unembargo(u, summary, short_summary, session=None):
131 return package_to_queue(u, summary, short_summary, "Unembargoed",
132 perms=0660, build=True, announce='process-unchecked.accepted')
134 ################################################################################
137 # if embargoed queues are enabled always embargo
140 def queue_embargo(u, summary, short_summary, session=None):
141 return package_to_queue(u, summary, short_summary, "Unembargoed",
142 perms=0660, build=True, announce='process-unchecked.accepted')
144 ################################################################################
146 def is_stableupdate(u):
147 return package_to_suite(u, 'proposed-updates')
149 def do_stableupdate(u, summary, short_summary, session=None):
150 return package_to_queue(u, summary, short_summary, "ProposedUpdates",
151 perms=0664, build=False, announce=None)
153 ################################################################################
155 def is_oldstableupdate(u):
156 return package_to_suite(u, 'oldstable-proposed-updates')
158 def do_oldstableupdate(u, summary, short_summary, session=None):
159 return package_to_queue(u, summary, short_summary, "OldProposedUpdates",
160 perms=0664, build=False, announce=None)
162 ################################################################################
164 def is_autobyhand(u):
169 for f in u.pkg.files.keys():
170 if u.pkg.files[f].has_key("byhand"):
173 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
174 # don't contain underscores, and ARCH doesn't contain dots.
175 # further VER matches the .changes Version:, and ARCH should be in
176 # the .changes Architecture: list.
181 (pckg, ver, archext) = f.split("_", 2)
182 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
186 ABH = cnf.SubTree("AutomaticByHandPackages")
187 if not ABH.has_key(pckg) or \
188 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
189 print "not match %s %s" % (pckg, u.pkg.changes["source"])
193 (arch, ext) = archext.split(".", 1)
194 if arch not in u.pkg.changes["architecture"]:
198 u.pkg.files[f]["byhand-arch"] = arch
199 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
201 return any_auto and all_auto
203 def do_autobyhand(u, summary, short_summary, session=None):
204 print "Attempting AUTOBYHAND."
206 for f, entry in u.pkg.files.items():
209 if not entry.has_key("byhand"):
212 if not entry.has_key("byhand-script"):
216 os.system("ls -l %s" % byhandfile)
218 result = os.system("%s %s %s %s %s" % (
219 entry["byhand-script"],
221 u.pkg.changes["version"],
222 entry["byhand-arch"],
223 os.path.abspath(u.pkg.changes_file)))
226 os.unlink(byhandfile)
229 print "Error processing %s, left as byhand." % (f)
233 do_byhand(u, summary, short_summary, session)
235 u.accept(summary, short_summary, session)
238 ################################################################################
241 for f in u.pkg.files.keys():
242 if u.pkg.files[f].has_key("byhand"):
246 def do_byhand(u, summary, short_summary, session=None):
247 return package_to_queue(u, summary, short_summary, "Byhand",
248 perms=0660, build=False, announce=None)
250 ################################################################################
253 for f in u.pkg.files.keys():
254 if u.pkg.files[f].has_key("new"):
258 def acknowledge_new(u, summary, short_summary, session=None):
261 print "Moving to NEW queue."
262 u.logger.log(["Moving to new", u.pkg.changes_file])
264 u.move_to_dir(cnf["Dir::Queue::New"], perms=0640, changesperms=0644)
266 if not cnf["Dinstall::Options::No-Mail"]:
267 print "Sending new ack."
268 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
270 u.Subst["__SUMMARY__"] = summary
271 new_ack_message = utils.TemplateSubst(u.Subst, template)
272 utils.send_mail(new_ack_message)
274 ################################################################################
276 # q-unapproved hax0ring
278 "New": { "is": is_new, "process": acknowledge_new },
279 "Autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
280 "Byhand" : { "is": is_byhand, "process": do_byhand },
281 "OldStableUpdate" : { "is": is_oldstableupdate,
282 "process": do_oldstableupdate },
283 "StableUpdate" : { "is": is_stableupdate, "process": do_stableupdate },
284 "Unembargo" : { "is": is_unembargo, "process": queue_unembargo },
285 "Embargo" : { "is": is_embargo, "process": queue_embargo },