]> git.donarmstrong.com Git - dak.git/blob - daklib/queue_install.py
Remove old (and slow) code
[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 from shutil import copyfile
30
31 from daklib import utils
32 from daklib.dbconn import *
33 from daklib.config import Config
34
35 ################################################################################
36
37 def package_to_suite(u, suite_name, session):
38     if suite_name not in u.pkg.changes["distribution"]:
39         return False
40
41     if 'source' in u.pkg.changes["architecture"]:
42         return True
43
44     q = session.query(Suite).filter_by(suite_name = suite_name). \
45         filter(Suite.sources.any( \
46             source = u.pkg.changes['source'], \
47             version = u.pkg.changes['version']))
48
49     # NB: Careful, this logic isn't what you would think it is
50     # Source is already in the target suite so no need to go to policy
51     # Instead, we don't move to the policy area, we just do an ACCEPT
52     if q.count() > 0:
53         return False
54     else:
55         return True
56
57 def package_to_queue(u, summary, short_summary, queue, chg, session, announce=None):
58     cnf = Config()
59     dir = queue.path
60
61     print "Moving to %s policy queue" % queue.queue_name.upper()
62     u.logger.log(["Moving to %s" % queue.queue_name, u.pkg.changes_file])
63
64     u.move_to_queue(queue)
65     chg.in_queue_id = queue.policy_queue_id
66     session.add(chg)
67
68     # send to build queues
69     if queue.send_to_build_queues:
70         for suite_name in u.pkg.changes["distribution"].keys():
71             suite = get_suite(suite_name, session)
72             for q in suite.copy_queues:
73                 q.add_changes_from_policy_queue(queue, chg)
74
75     session.commit()
76
77     # Check for override disparities
78     u.check_override()
79
80     # Send accept mail, announce to lists and close bugs
81     if announce:
82         template = os.path.join(cnf["Dir::Templates"], announce)
83         u.update_subst()
84         mail_message = utils.TemplateSubst(u.Subst, template)
85         utils.send_mail(mail_message)
86         u.announce(short_summary, True)
87
88 ################################################################################
89
90 def is_unembargo(u):
91    session = DBConn().session()
92
93    # If we dont have the disembargo queue we are not on security and so not interested
94    # in doing any security queue handling
95    disembargo_queue = get_policy_queue("unembargoed")
96    if not disembargo_queue:
97        return False
98
99    # If we already are in newstage, then it means this just got passed through and accepted
100    # by a security team member. Don't try to accept it for disembargo again
101    dbc = get_dbchange(u.pkg.changes_file, session)
102    if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
103        return False
104
105    q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version",
106                        {'source': u.pkg.changes["source"],
107                         'version': u.pkg.changes["version"]})
108    if q.rowcount > 0:
109        session.close()
110        return True
111
112    # Ensure we don't have a / on the end or something
113    disdir = os.path.abspath(disembargo_queue.path)
114
115    ret = False
116
117    if u.pkg.directory == disdir:
118        if u.pkg.changes["architecture"].has_key("source"):
119            session.execute("INSERT INTO disembargo (package, version) VALUES (:source, :version)",
120                            {'source': u.pkg.changes["source"],
121                             'version': u.pkg.changes["version"]})
122            session.commit()
123
124            ret = True
125
126    session.close()
127
128    return ret
129
130 def do_unembargo(u, summary, short_summary, chg, session=None):
131     polq=get_policy_queue('unembargoed')
132     package_to_queue(u, summary, short_summary,
133                      polq, chg, session,
134                      announce=None)
135 #
136 #################################################################################
137 #
138 def is_embargo(u):
139    # if we are the security archive, we always have a embargo queue and its the
140    # last in line, so if that exists, return true
141    # Of course do not return true when we accept from out of newstage, as that means
142    # it just left embargo and we want it in the archive
143    if get_policy_queue('embargoed'):
144        session = DBConn().session()
145        dbc = get_dbchange(u.pkg.changes_file, session)
146        if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
147            return False
148
149        return True
150
151 def do_embargo(u, summary, short_summary, chg, session=None):
152     polq=get_policy_queue('embargoed')
153     package_to_queue(u, summary, short_summary,
154                      polq, chg, session,
155                      announce=None)
156
157 ################################################################################
158
159 def is_autobyhand(u):
160     cnf = Config()
161
162     all_auto = 1
163     any_auto = 0
164     for f in u.pkg.files.keys():
165         if u.pkg.files[f].has_key("byhand"):
166             any_auto = 1
167
168             # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
169             # don't contain underscores, and ARCH doesn't contain dots.
170             # further VER matches the .changes Version:, and ARCH should be in
171             # the .changes Architecture: list.
172             if f.count("_") < 2:
173                 all_auto = 0
174                 continue
175
176             (pckg, ver, archext) = f.split("_", 2)
177             if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
178                 all_auto = 0
179                 continue
180
181             ABH = cnf.subtree("AutomaticByHandPackages")
182             if not ABH.has_key(pckg) or \
183               ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
184                 print "not match %s %s" % (pckg, u.pkg.changes["source"])
185                 all_auto = 0
186                 continue
187
188             (arch, ext) = archext.split(".", 1)
189             if arch not in u.pkg.changes["architecture"]:
190                 all_auto = 0
191                 continue
192
193             u.pkg.files[f]["byhand-arch"] = arch
194             u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
195
196     return any_auto and all_auto
197
198 def do_autobyhand(u, summary, short_summary, chg, session):
199     print "Attempting AUTOBYHAND."
200     byhandleft = False
201     for f, entry in u.pkg.files.items():
202         byhandfile = f
203
204         if not entry.has_key("byhand"):
205             continue
206
207         if not entry.has_key("byhand-script"):
208             byhandleft = True
209             continue
210
211         os.system("ls -l %s" % byhandfile)
212
213         result = os.system("%s %s %s %s %s" % (
214                 entry["byhand-script"],
215                 byhandfile,
216                 u.pkg.changes["version"],
217                 entry["byhand-arch"],
218                 os.path.abspath(u.pkg.changes_file)))
219
220         if result == 0:
221             os.unlink(byhandfile)
222             del u.pkg.files[f]
223         else:
224             print "Error processing %s, left as byhand." % (f)
225             byhandleft = True
226
227     if byhandleft:
228         do_byhand(u, summary, short_summary, chg, session)
229     else:
230         u.accept(summary, short_summary, session)
231         u.check_override()
232
233 ################################################################################
234
235 def is_byhand(u):
236     for f in u.pkg.files.keys():
237         if u.pkg.files[f].has_key("byhand"):
238             return True
239     return False
240
241 def do_byhand(u, summary, short_summary, chg, session):
242     return package_to_queue(u, summary, short_summary,
243                             get_policy_queue('byhand'), chg, session,
244                             announce=None)
245
246 ################################################################################
247
248 def is_new(u):
249     for f in u.pkg.files.keys():
250         if u.pkg.files[f].has_key("new"):
251             return True
252     return False
253
254 def acknowledge_new(u, summary, short_summary, chg, session):
255     cnf = Config()
256
257     print "Moving to NEW queue."
258     u.logger.log(["Moving to new", u.pkg.changes_file])
259
260     q = get_policy_queue('new', session)
261
262     u.move_to_queue(q)
263     chg.in_queue_id = q.policy_queue_id
264     session.add(chg)
265     session.commit()
266
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 # FIXME: queues should be able to get autobuild
277 #        the current logic doesnt allow this, as buildd stuff is AFTER accept...
278 #        embargo/disembargo use a workaround due to this
279 # q-unapproved hax0ring
280 QueueInfo = {
281     "new": { "is": is_new, "process": acknowledge_new },
282     "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
283     "byhand" : { "is": is_byhand, "process": do_byhand },
284     "embargoed" : { "is": is_embargo, "process": do_embargo },
285     "unembargoed" : { "is": is_unembargo, "process": do_unembargo },
286 }
287
288 def determine_target(u):
289     cnf = Config()
290
291     # Statically handled queues
292     target = None
293
294     for q in ["autobyhand", "byhand", "new", "unembargoed", "embargoed"]:
295         if QueueInfo[q]["is"](u):
296             target = q
297             break
298
299     return target
300
301 ###############################################################################
302