]> git.decadent.org.uk Git - dak.git/blob - daklib/queue_install.py
check_files: check changes against known_changes
[dak.git] / daklib / queue_install.py
1 #!/usr/bin/env python
2 # vim:set et sw=4:
3
4 """
5 Utility functions for process-upload
6
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
12 """
13
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.
18
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.
23
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
27
28 import os
29
30 from daklib import utils
31 from daklib.dbconn import *
32 from daklib.config import Config
33
34 ###############################################################################
35
36 def determine_target(u):
37     cnf = Config()
38     
39     queues = [ "New", "Autobyhand", "Byhand" ]
40     if cnf.FindB("Dinstall::SecurityQueueHandling"):
41         queues += [ "Unembargo", "Embargo" ]
42     else:
43         queues += [ "OldStableUpdate", "StableUpdate" ]
44
45     target = None
46     for q in queues:
47         if QueueInfo[q]["is"](u):
48             target = q
49             break
50
51     return target
52
53 ################################################################################
54
55 def package_to_suite(u, suite):
56     if not u.pkg.changes["distribution"].has_key(suite):
57         return False
58
59     ret = True
60
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)
67
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
71         if q.count() > 0:
72             ret = False
73
74         s.close()
75
76     return ret
77
78 def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, announce=None):
79     cnf = Config()
80     dir = cnf["Dir::Queue::%s" % queue]
81
82     print "Moving to %s holding area" % queue.upper()
83     u.logger.log(["Moving to %s" % queue, u.pkg.changes_file])
84
85     u.move_to_dir(dir, perms=perms)
86     if build:
87         get_or_set_queue(queue.lower()).autobuild_upload(u.pkg, dir)
88
89     # Check for override disparities
90     u.check_override()
91
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)
95         u.update_subst()
96         u.Subst["__SUITE__"] = ""
97         mail_message = utils.TemplateSubst(u.Subst, template)
98         utils.send_mail(mail_message)
99         u.announce(short_summary, True)
100
101 ################################################################################
102
103 def is_unembargo(u):
104     session = DBConn().session()
105     cnf = Config()
106
107     q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
108     if q.rowcount > 0:
109         session.close()
110         return True
111
112     oldcwd = os.getcwd()
113     os.chdir(cnf["Dir::Queue::Disembargo"])
114     disdir = os.getcwd()
115     os.chdir(oldcwd)
116
117     ret = False
118
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)
122             session.commit()
123
124             ret = True
125
126     session.close()
127
128     return ret
129
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')
133
134 ################################################################################
135
136 def is_embargo(u):
137     # if embargoed queues are enabled always embargo
138     return True
139
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')
143
144 ################################################################################
145
146 def is_stableupdate(u):
147     return package_to_suite(u, 'proposed-updates')
148
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)
152
153 ################################################################################
154
155 def is_oldstableupdate(u):
156     return package_to_suite(u, 'oldstable-proposed-updates')
157
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)
161
162 ################################################################################
163
164 def is_autobyhand(u):
165     cnf = Config()
166
167     all_auto = 1
168     any_auto = 0
169     for f in u.pkg.files.keys():
170         if u.pkg.files[f].has_key("byhand"):
171             any_auto = 1
172
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.
177             if f.count("_") < 2:
178                 all_auto = 0
179                 continue
180
181             (pckg, ver, archext) = f.split("_", 2)
182             if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
183                 all_auto = 0
184                 continue
185
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"])
190                 all_auto = 0
191                 continue
192
193             (arch, ext) = archext.split(".", 1)
194             if arch not in u.pkg.changes["architecture"]:
195                 all_auto = 0
196                 continue
197
198             u.pkg.files[f]["byhand-arch"] = arch
199             u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
200
201     return any_auto and all_auto
202
203 def do_autobyhand(u, summary, short_summary, session=None):
204     print "Attempting AUTOBYHAND."
205     byhandleft = True
206     for f, entry in u.pkg.files.items():
207         byhandfile = f
208
209         if not entry.has_key("byhand"):
210             continue
211
212         if not entry.has_key("byhand-script"):
213             byhandleft = True
214             continue
215
216         os.system("ls -l %s" % byhandfile)
217
218         result = os.system("%s %s %s %s %s" % (
219                 entry["byhand-script"],
220                 byhandfile,
221                 u.pkg.changes["version"],
222                 entry["byhand-arch"],
223                 os.path.abspath(u.pkg.changes_file)))
224
225         if result == 0:
226             os.unlink(byhandfile)
227             del entry
228         else:
229             print "Error processing %s, left as byhand." % (f)
230             byhandleft = True
231
232     if byhandleft:
233         do_byhand(u, summary, short_summary, session)
234     else:
235         u.accept(summary, short_summary, session)
236         u.check_override()
237
238 ################################################################################
239
240 def is_byhand(u):
241     for f in u.pkg.files.keys():
242         if u.pkg.files[f].has_key("byhand"):
243             return True
244     return False
245
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)
249
250 ################################################################################
251
252 def is_new(u):
253     for f in u.pkg.files.keys():
254         if u.pkg.files[f].has_key("new"):
255             return True
256     return False
257
258 def acknowledge_new(u, summary, short_summary, session=None):
259     cnf = Config()
260
261     print "Moving to NEW queue."
262     u.logger.log(["Moving to new", u.pkg.changes_file])
263
264     u.move_to_dir(cnf["Dir::Queue::New"], perms=0640, changesperms=0644)
265
266     if not cnf["Dinstall::Options::No-Mail"]:
267         print "Sending new ack."
268         template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
269         u.update_subst()
270         u.Subst["__SUMMARY__"] = summary
271         new_ack_message = utils.TemplateSubst(u.Subst, template)
272         utils.send_mail(new_ack_message)
273
274 ################################################################################
275
276 # q-unapproved hax0ring
277 QueueInfo = {
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 },
286 }