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 package_to_suite(u, suite_name, session):
37 if not u.pkg.changes["distribution"].has_key(suite_name):
42 if not u.pkg.changes["architecture"].has_key("source"):
43 q = session.query(SrcAssociation.sa_id)
44 q = q.join(Suite).filter_by(suite_name=suite_name)
45 q = q.join(DBSource).filter_by(source=u.pkg.changes['source'])
46 q = q.filter_by(version=u.pkg.changes['version']).limit(1)
48 # NB: Careful, this logic isn't what you would think it is
49 # Source is already in the target suite so no need to go to policy
50 # Instead, we don't move to the policy area, we just do an ACCEPT
56 def package_to_queue(u, summary, short_summary, queue, chg, session, announce=None):
60 print "Moving to %s policy queue" % queue.queue_name.upper()
61 u.logger.log(["Moving to %s" % queue.queue_name, u.pkg.changes_file])
63 u.move_to_queue(queue)
64 chg.in_queue_id = queue.policy_queue_id
68 # Check for override disparities
71 # Send accept mail, announce to lists and close bugs
73 template = os.path.join(cnf["Dir::Templates"], announce)
75 mail_message = utils.TemplateSubst(u.Subst, template)
76 utils.send_mail(mail_message)
77 u.announce(short_summary, True)
79 ################################################################################
82 session = DBConn().session()
85 # If we dont have the disembargo queue we are not on security and so not interested
86 # in doing any security queue handling
87 if not get_policy_queue("disembargo"):
90 q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version",
91 {'source': u.pkg.changes["source"],
92 'version': u.pkg.changes["version"]})
98 os.chdir(cnf["Dir::Queue::Disembargo"])
104 if u.pkg.directory == disdir:
105 if u.pkg.changes["architecture"].has_key("source"):
106 session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)",
107 {'source': u.pkg.changes["source"],
108 'version': u.pkg.changes["version"]})
117 def do_unembargo(u, summary, short_summary, chg, session=None):
118 polq=get_policy_queue('disembargo')
119 package_to_queue(u, summary, short_summary,
122 for suite_name in u.pkg.changes["distribution"].keys():
123 suite = get_suite(suite_name, session)
124 for q in suite.copy_queues:
125 for f in u.pkg.files.keys():
126 os.symlink(os.path.join(polq.path, f), os.path.join(q.path, f))
128 #################################################################################
131 # if we are the security archive, we always have a embargo queue and its the
132 # last in line, so if that exists, return true
133 if get_policy_queue('embargo'):
136 def do_embargo(u, summary, short_summary, chg, session=None):
137 polq=get_policy_queue('embargo')
138 package_to_queue(u, summary, short_summary,
141 for suite_name in u.pkg.changes["distribution"].keys():
142 suite = get_suite(suite_name, session)
143 for q in suite.copy_queues:
144 for f in u.pkg.files.keys():
145 os.symlink(os.path.join(polq.path, f), os.path.join(q.path, f))
147 ################################################################################
149 def is_autobyhand(u):
154 for f in u.pkg.files.keys():
155 if u.pkg.files[f].has_key("byhand"):
158 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
159 # don't contain underscores, and ARCH doesn't contain dots.
160 # further VER matches the .changes Version:, and ARCH should be in
161 # the .changes Architecture: list.
166 (pckg, ver, archext) = f.split("_", 2)
167 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
171 ABH = cnf.SubTree("AutomaticByHandPackages")
172 if not ABH.has_key(pckg) or \
173 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
174 print "not match %s %s" % (pckg, u.pkg.changes["source"])
178 (arch, ext) = archext.split(".", 1)
179 if arch not in u.pkg.changes["architecture"]:
183 u.pkg.files[f]["byhand-arch"] = arch
184 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
186 return any_auto and all_auto
188 def do_autobyhand(u, summary, short_summary, chg, session):
189 print "Attempting AUTOBYHAND."
191 for f, entry in u.pkg.files.items():
194 if not entry.has_key("byhand"):
197 if not entry.has_key("byhand-script"):
201 os.system("ls -l %s" % byhandfile)
203 result = os.system("%s %s %s %s %s" % (
204 entry["byhand-script"],
206 u.pkg.changes["version"],
207 entry["byhand-arch"],
208 os.path.abspath(u.pkg.changes_file)))
211 os.unlink(byhandfile)
214 print "Error processing %s, left as byhand." % (f)
218 do_byhand(u, summary, short_summary, chg, session)
220 u.accept(summary, short_summary, session)
223 ################################################################################
226 for f in u.pkg.files.keys():
227 if u.pkg.files[f].has_key("byhand"):
231 def do_byhand(u, summary, short_summary, chg, session):
232 return package_to_queue(u, summary, short_summary,
233 get_policy_queue('byhand'), chg, session,
236 ################################################################################
239 for f in u.pkg.files.keys():
240 if u.pkg.files[f].has_key("new"):
244 def acknowledge_new(u, summary, short_summary, chg, session):
247 print "Moving to NEW queue."
248 u.logger.log(["Moving to new", u.pkg.changes_file])
250 q = get_policy_queue('new', session)
253 chg.in_queue_id = q.policy_queue_id
257 print "Sending new ack."
258 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
260 u.Subst["__SUMMARY__"] = summary
261 new_ack_message = utils.TemplateSubst(u.Subst, template)
262 utils.send_mail(new_ack_message)
264 ################################################################################
266 # FIXME: queues should be able to get autobuild
267 # the current logic doesnt allow this, as buildd stuff is AFTER accept...
268 # embargo/disembargo use a workaround due to this
269 # q-unapproved hax0ring
271 "new": { "is": is_new, "process": acknowledge_new },
272 "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
273 "byhand" : { "is": is_byhand, "process": do_byhand },
274 "embargoed" : { "is": is_embargo, "process": do_embargo },
275 "unembargoed" : { "is": is_unembargo, "process": do_unembargo },
278 def determine_target(u):
281 # Statically handled queues
284 for q in ["autobyhand", "byhand", "new", "unembargoed", "embargoed"]:
285 if QueueInfo[q]["is"](u):
291 ###############################################################################