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