]> git.decadent.org.uk Git - dak.git/blob - daklib/queue.py
5a5c8f90f07db110f4a6150f1c7eff66fb9143ff
[dak.git] / daklib / queue.py
1 #!/usr/bin/env python
2 # vim:set et sw=4:
3
4 """
5 Queue utility functions for dak
6
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2001 - 2006 James Troup <james@nocrew.org>
9 @copyright: 2009, 2010  Joerg Jaspert <joerg@debian.org>
10 @license: GNU General Public License version 2 or later
11 """
12
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
27 ###############################################################################
28
29 import errno
30 import os
31 import stat
32 import sys
33 import time
34 import apt_inst
35 import apt_pkg
36 import utils
37 import commands
38 import shutil
39 import textwrap
40 from types import *
41 from sqlalchemy.sql.expression import desc
42 from sqlalchemy.orm.exc import NoResultFound
43
44 from dak_exceptions import *
45 from changes import *
46 from regexes import *
47 from config import Config
48 from holding import Holding
49 from urgencylog import UrgencyLog
50 from dbconn import *
51 from summarystats import SummaryStats
52 from utils import parse_changes, check_dsc_files, build_package_list
53 from textutils import fix_maintainer
54 from lintian import parse_lintian_output, generate_reject_messages
55 from contents import UnpackedSource
56
57 ################################################################################
58
59 def check_valid(overrides, session):
60     """Check if section and priority for new overrides exist in database.
61
62     Additionally does sanity checks:
63       - debian-installer packages have to be udeb (or source)
64       - non debian-installer packages cannot be udeb
65
66     @type  overrides: list of dict
67     @param overrides: list of overrides to check. The overrides need
68                       to be given in form of a dict with the following keys:
69
70                       - package: package name
71                       - priority
72                       - section
73                       - component
74                       - type: type of requested override ('dsc', 'deb' or 'udeb')
75
76                       All values are strings.
77
78     @rtype:  bool
79     @return: C{True} if all overrides are valid, C{False} if there is any
80              invalid override.
81     """
82     all_valid = True
83     for o in overrides:
84         o['valid'] = True
85         if session.query(Priority).filter_by(priority=o['priority']).first() is None:
86             o['valid'] = False
87         if session.query(Section).filter_by(section=o['section']).first() is None:
88             o['valid'] = False
89         if get_mapped_component(o['component'], session) is None:
90             o['valid'] = False
91         if o['type'] not in ('dsc', 'deb', 'udeb'):
92             raise Exception('Unknown override type {0}'.format(o['type']))
93         if o['type'] == 'udeb' and o['section'] != 'debian-installer':
94             o['valid'] = False
95         if o['section'] == 'debian-installer' and o['type'] not in ('dsc', 'udeb'):
96             o['valid'] = False
97         all_valid = all_valid and o['valid']
98     return all_valid
99
100 ###############################################################################
101
102 def prod_maintainer(notes, upload):
103     cnf = Config()
104     changes = upload.changes
105     whitelists = [ upload.target_suite.mail_whitelist ]
106
107     # Here we prepare an editor and get them ready to prod...
108     (fd, temp_filename) = utils.temp_filename()
109     temp_file = os.fdopen(fd, 'w')
110     temp_file.write("\n\n=====\n\n".join([note.comment for note in notes]))
111     temp_file.close()
112     editor = os.environ.get("EDITOR","vi")
113     answer = 'E'
114     while answer == 'E':
115         os.system("%s %s" % (editor, temp_filename))
116         temp_fh = utils.open_file(temp_filename)
117         prod_message = "".join(temp_fh.readlines())
118         temp_fh.close()
119         print "Prod message:"
120         print utils.prefix_multi_line_string(prod_message,"  ",include_blank_lines=1)
121         prompt = "[P]rod, Edit, Abandon, Quit ?"
122         answer = "XXX"
123         while prompt.find(answer) == -1:
124             answer = utils.our_raw_input(prompt)
125             m = re_default_answer.search(prompt)
126             if answer == "":
127                 answer = m.group(1)
128             answer = answer[:1].upper()
129     os.unlink(temp_filename)
130     if answer == 'A':
131         return
132     elif answer == 'Q':
133         return 0
134     # Otherwise, do the proding...
135     user_email_address = utils.whoami() + " <%s>" % (
136         cnf["Dinstall::MyAdminAddress"])
137
138     changed_by = changes.changedby or changes.maintainer
139     maintainer = changes.maintainer
140     maintainer_to = utils.mail_addresses_for_upload(maintainer, changed_by, changes.fingerprint)
141
142     Subst = {
143         '__SOURCE__': upload.changes.source,
144         '__CHANGES_FILENAME__': upload.changes.changesname,
145         '__MAINTAINER_TO__': ", ".join(maintainer_to),
146         }
147
148     Subst["__FROM_ADDRESS__"] = user_email_address
149     Subst["__PROD_MESSAGE__"] = prod_message
150     Subst["__CC__"] = "Cc: " + cnf["Dinstall::MyEmailAddress"]
151
152     prod_mail_message = utils.TemplateSubst(
153         Subst,cnf["Dir::Templates"]+"/process-new.prod")
154
155     # Send the prod mail
156     utils.send_mail(prod_mail_message, whitelists=whitelists)
157
158     print "Sent prodding message"
159
160 ################################################################################
161
162 def edit_note(note, upload, session, trainee=False):
163     # Write the current data to a temporary file
164     (fd, temp_filename) = utils.temp_filename()
165     editor = os.environ.get("EDITOR","vi")
166     answer = 'E'
167     while answer == 'E':
168         os.system("%s %s" % (editor, temp_filename))
169         temp_file = utils.open_file(temp_filename)
170         newnote = temp_file.read().rstrip()
171         temp_file.close()
172         print "New Note:"
173         print utils.prefix_multi_line_string(newnote,"  ")
174         prompt = "[D]one, Edit, Abandon, Quit ?"
175         answer = "XXX"
176         while prompt.find(answer) == -1:
177             answer = utils.our_raw_input(prompt)
178             m = re_default_answer.search(prompt)
179             if answer == "":
180                 answer = m.group(1)
181             answer = answer[:1].upper()
182     os.unlink(temp_filename)
183     if answer == 'A':
184         return
185     elif answer == 'Q':
186         return 0
187
188     comment = NewComment()
189     comment.policy_queue = upload.policy_queue
190     comment.package = upload.changes.source
191     comment.version = upload.changes.version
192     comment.comment = newnote
193     comment.author  = utils.whoami()
194     comment.trainee = trainee
195     session.add(comment)
196     session.commit()
197
198 ###############################################################################
199
200 # FIXME: Should move into the database
201 # suite names DMs can upload to
202 dm_suites = ['unstable', 'experimental', 'squeeze-backports','squeeze-backports-sloppy', 'wheezy-backports']
203
204 def get_newest_source(source, session):
205     'returns the newest DBSource object in dm_suites'
206     ## the most recent version of the package uploaded to unstable or
207     ## experimental includes the field "DM-Upload-Allowed: yes" in the source
208     ## section of its control file
209     q = session.query(DBSource).filter_by(source = source). \
210         filter(DBSource.suites.any(Suite.suite_name.in_(dm_suites))). \
211         order_by(desc('source.version'))
212     return q.first()
213
214 def get_suite_version_by_source(source, session):
215     'returns a list of tuples (suite_name, version) for source package'
216     q = session.query(Suite.suite_name, DBSource.version). \
217         join(Suite.sources).filter_by(source = source)
218     return q.all()
219
220 def get_source_by_package_and_suite(package, suite_name, session):
221     '''
222     returns a DBSource query filtered by DBBinary.package and this package's
223     suite_name
224     '''
225     return session.query(DBSource). \
226         join(DBSource.binaries).filter_by(package = package). \
227         join(DBBinary.suites).filter_by(suite_name = suite_name)
228
229 def get_suite_version_by_package(package, arch_string, session):
230     '''
231     returns a list of tuples (suite_name, version) for binary package and
232     arch_string
233     '''
234     return session.query(Suite.suite_name, DBBinary.version). \
235         join(Suite.binaries).filter_by(package = package). \
236         join(DBBinary.architecture). \
237         filter(Architecture.arch_string.in_([arch_string, 'all'])).all()
238
239 class Upload(object):
240     """
241     Everything that has to do with an upload processed.
242
243     """
244     def __init__(self):
245         self.logger = None
246         self.pkg = Changes()
247         self.reset()
248
249     ###########################################################################
250
251     def update_subst(self):
252         """ Set up the per-package template substitution mappings """
253         raise Exception('to be removed')
254
255         cnf = Config()
256
257         # If 'dak process-unchecked' crashed out in the right place, architecture may still be a string.
258         if not self.pkg.changes.has_key("architecture") or not \
259            isinstance(self.pkg.changes["architecture"], dict):
260             self.pkg.changes["architecture"] = { "Unknown" : "" }
261
262         # and maintainer2047 may not exist.
263         if not self.pkg.changes.has_key("maintainer2047"):
264             self.pkg.changes["maintainer2047"] = cnf["Dinstall::MyEmailAddress"]
265
266         self.Subst["__ARCHITECTURE__"] = " ".join(self.pkg.changes["architecture"].keys())
267         self.Subst["__CHANGES_FILENAME__"] = os.path.basename(self.pkg.changes_file)
268         self.Subst["__FILE_CONTENTS__"] = self.pkg.changes.get("filecontents", "")
269
270         # For source uploads the Changed-By field wins; otherwise Maintainer wins.
271         if self.pkg.changes["architecture"].has_key("source") and \
272            self.pkg.changes["changedby822"] != "" and \
273            (self.pkg.changes["changedby822"] != self.pkg.changes["maintainer822"]):
274
275             self.Subst["__MAINTAINER_FROM__"] = self.pkg.changes["changedby2047"]
276             self.Subst["__MAINTAINER_TO__"] = "%s, %s" % (self.pkg.changes["changedby2047"], self.pkg.changes["maintainer2047"])
277             self.Subst["__MAINTAINER__"] = self.pkg.changes.get("changed-by", "Unknown")
278         else:
279             self.Subst["__MAINTAINER_FROM__"] = self.pkg.changes["maintainer2047"]
280             self.Subst["__MAINTAINER_TO__"] = self.pkg.changes["maintainer2047"]
281             self.Subst["__MAINTAINER__"] = self.pkg.changes.get("maintainer", "Unknown")
282
283         # Process policy doesn't set the fingerprint field and I don't want to make it
284         # do it for now as I don't want to have to deal with the case where we accepted
285         # the package into PU-NEW, but the fingerprint has gone away from the keyring in
286         # the meantime so the package will be remarked as rejectable.  Urgh.
287         # TODO: Fix this properly
288         if self.pkg.changes.has_key('fingerprint'):
289             session = DBConn().session()
290             fpr = get_fingerprint(self.pkg.changes['fingerprint'], session)
291             if fpr and self.check_if_upload_is_sponsored("%s@debian.org" % fpr.uid.uid, fpr.uid.name):
292                 if self.pkg.changes.has_key("sponsoremail"):
293                     self.Subst["__MAINTAINER_TO__"] += ", %s" % self.pkg.changes["sponsoremail"]
294             session.close()
295
296         if cnf.has_key("Dinstall::TrackingServer") and self.pkg.changes.has_key("source"):
297             self.Subst["__MAINTAINER_TO__"] += "\nBcc: %s@%s" % (self.pkg.changes["source"], cnf["Dinstall::TrackingServer"])
298
299         # Apply any global override of the Maintainer field
300         if cnf.get("Dinstall::OverrideMaintainer"):
301             self.Subst["__MAINTAINER_TO__"] = cnf["Dinstall::OverrideMaintainer"]
302             self.Subst["__MAINTAINER_FROM__"] = cnf["Dinstall::OverrideMaintainer"]
303
304         self.Subst["__REJECT_MESSAGE__"] = self.package_info()
305         self.Subst["__SOURCE__"] = self.pkg.changes.get("source", "Unknown")
306         self.Subst["__VERSION__"] = self.pkg.changes.get("version", "Unknown")
307         self.Subst["__SUITE__"] = ", ".join(self.pkg.changes["distribution"])
308
309     ###########################################################################
310
311     def check_distributions(self):
312         "Check and map the Distribution field"
313
314         Cnf = Config()
315
316         # Handle suite mappings
317         for m in Cnf.value_list("SuiteMappings"):
318             args = m.split()
319             mtype = args[0]
320             if mtype == "map" or mtype == "silent-map":
321                 (source, dest) = args[1:3]
322                 if self.pkg.changes["distribution"].has_key(source):
323                     del self.pkg.changes["distribution"][source]
324                     self.pkg.changes["distribution"][dest] = 1
325                     if mtype != "silent-map":
326                         self.notes.append("Mapping %s to %s." % (source, dest))
327                 if self.pkg.changes.has_key("distribution-version"):
328                     if self.pkg.changes["distribution-version"].has_key(source):
329                         self.pkg.changes["distribution-version"][source]=dest
330             elif mtype == "map-unreleased":
331                 (source, dest) = args[1:3]
332                 if self.pkg.changes["distribution"].has_key(source):
333                     for arch in self.pkg.changes["architecture"].keys():
334                         if arch not in [ a.arch_string for a in get_suite_architectures(source) ]:
335                             self.notes.append("Mapping %s to %s for unreleased architecture %s." % (source, dest, arch))
336                             del self.pkg.changes["distribution"][source]
337                             self.pkg.changes["distribution"][dest] = 1
338                             break
339             elif mtype == "ignore":
340                 suite = args[1]
341                 if self.pkg.changes["distribution"].has_key(suite):
342                     del self.pkg.changes["distribution"][suite]
343                     self.warnings.append("Ignoring %s as a target suite." % (suite))
344             elif mtype == "reject":
345                 suite = args[1]
346                 if self.pkg.changes["distribution"].has_key(suite):
347                     self.rejects.append("Uploads to %s are not accepted." % (suite))
348             elif mtype == "propup-version":
349                 # give these as "uploaded-to(non-mapped) suites-to-add-when-upload-obsoletes"
350                 #
351                 # changes["distribution-version"] looks like: {'testing': 'testing-proposed-updates'}
352                 if self.pkg.changes["distribution"].has_key(args[1]):
353                     self.pkg.changes.setdefault("distribution-version", {})
354                     for suite in args[2:]:
355                         self.pkg.changes["distribution-version"][suite] = suite
356
357         # Ensure there is (still) a target distribution
358         if len(self.pkg.changes["distribution"].keys()) < 1:
359             self.rejects.append("No valid distribution remaining.")
360
361         # Ensure target distributions exist
362         for suite in self.pkg.changes["distribution"].keys():
363             if not get_suite(suite.lower()):
364                 self.rejects.append("Unknown distribution `%s'." % (suite))
365
366     ###########################################################################
367
368     def per_suite_file_checks(self, f, suite, session):
369         raise Exception('removed')
370
371         # Handle component mappings
372         for m in cnf.value_list("ComponentMappings"):
373             (source, dest) = m.split()
374             if entry["component"] == source:
375                 entry["original component"] = source
376                 entry["component"] = dest
377
378     ###########################################################################
379
380     # Sanity check the time stamps of files inside debs.
381     # [Files in the near future cause ugly warnings and extreme time
382     #  travel can cause errors on extraction]
383
384     def check_if_upload_is_sponsored(self, uid_email, uid_name):
385         for key in "maintaineremail", "changedbyemail", "maintainername", "changedbyname":
386             if not self.pkg.changes.has_key(key):
387                 return False
388         uid_email = '@'.join(uid_email.split('@')[:2])
389         if uid_email in [self.pkg.changes["maintaineremail"], self.pkg.changes["changedbyemail"]]:
390             sponsored = False
391         elif uid_name in [self.pkg.changes["maintainername"], self.pkg.changes["changedbyname"]]:
392             sponsored = False
393             if uid_name == "":
394                 sponsored = True
395         else:
396             sponsored = True
397             sponsor_addresses = utils.gpg_get_key_addresses(self.pkg.changes["fingerprint"])
398             debian_emails = filter(lambda addr: addr.endswith('@debian.org'), sponsor_addresses)
399             if uid_email not in debian_emails:
400                 if debian_emails:
401                     uid_email = debian_emails[0]
402             if ("source" in self.pkg.changes["architecture"] and uid_email and utils.is_email_alias(uid_email)):
403                 if (self.pkg.changes["maintaineremail"] not in sponsor_addresses and
404                     self.pkg.changes["changedbyemail"] not in sponsor_addresses):
405                         self.pkg.changes["sponsoremail"] = uid_email
406
407         return sponsored
408
409     def check_dm_upload(self, fpr, session):
410         # Quoth the GR (http://www.debian.org/vote/2007/vote_003):
411         ## none of the uploaded packages are NEW
412         ## none of the packages are being taken over from other source packages
413         for b in self.pkg.changes["binary"].keys():
414             for suite in self.pkg.changes["distribution"].keys():
415                 for s in get_source_by_package_and_suite(b, suite, session):
416                     if s.source != self.pkg.changes["source"]:
417                         self.rejects.append("%s may not hijack %s from source package %s in suite %s" % (fpr.uid.uid, b, s, suite))
418
419     ###########################################################################
420     # End check_signed_by_key checks
421     ###########################################################################
422
423     def build_summaries(self):
424         """ Build a summary of changes the upload introduces. """
425
426         (byhand, new, summary, override_summary) = self.pkg.file_summary()
427
428         short_summary = summary
429
430         # This is for direport's benefit...
431         f = re_fdnic.sub("\n .\n", self.pkg.changes.get("changes", ""))
432
433         summary += "\n\nChanges:\n" + f
434
435         summary += "\n\nOverride entries for your package:\n" + override_summary + "\n"
436
437         summary += self.announce(short_summary, 0)
438
439         return (summary, short_summary)
440
441     ###########################################################################
442
443     def announce(self, short_summary, action):
444         """
445         Send an announce mail about a new upload.
446
447         @type short_summary: string
448         @param short_summary: Short summary text to include in the mail
449
450         @type action: bool
451         @param action: Set to false no real action will be done.
452
453         @rtype: string
454         @return: Textstring about action taken.
455
456         """
457
458         cnf = Config()
459
460         # Skip all of this if not sending mail to avoid confusing people
461         if cnf.has_key("Dinstall::Options::No-Mail") and cnf["Dinstall::Options::No-Mail"]:
462             return ""
463
464         # Only do announcements for source uploads with a recent dpkg-dev installed
465         if float(self.pkg.changes.get("format", 0)) < 1.6 or not \
466            self.pkg.changes["architecture"].has_key("source"):
467             return ""
468
469         announcetemplate = os.path.join(cnf["Dir::Templates"], 'process-unchecked.announce')
470
471         lists_todo = {}
472         summary = ""
473
474         # Get a unique list of target lists
475         for dist in self.pkg.changes["distribution"].keys():
476             suite = get_suite(dist)
477             if suite is None: continue
478             for tgt in suite.announce:
479                 lists_todo[tgt] = 1
480
481         self.Subst["__SHORT_SUMMARY__"] = short_summary
482
483         for announce_list in lists_todo.keys():
484             summary += "Announcing to %s\n" % (announce_list)
485
486             if action:
487                 self.update_subst()
488                 self.Subst["__ANNOUNCE_LIST_ADDRESS__"] = announce_list
489                 if cnf.get("Dinstall::TrackingServer") and \
490                    self.pkg.changes["architecture"].has_key("source"):
491                     trackingsendto = "Bcc: %s@%s" % (self.pkg.changes["source"], cnf["Dinstall::TrackingServer"])
492                     self.Subst["__ANNOUNCE_LIST_ADDRESS__"] += "\n" + trackingsendto
493
494                 mail_message = utils.TemplateSubst(self.Subst, announcetemplate)
495                 utils.send_mail(mail_message)
496
497                 del self.Subst["__ANNOUNCE_LIST_ADDRESS__"]
498
499         if cnf.find_b("Dinstall::CloseBugs") and cnf.has_key("Dinstall::BugServer"):
500             summary = self.close_bugs(summary, action)
501
502         del self.Subst["__SHORT_SUMMARY__"]
503
504         return summary
505
506     ###########################################################################
507
508     def check_override(self):
509         """
510         Checks override entries for validity. Mails "Override disparity" warnings,
511         if that feature is enabled.
512
513         Abandons the check if
514           - override disparity checks are disabled
515           - mail sending is disabled
516         """
517
518         cnf = Config()
519
520         # Abandon the check if override disparity checks have been disabled
521         if not cnf.find_b("Dinstall::OverrideDisparityCheck"):
522             return
523
524         summary = self.pkg.check_override()
525
526         if summary == "":
527             return
528
529         overridetemplate = os.path.join(cnf["Dir::Templates"], 'process-unchecked.override-disparity')
530
531         self.update_subst()
532         self.Subst["__SUMMARY__"] = summary
533         mail_message = utils.TemplateSubst(self.Subst, overridetemplate)
534         utils.send_mail(mail_message)
535         del self.Subst["__SUMMARY__"]
536
537     ################################################################################
538     def get_anyversion(self, sv_list, suite):
539         """
540         @type sv_list: list
541         @param sv_list: list of (suite, version) tuples to check
542
543         @type suite: string
544         @param suite: suite name
545
546         Description: TODO
547         """
548         Cnf = Config()
549         anyversion = None
550         anysuite = [suite] + [ vc.reference.suite_name for vc in get_version_checks(suite, "Enhances") ]
551         for (s, v) in sv_list:
552             if s in [ x.lower() for x in anysuite ]:
553                 if not anyversion or apt_pkg.version_compare(anyversion, v) <= 0:
554                     anyversion = v
555
556         return anyversion
557
558     ################################################################################
559
560     def cross_suite_version_check(self, sv_list, filename, new_version, sourceful=False):
561         """
562         @type sv_list: list
563         @param sv_list: list of (suite, version) tuples to check
564
565         @type filename: string
566         @param filename: XXX
567
568         @type new_version: string
569         @param new_version: XXX
570
571         Ensure versions are newer than existing packages in target
572         suites and that cross-suite version checking rules as
573         set out in the conf file are satisfied.
574         """
575
576         cnf = Config()
577
578         # Check versions for each target suite
579         for target_suite in self.pkg.changes["distribution"].keys():
580             # Check we can find the target suite
581             ts = get_suite(target_suite)
582             if ts is None:
583                 self.rejects.append("Cannot find target suite %s to perform version checks" % target_suite)
584                 continue
585
586             must_be_newer_than = [ vc.reference.suite_name for vc in get_version_checks(target_suite, "MustBeNewerThan") ]
587             must_be_older_than = [ vc.reference.suite_name for vc in get_version_checks(target_suite, "MustBeOlderThan") ]
588
589             # Enforce "must be newer than target suite" even if conffile omits it
590             if target_suite not in must_be_newer_than:
591                 must_be_newer_than.append(target_suite)
592
593             for (suite, existent_version) in sv_list:
594                 vercmp = apt_pkg.version_compare(new_version, existent_version)
595
596                 if suite in must_be_newer_than and sourceful and vercmp < 1:
597                     self.rejects.append("%s: old version (%s) in %s >= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite))
598
599                 if suite in must_be_older_than and vercmp > -1:
600                     cansave = 0
601
602                     if self.pkg.changes.get('distribution-version', {}).has_key(suite):
603                         # we really use the other suite, ignoring the conflicting one ...
604                         addsuite = self.pkg.changes["distribution-version"][suite]
605
606                         add_version = self.get_anyversion(sv_list, addsuite)
607                         target_version = self.get_anyversion(sv_list, target_suite)
608
609                         if not add_version:
610                             # not add_version can only happen if we map to a suite
611                             # that doesn't enhance the suite we're propup'ing from.
612                             # so "propup-ver x a b c; map a d" is a problem only if
613                             # d doesn't enhance a.
614                             #
615                             # i think we could always propagate in this case, rather
616                             # than complaining. either way, this isn't a REJECT issue
617                             #
618                             # And - we really should complain to the dorks who configured dak
619                             self.warnings.append("%s is mapped to, but not enhanced by %s - adding anyways" % (suite, addsuite))
620                             self.pkg.changes.setdefault("propdistribution", {})
621                             self.pkg.changes["propdistribution"][addsuite] = 1
622                             cansave = 1
623                         elif not target_version:
624                             # not targets_version is true when the package is NEW
625                             # we could just stick with the "...old version..." REJECT
626                             # for this, I think.
627                             self.rejects.append("Won't propogate NEW packages.")
628                         elif apt_pkg.version_compare(new_version, add_version) < 0:
629                             # propogation would be redundant. no need to reject though.
630                             self.warnings.append("ignoring versionconflict: %s: old version (%s) in %s <= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite))
631                             cansave = 1
632                         elif apt_pkg.version_compare(new_version, add_version) > 0 and \
633                              apt_pkg.version_compare(add_version, target_version) >= 0:
634                             # propogate!!
635                             self.warnings.append("Propogating upload to %s" % (addsuite))
636                             self.pkg.changes.setdefault("propdistribution", {})
637                             self.pkg.changes["propdistribution"][addsuite] = 1
638                             cansave = 1
639
640                     if not cansave:
641                         self.rejects.append("%s: old version (%s) in %s <= new version (%s) targeted at %s." % (filename, existent_version, suite, new_version, target_suite))
642
643     ################################################################################
644
645     def accepted_checks(self, overwrite_checks, session):
646         # Recheck anything that relies on the database; since that's not
647         # frozen between accept and our run time when called from p-a.
648
649         # overwrite_checks is set to False when installing to stable/oldstable
650
651         propogate={}
652         nopropogate={}
653
654         for checkfile in self.pkg.files.keys():
655             # The .orig.tar.gz can disappear out from under us is it's a
656             # duplicate of one in the archive.
657             if not self.pkg.files.has_key(checkfile):
658                 continue
659
660             entry = self.pkg.files[checkfile]
661
662             # propogate in the case it is in the override tables:
663             for suite in self.pkg.changes.get("propdistribution", {}).keys():
664                 if self.in_override_p(entry["package"], entry["component"], suite, entry.get("dbtype",""), checkfile, session):
665                     propogate[suite] = 1
666                 else:
667                     nopropogate[suite] = 1
668
669         for suite in propogate.keys():
670             if suite in nopropogate:
671                 continue
672             self.pkg.changes["distribution"][suite] = 1
673
674         for checkfile in self.pkg.files.keys():
675             # Check the package is still in the override tables
676             for suite in self.pkg.changes["distribution"].keys():
677                 if not self.in_override_p(entry["package"], entry["component"], suite, entry.get("dbtype",""), checkfile, session):
678                     self.rejects.append("%s is NEW for %s." % (checkfile, suite))