]> git.decadent.org.uk Git - dak.git/blob - daklib/queue_install.py
add pickle file db-metadata-0.5.2.pkl
[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, chg, session, 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_queue(queue)
64     chg.in_queue_id = queue.policy_queue_id
65     session.add(chg)
66     session.commit()
67
68     # Check for override disparities
69     u.check_override()
70
71     # Send accept mail, announce to lists and close bugs
72     if announce:
73         template = os.path.join(cnf["Dir::Templates"], announce)
74         u.update_subst()
75         mail_message = utils.TemplateSubst(u.Subst, template)
76         utils.send_mail(mail_message)
77         u.announce(short_summary, True)
78
79 ################################################################################
80
81 def is_unembargo(u):
82    session = DBConn().session()
83    cnf = Config()
84
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"):
88        return False
89
90    # If we already are in newstage, then it means this just got passed through and accepted
91    # by a security team member. Don't try to accept it for disembargo again
92    dbc = get_dbchange(u.pkg.changes_file, session)
93    if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
94        return False
95
96    q = session.execute("SELECT package FROM disembargo WHERE package = :source AND version = :version",
97                        {'source': u.pkg.changes["source"],
98                         'version': u.pkg.changes["version"]})
99    if q.rowcount > 0:
100        session.close()
101        return True
102
103    oldcwd = os.getcwd()
104    os.chdir(cnf["Dir::Queue::Disembargo"])
105    disdir = os.getcwd()
106    os.chdir(oldcwd)
107
108    ret = False
109
110    if u.pkg.directory == disdir:
111        if u.pkg.changes["architecture"].has_key("source"):
112            session.execute("INSERT INTO disembargo (package, version) VALUES (:source, :version)",
113                            {'source': u.pkg.changes["source"],
114                             'version': u.pkg.changes["version"]})
115            session.commit()
116
117            ret = True
118
119    session.close()
120
121    return ret
122
123 def do_unembargo(u, summary, short_summary, chg, session=None):
124     polq=get_policy_queue('disembargo')
125     package_to_queue(u, summary, short_summary,
126                      polq, chg, session,
127                      announce=None)
128     for suite_name in u.pkg.changes["distribution"].keys():
129         suite = get_suite(suite_name, session)
130         for q in suite.copy_queues:
131             for f in u.pkg.files.keys():
132                 os.symlink(os.path.join(polq.path, f), os.path.join(q.path, f))
133 #
134 #################################################################################
135 #
136 def is_embargo(u):
137    # if we are the security archive, we always have a embargo queue and its the
138    # last in line, so if that exists, return true
139    # Of course do not return true when we accept from out of newstage, as that means
140    # it just left embargo and we want it in the archive
141    if get_policy_queue('embargo'):
142        session = DBConn().session()
143        dbc = get_dbchange(u.pkg.changes_file, session)
144        if dbc and dbc.in_queue.queue_name in [ 'newstage' ]:
145            return False
146
147        return True
148
149 def do_embargo(u, summary, short_summary, chg, session=None):
150     polq=get_policy_queue('embargo')
151     package_to_queue(u, summary, short_summary,
152                      polq, chg, session,
153                      announce=None)
154     for suite_name in u.pkg.changes["distribution"].keys():
155         suite = get_suite(suite_name, session)
156         for q in suite.copy_queues:
157             for f in u.pkg.files.keys():
158                 os.symlink(os.path.join(polq.path, f), os.path.join(q.path, f))
159
160 ################################################################################
161
162 def is_autobyhand(u):
163     cnf = Config()
164
165     all_auto = 1
166     any_auto = 0
167     for f in u.pkg.files.keys():
168         if u.pkg.files[f].has_key("byhand"):
169             any_auto = 1
170
171             # filename is of form "PKG_VER_ARCH.EXT" where PKG, VER and ARCH
172             # don't contain underscores, and ARCH doesn't contain dots.
173             # further VER matches the .changes Version:, and ARCH should be in
174             # the .changes Architecture: list.
175             if f.count("_") < 2:
176                 all_auto = 0
177                 continue
178
179             (pckg, ver, archext) = f.split("_", 2)
180             if archext.count(".") < 1 or u.pkg.changes["version"] != ver:
181                 all_auto = 0
182                 continue
183
184             ABH = cnf.SubTree("AutomaticByHandPackages")
185             if not ABH.has_key(pckg) or \
186               ABH["%s::Source" % (pckg)] != u.pkg.changes["source"]:
187                 print "not match %s %s" % (pckg, u.pkg.changes["source"])
188                 all_auto = 0
189                 continue
190
191             (arch, ext) = archext.split(".", 1)
192             if arch not in u.pkg.changes["architecture"]:
193                 all_auto = 0
194                 continue
195
196             u.pkg.files[f]["byhand-arch"] = arch
197             u.pkg.files[f]["byhand-script"] = ABH["%s::Script" % (pckg)]
198
199     return any_auto and all_auto
200
201 def do_autobyhand(u, summary, short_summary, chg, session):
202     print "Attempting AUTOBYHAND."
203     byhandleft = False
204     for f, entry in u.pkg.files.items():
205         byhandfile = f
206
207         if not entry.has_key("byhand"):
208             continue
209
210         if not entry.has_key("byhand-script"):
211             byhandleft = True
212             continue
213
214         os.system("ls -l %s" % byhandfile)
215
216         result = os.system("%s %s %s %s %s" % (
217                 entry["byhand-script"],
218                 byhandfile,
219                 u.pkg.changes["version"],
220                 entry["byhand-arch"],
221                 os.path.abspath(u.pkg.changes_file)))
222
223         if result == 0:
224             os.unlink(byhandfile)
225             del u.pkg.files[f]
226         else:
227             print "Error processing %s, left as byhand." % (f)
228             byhandleft = True
229
230     if byhandleft:
231         do_byhand(u, summary, short_summary, chg, session)
232     else:
233         u.accept(summary, short_summary, session)
234         u.check_override()
235
236 ################################################################################
237
238 def is_byhand(u):
239     for f in u.pkg.files.keys():
240         if u.pkg.files[f].has_key("byhand"):
241             return True
242     return False
243
244 def do_byhand(u, summary, short_summary, chg, session):
245     return package_to_queue(u, summary, short_summary,
246                             get_policy_queue('byhand'), chg, session,
247                             announce=None)
248
249 ################################################################################
250
251 def is_new(u):
252     for f in u.pkg.files.keys():
253         if u.pkg.files[f].has_key("new"):
254             return True
255     return False
256
257 def acknowledge_new(u, summary, short_summary, chg, session):
258     cnf = Config()
259
260     print "Moving to NEW queue."
261     u.logger.log(["Moving to new", u.pkg.changes_file])
262
263     q = get_policy_queue('new', session)
264
265     u.move_to_queue(q)
266     chg.in_queue_id = q.policy_queue_id
267     session.add(chg)
268     session.commit()
269
270     print "Sending new ack."
271     template = os.path.join(cnf["Dir::Templates"], 'process-unchecked.new')
272     u.update_subst()
273     u.Subst["__SUMMARY__"] = summary
274     new_ack_message = utils.TemplateSubst(u.Subst, template)
275     utils.send_mail(new_ack_message)
276
277 ################################################################################
278
279 # FIXME: queues should be able to get autobuild
280 #        the current logic doesnt allow this, as buildd stuff is AFTER accept...
281 #        embargo/disembargo use a workaround due to this
282 # q-unapproved hax0ring
283 QueueInfo = {
284     "new": { "is": is_new, "process": acknowledge_new },
285     "autobyhand" : { "is" : is_autobyhand, "process": do_autobyhand },
286     "byhand" : { "is": is_byhand, "process": do_byhand },
287     "embargoed" : { "is": is_embargo, "process": do_embargo },
288     "unembargoed" : { "is": is_unembargo, "process": do_unembargo },
289 }
290
291 def determine_target(u):
292     cnf = Config()
293
294     # Statically handled queues
295     target = None
296
297     for q in ["autobyhand", "byhand", "new", "unembargoed", "embargoed"]:
298         if QueueInfo[q]["is"](u):
299             target = q
300             break
301
302     return target
303
304 ###############################################################################
305