]> git.donarmstrong.com Git - dak.git/blob - daklib/queue_install.py
Merge commit 'ftpmaster/master'
[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 package_to_suite(u, suite_name, session):
37     if not u.pkg.changes["distribution"].has_key(suite_name):
38         return False
39
40     ret = True
41
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)
47
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
51         if q.count() > 0:
52             ret = False
53
54     return ret
55
56 def package_to_queue(u, summary, short_summary, queue, perms=0660, announce=None):
57     cnf = Config()
58     dir = queue.path
59
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])
62
63     u.move_to_dir(dir, perms=perms)
64     # TODO: Put building logic in here?  We used to take a build=bool argument
65
66     # Check for override disparities
67     u.check_override()
68
69     # Send accept mail, announce to lists and close bugs
70     if announce and not cnf["Dinstall::Options::No-Mail"]:
71         template = os.path.join(cnf["Dir::Templates"], announce)
72         u.update_subst()
73         u.Subst["__SUITE__"] = ""
74         mail_message = utils.TemplateSubst(u.Subst, template)
75         utils.send_mail(mail_message)
76         u.announce(short_summary, True)
77
78 ################################################################################
79
80 # TODO: This logic needs to be replaced with policy queues before we upgrade
81 # security master
82
83 #def is_unembargo(u):
84 #    session = DBConn().session()
85 #    cnf = Config()
86 #
87 #    q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version", u.pkg.changes)
88 #    if q.rowcount > 0:
89 #        session.close()
90 #        return True
91 #
92 #    oldcwd = os.getcwd()
93 #    os.chdir(cnf["Dir::Queue::Disembargo"])
94 #    disdir = os.getcwd()
95 #    os.chdir(oldcwd)
96 #
97 #    ret = False
98 #
99 #    if u.pkg.directory == disdir:
100 #        if u.pkg.changes["architecture"].has_key("source"):
101 #            session.execute("INSERT INTO disembargo (package, version) VALUES (:package, :version)", u.pkg.changes)
102 #            session.commit()
103 #
104 #            ret = True
105 #
106 #    session.close()
107 #
108 #    return ret
109 #
110 #def queue_unembargo(u, summary, short_summary, session=None):
111 #    return package_to_queue(u, summary, short_summary, "Unembargoed",
112 #                            perms=0660, build=True, announce='process-unchecked.accepted')
113 #
114 #################################################################################
115 #
116 #def is_embargo(u):
117 #    # if embargoed queues are enabled always embargo
118 #    return True
119 #
120 #def queue_embargo(u, summary, short_summary, session=None):
121 #    return package_to_queue(u, summary, short_summary, "Unembargoed",
122 #                            perms=0660, build=True, announce='process-unchecked.accepted')
123
124 ################################################################################
125
126 def is_autobyhand(u):
127     cnf = Config()
128
129     all_auto = 1
130     any_auto = 0
131     for f in u.pkg.files.keys():
132         if u.pkg.files[f].has_key("byhand"):
133             any_auto = 1
134
135             # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
136             # don't contain underscores, and ARCH doesn't contain dots.
137             # further VER matches the .changes Version:, and ARCH should be in
138             # the .changes Architecture: list.
139             if f.count("_") < 2:
140                 all_auto = 0
141                 continue
142
143             (pckg, ver, archext) = f.split("_", 2)
144             if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
145                 all_auto = 0
146                 continue
147
148             ABH = cnf.SubTree("AutomaticByHandPackages")
149             if not ABH.has_key(pckg) or \
150               ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
151                 print "not match %s %s" % (pckg, u.pkg.changes["source"])
152                 all_auto = 0
153                 continue
154
155             (arch, ext) = archext.split(".", 1)
156             if arch not in u.pkg.changes["architecture"]:
157                 all_auto = 0
158                 continue
159
160             u.pkg.files[f]["byhand-arch"] = arch
161             u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
162
163     return any_auto and all_auto
164
165 def do_autobyhand(u, summary, short_summary, session=None):
166     print "Attempting AUTOBYHAND."
167     byhandleft = True
168     for f, entry in u.pkg.files.items():
169         byhandfile = f
170
171         if not entry.has_key("byhand"):
172             continue
173
174         if not entry.has_key("byhand-script"):
175             byhandleft = True
176             continue
177
178         os.system("ls -l %s" % byhandfile)
179
180         result = os.system("%s %s %s %s %s" % (
181                 entry["byhand-script"],
182                 byhandfile,
183                 u.pkg.changes["version"],
184                 entry["byhand-arch"],
185                 os.path.abspath(u.pkg.changes_file)))
186
187         if result == 0:
188             os.unlink(byhandfile)
189             del entry
190         else:
191             print "Error processing %s, left as byhand." % (f)
192             byhandleft = True
193
194     if byhandleft:
195         do_byhand(u, summary, short_summary, session)
196     else:
197         u.accept(summary, short_summary, session)
198         u.check_override()
199
200 ################################################################################
201
202 def is_byhand(u):
203     for f in u.pkg.files.keys():
204         if u.pkg.files[f].has_key("byhand"):
205             return True
206     return False
207
208 def do_byhand(u, summary, short_summary, session=None):
209     return package_to_queue(u, summary, short_summary, "Byhand",
210                             perms=0660, build=False, announce=None)
211
212 ################################################################################
213
214 def is_new(u):
215     for f in u.pkg.files.keys():
216         if u.pkg.files[f].has_key("new"):
217             return True
218     return False
219
220 def acknowledge_new(u, summary, short_summary, session=None):
221     cnf = Config()
222
223     print "Moving to NEW queue."
224     u.logger.log(["Moving to new", u.pkg.changes_file])
225
226     u.move_to_dir(cnf["Dir::Queue::New"], perms=0640, changesperms=0644)
227
228     if not cnf["Dinstall::Options::No-Mail"]:
229         print "Sending new ack."
230         template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
231         u.update_subst()
232         u.Subst["__SUMMARY__"] = summary
233         new_ack_message = utils.TemplateSubst(u.Subst, template)
234         utils.send_mail(new_ack_message)
235
236 ################################################################################
237
238 # q-unapproved hax0ring
239 QueueInfo = {
240     "new": { "is": is_new, "process": acknowledge_new },
241     "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
242     "byhand" : { "is": is_byhand, "process": do_byhand },
243 }
244
245 def determine_target(u):
246     cnf = Config()
247
248     # Statically handled queues
249     target = None
250
251     for q in QueueInfo.keys():
252         if QueueInfo[q]["is"](u):
253             target = q
254
255     return target
256
257 ###############################################################################
258