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 u.Subst["__SUITE__"] = ""
76 mail_message = utils.TemplateSubst(u.Subst, template)
77 utils.send_mail(mail_message)
78 u.announce(short_summary, True)
80 ################################################################################
82 # TODO: This logic needs to be replaced with policy queues before we upgrade
86 # session = DBConn().session()
89 # q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
94 # oldcwd = os.getcwd()
95 # os.chdir(cnf["Dir::Queue::Disembargo"])
96 # disdir = os.getcwd()
101 # if u.pkg.directory == disdir:
102 # if u.pkg.changes["architecture"].has_key("source"):
103 # session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)", u.pkg.changes)
112 #def queue_unembargo(u, summary, short_summary, session=None):
113 # return package_to_queue(u, summary, short_summary, "Unembargoed",
114 # perms=0660, build=True, announce='process-unchecked.accepted')
116 #################################################################################
119 # # if embargoed queues are enabled always embargo
122 #def queue_embargo(u, summary, short_summary, session=None):
123 # return package_to_queue(u, summary, short_summary, "Unembargoed",
124 # perms=0660, build=True, announce='process-unchecked.accepted')
126 ################################################################################
128 def is_autobyhand(u):
133 for f in u.pkg.files.keys():
134 if u.pkg.files[f].has_key("byhand"):
137 # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
138 # don't contain underscores, and ARCH doesn't contain dots.
139 # further VER matches the .changes Version:, and ARCH should be in
140 # the .changes Architecture: list.
145 (pckg, ver, archext) = f.split("_", 2)
146 if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
150 ABH = cnf.SubTree("AutomaticByHandPackages")
151 if not ABH.has_key(pckg) or \
152 ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
153 print "not match %s %s" % (pckg, u.pkg.changes["source"])
157 (arch, ext) = archext.split(".", 1)
158 if arch not in u.pkg.changes["architecture"]:
162 u.pkg.files[f]["byhand-arch"] = arch
163 u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
165 return any_auto and all_auto
167 def do_autobyhand(u, summary, short_summary, chg, session):
168 print "Attempting AUTOBYHAND."
170 for f, entry in u.pkg.files.items():
173 if not entry.has_key("byhand"):
176 if not entry.has_key("byhand-script"):
180 os.system("ls -l %s" % byhandfile)
182 result = os.system("%s %s %s %s %s" % (
183 entry["byhand-script"],
185 u.pkg.changes["version"],
186 entry["byhand-arch"],
187 os.path.abspath(u.pkg.changes_file)))
190 os.unlink(byhandfile)
193 print "Error processing %s, left as byhand." % (f)
197 do_byhand(u, summary, short_summary, chg, session)
199 u.accept(summary, short_summary, session)
202 ################################################################################
205 for f in u.pkg.files.keys():
206 if u.pkg.files[f].has_key("byhand"):
210 def do_byhand(u, summary, short_summary, chg, session):
211 return package_to_queue(u, summary, short_summary,
212 get_policy_queue('byhand'), chg, session,
215 ################################################################################
218 for f in u.pkg.files.keys():
219 if u.pkg.files[f].has_key("new"):
223 def acknowledge_new(u, summary, short_summary, chg, session):
226 print "Moving to NEW queue."
227 u.logger.log(["Moving to new", u.pkg.changes_file])
229 q = get_policy_queue('new', session)
232 chg.in_queue_id = q.policy_queue_id
236 print "Sending new ack."
237 template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
239 u.Subst["__SUMMARY__"] = summary
240 new_ack_message = utils.TemplateSubst(u.Subst, template)
241 utils.send_mail(new_ack_message)
243 ################################################################################
245 # q-unapproved hax0ring
247 "new": { "is": is_new, "process": acknowledge_new },
248 "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
249 "byhand" : { "is": is_byhand, "process": do_byhand },
252 def determine_target(u):
255 # Statically handled queues
258 for q in ["new", "autobyhand", "byhand"]:
259 if QueueInfo[q]["is"](u):
265 ###############################################################################