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
28 from daklib.config import Config
30 ###############################################################################
32 # q-unapproved hax0ring
34 "New": { "is": is_new, "process": acknowledge_new },
35 "Autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
36 "Byhand" : { "is": is_byhand, "process": do_byhand },
37 "OldStableUpdate" : { "is": is_oldstableupdate,
38 "process": do_oldstableupdate },
39 "StableUpdate" : { "is": is_stableupdate, "process": do_stableupdate },
40 "Unembargo" : { "is": is_unembargo, "process": queue_unembargo },
41 "Embargo" : { "is": is_embargo, "process": queue_embargo },
44 def determine_target(u):
47 queues = [ "New", "Autobyhand", "Byhand" ]
48 if cnf.FindB("Dinstall::SecurityQueueHandling"):
49 queues += [ "Unembargo", "Embargo" ]
51 queues += [ "OldStableUpdate", "StableUpdate" ]
55 if QueueInfo[q]["is"](u):
61 ################################################################################
63 def package_to_suite(u, suite):
64 if not u.pkg.changes["distribution"].has_key(suite):
69 if not u.pkg.changes["architecture"].has_key("source"):
70 s = DBConn().session()
71 q = s.query(SrcAssociation.sa_id)
72 q = q.join(Suite).filter_by(suite_name=suite)
73 q = q.join(DBSource).filter_by(source=u.pkg.changes['source'])
74 q = q.filter_by(version=u.pkg.changes['version']).limit(1)
76 # NB: Careful, this logic isn't what you would think it is
77 # Source is already in {old-,}proposed-updates so no need to hold
78 # Instead, we don't move to the holding area, we just do an ACCEPT
86 def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, announce=None):
88 dir = cnf["Dir::Queue::%s" % queue]
90 print "Moving to %s holding area" % queue.upper()
91 Logger.log(["Moving to %s" % queue, u.pkg.changes_file])
93 u.pkg.write_dot_dak(dir)
94 u.move_to_dir(dir, perms=perms)
96 get_or_set_queue(queue.lower()).autobuild_upload(u.pkg, dir)
98 # Check for override disparities
101 # Send accept mail, announce to lists and close bugs
102 if announce and not cnf["Dinstall::Options::No-Mail"]:
103 template = os.path.join(cnf["Dir::Templates"], announce)
105 u.Subst["__SUITE__"] = ""
106 mail_message = utils.TemplateSubst(u.Subst, template)
107 utils.send_mail(mail_message)
108 u.announce(short_summary, True)
110 ################################################################################
113 session = DBConn().session()
116 q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
122 os.chdir(cnf["Dir::Queue::Disembargo"])
128 if u.pkg.directory == disdir:
129 if u.pkg.changes["architecture"].has_key("source"):
130 if not Options["No-Action"]:
131 session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)", u.pkg.changes)
140 def queue_unembargo(u, summary, short_summary):
141 return package_to_queue(u, summary, short_summary, "Unembargoed",
142 perms=0660, build=True, announce='process-unchecked.accepted')
144 ################################################################################
147 # if embargoed queues are enabled always embargo
150 def queue_embargo(u, summary, short_summary):
151 return package_to_queue(u, summary, short_summary, "Unembargoed",
152 perms=0660, build=True, announce='process-unchecked.accepted')
154 ################################################################################
156 def is_stableupdate(u):
157 return package_to_suite(u, 'proposed-updates')
159 def do_stableupdate(u, summary, short_summary):
160 return package_to_queue(u, summary, short_summary, "ProposedUpdates",
161 perms=0664, build=False, announce=None)
163 ################################################################################
165 def is_oldstableupdate(u):
166 return package_to_suite(u, 'oldstable-proposed-updates')
168 def do_oldstableupdate(u, summary, short_summary):
169 return package_to_queue(u, summary, short_summary, "OldProposedUpdates",
170 perms=0664, build=False, announce=None)
172 ################################################################################
174 def is_autobyhand(u):
179 for f in u.pkg.files.keys():
180 if u.pkg.files[f].has_key("byhand"):
183 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
184 # don't contain underscores, and ARCH doesn't contain dots.
185 # further VER matches the .changes Version:, and ARCH should be in
186 # the .changes Architecture: list.
191 (pckg, ver, archext) = f.split("_", 2)
192 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
196 ABH = cnf.SubTree("AutomaticByHandPackages")
197 if not ABH.has_key(pckg) or \
198 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
199 print "not match %s %s" % (pckg, u.pkg.changes["source"])
203 (arch, ext) = archext.split(".", 1)
204 if arch not in u.pkg.changes["architecture"]:
208 u.pkg.files[f]["byhand-arch"] = arch
209 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
211 return any_auto and all_auto
213 def do_autobyhand(u, summary, short_summary):
214 print "Attempting AUTOBYHAND."
216 for f, entry in u.pkg.files.items():
219 if not entry.has_key("byhand"):
222 if not entry.has_key("byhand-script"):
226 os.system("ls -l %s" % byhandfile)
228 result = os.system("%s %s %s %s %s" % (
229 entry["byhand-script"],
231 u.pkg.changes["version"],
232 entry["byhand-arch"],
233 os.path.abspath(u.pkg.changes_file)))
236 os.unlink(byhandfile)
239 print "Error processing %s, left as byhand." % (f)
243 do_byhand(u, summary, short_summary)
245 u.accept(summary, short_summary)
247 # XXX: We seem to be missing a u.remove() here
248 # This might explain why we get byhand leftovers in unchecked - mhy
250 ################################################################################
253 for f in u.pkg.files.keys():
254 if u.pkg.files[f].has_key("byhand"):
258 def do_byhand(u, summary, short_summary):
259 return package_to_queue(u, summary, short_summary, "Byhand",
260 perms=0660, build=False, announce=None)
262 ################################################################################
265 for f in u.pkg.files.keys():
266 if u.pkg.files[f].has_key("new"):
270 def acknowledge_new(u, summary, short_summary):
273 print "Moving to NEW holding area."
274 Logger.log(["Moving to new", u.pkg.changes_file])
276 u.pkg.write_dot_dak(cnf["Dir::Queue::New"])
277 u.move_to_dir(cnf["Dir::Queue::New"], perms=0640, changesperms=0644)
279 if not Options["No-Mail"]:
280 print "Sending new ack."
281 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
283 u.Subst["__SUMMARY__"] = summary
284 new_ack_message = utils.TemplateSubst(u.Subst, template)
285 utils.send_mail(new_ack_message)