]> git.decadent.org.uk Git - dak.git/blob - dak/cruft_report.py
Ignore yet another warning in cruft-report.
[dak.git] / dak / cruft_report.py
1 #!/usr/bin/env python
2
3 """
4 Check for obsolete binary packages
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2000-2006 James Troup <james@nocrew.org>
8 @copyright: 2009      Torsten Werner <twerner@debian.org>
9 @license: GNU General Public License version 2 or later
10 """
11
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26 ################################################################################
27
28 # ``If you're claiming that's a "problem" that needs to be "fixed",
29 #   you might as well write some letters to God about how unfair entropy
30 #   is while you're at it.'' -- 20020802143104.GA5628@azure.humbug.org.au
31
32 ## TODO:  fix NBS looping for version, implement Dubious NBS, fix up output of
33 ##        duplicate source package stuff, improve experimental ?, add overrides,
34 ##        avoid ANAIS for duplicated packages
35
36 ################################################################################
37
38 import warnings
39 warnings.filterwarnings('ignore', \
40     "apt_pkg\.ParseTagFile\(\) is deprecated\. Please see apt_pkg\.TagFile\(\) for the replacement\.", \
41     DeprecationWarning)
42 warnings.filterwarnings('ignore', \
43     "Attribute '.*' of the 'apt_pkg\.TagFile' object is deprecated, use '.*' instead\.", \
44     DeprecationWarning)
45 warnings.filterwarnings('ignore', \
46     "Attribute 'Find' of the 'apt_pkg\.TagSection' object is deprecated, use 'find' instead\.", \
47     DeprecationWarning)
48
49 ################################################################################
50
51 import commands, os, sys, re
52 import apt_pkg
53
54 from daklib.config import Config
55 from daklib.dbconn import *
56 from daklib import utils
57 from daklib.regexes import re_extract_src_version
58 from daklib.cruft import *
59
60 ################################################################################
61
62 no_longer_in_suite = {}; # Really should be static to add_nbs, but I'm lazy
63
64 source_binaries = {}
65 source_versions = {}
66
67 ################################################################################
68
69 def usage(exit_code=0):
70     print """Usage: dak cruft-report
71 Check for obsolete or duplicated packages.
72
73   -h, --help                show this help and exit.
74   -m, --mode=MODE           chose the MODE to run in (full or daily).
75   -s, --suite=SUITE         check suite SUITE.
76   -w, --wanna-build-dump    where to find the copies of http://buildd.debian.org/stats/*.txt"""
77     sys.exit(exit_code)
78
79 ################################################################################
80
81 def add_nbs(nbs_d, source, version, package, suite_id, session):
82     # Ensure the package is still in the suite (someone may have already removed it)
83     if no_longer_in_suite.has_key(package):
84         return
85     else:
86         q = session.execute("""SELECT b.id FROM binaries b, bin_associations ba
87                                 WHERE ba.bin = b.id AND ba.suite = :suite_id
88                                   AND b.package = :package LIMIT 1""", {'suite_id': suite_id,
89                                                                          'package': package})
90         if not q.fetchall():
91             no_longer_in_suite[package] = ""
92             return
93
94     nbs_d.setdefault(source, {})
95     nbs_d[source].setdefault(version, {})
96     nbs_d[source][version][package] = ""
97
98 ################################################################################
99
100 # Check for packages built on architectures they shouldn't be.
101 def do_anais(architecture, binaries_list, source, session):
102     if architecture == "any" or architecture == "all":
103         return ""
104
105     anais_output = ""
106     architectures = {}
107     for arch in architecture.split():
108         architectures[arch.strip()] = ""
109     for binary in binaries_list:
110         q = session.execute("""SELECT a.arch_string, b.version
111                                 FROM binaries b, bin_associations ba, architecture a
112                                WHERE ba.suite = :suiteid AND ba.bin = b.id
113                                  AND b.architecture = a.id AND b.package = :package""",
114                              {'suiteid': suite_id, 'package': binary})
115         ql = q.fetchall()
116         versions = []
117         for i in ql:
118             arch = i[0]
119             version = i[1]
120             if architectures.has_key(arch):
121                 versions.append(version)
122         versions.sort(apt_pkg.VersionCompare)
123         if versions:
124             latest_version = versions.pop()
125         else:
126             latest_version = None
127         # Check for 'invalid' architectures
128         versions_d = {}
129         for i in ql:
130             arch = i[0]
131             version = i[1]
132             if not architectures.has_key(arch):
133                 versions_d.setdefault(version, [])
134                 versions_d[version].append(arch)
135
136         if versions_d != {}:
137             anais_output += "\n (*) %s_%s [%s]: %s\n" % (binary, latest_version, source, architecture)
138             versions = versions_d.keys()
139             versions.sort(apt_pkg.VersionCompare)
140             for version in versions:
141                 arches = versions_d[version]
142                 arches.sort()
143                 anais_output += "    o %s: %s\n" % (version, ", ".join(arches))
144     return anais_output
145
146
147 ################################################################################
148
149 # Check for out-of-date binaries on architectures that do not want to build that
150 # package any more, and have them listed as Not-For-Us
151 def do_nfu(nfu_packages):
152     output = ""
153     
154     a2p = {}
155
156     for architecture in nfu_packages:
157         a2p[architecture] = []
158         for (package,bver,sver) in nfu_packages[architecture]:
159             output += "  * [%s] does not want %s (binary %s, source %s)\n" % (architecture, package, bver, sver)
160             a2p[architecture].append(package)
161
162
163     if output:
164         print "Obsolete by Not-For-Us"
165         print "----------------------"
166         print
167         print output
168
169         print "Suggested commands:"
170         for architecture in a2p:
171             if a2p[architecture]:
172                 print (" dak rm -m \"[auto-cruft] NFU\" -s %s -a %s -b %s" % 
173                     (suite.suite_name, architecture, " ".join(a2p[architecture])))
174         print
175
176 def parse_nfu(architecture):
177     cnf = Config()
178     # utils/hpodder_1.1.5.0: Not-For-Us [optional:out-of-date]
179     r = re.compile("^\w+/([^_]+)_.*: Not-For-Us")
180
181     ret = set()
182     
183     filename = "%s/%s-all.txt" % (cnf["Cruft-Report::Options::Wanna-Build-Dump"], architecture)
184
185     # Not all architectures may have a wanna-build dump, so we want to ignore missin
186     # files
187     if os.path.exists(filename):
188         f = utils.open_file(filename)
189         for line in f:
190             if line[0] == ' ':
191                 continue
192
193             m = r.match(line)
194             if m:
195                 ret.add(m.group(1))
196
197         f.close()
198     else:
199         utils.warn("No wanna-build dump file for architecture %s" % architecture)
200     return ret
201
202 ################################################################################
203
204 def do_newer_version(lowersuite_name, highersuite_name, code, session):
205     list = newer_version(lowersuite_name, highersuite_name, session)
206     if len(list) > 0:
207         nv_to_remove = []
208         title = "Newer version in %s" % lowersuite_name
209         print title
210         print "-" * len(title)
211         print
212         for i in list:
213             (source, higher_version, lower_version) = i
214             print " o %s (%s, %s)" % (source, higher_version, lower_version)
215             nv_to_remove.append(source)
216         print
217         print "Suggested command:"
218         print " dak rm -m \"[auto-cruft] %s\" -s %s %s" % (code, highersuite_name,
219                                                            " ".join(nv_to_remove))
220         print
221
222 ################################################################################
223
224 def queryWithoutSource(suite_id, session):
225     """searches for arch: all packages from suite that do no longer
226     reference a source package in the same suite
227
228     subquery unique_binaries: selects all packages with only 1 version
229     in suite since 'dak rm' does not allow to specify version numbers"""
230
231     query = """
232     with unique_binaries as
233         (select package, max(version) as version, max(source) as source
234             from bin_associations_binaries
235             where architecture = 2 and suite = :suite_id
236             group by package having count(*) = 1)
237     select ub.package, ub.version
238         from unique_binaries ub
239         left join src_associations_src sas
240             on ub.source = sas.src and sas.suite = :suite_id
241         where sas.id is null
242         order by ub.package"""
243     return session.execute(query, { 'suite_id': suite_id })
244
245 def reportWithoutSource(suite_name, suite_id, session):
246     rows = queryWithoutSource(suite_id, session)
247     title = 'packages without source in suite %s' % suite_name
248     if rows.rowcount > 0:
249         print '%s\n%s\n' % (title, '-' * len(title))
250     message = '"[auto-cruft] no longer built from source"'
251     for row in rows:
252         (package, version) = row
253         print "* package %s in version %s is no longer built from source" % \
254             (package, version)
255         print "  - suggested command:"
256         print "    dak rm -m %s -s %s -a all -p -R -b %s\n" % \
257             (message, suite_name, package)
258
259 def queryNewerAll(suite_name, session):
260     """searches for arch != all packages that have an arch == all
261     package with a higher version in the same suite"""
262
263     query = """
264 select bab1.package, bab1.version as oldver,
265     array_to_string(array_agg(a.arch_string), ',') as oldarch,
266     bab2.version as newver
267     from bin_associations_binaries bab1
268     join bin_associations_binaries bab2
269         on bab1.package = bab2.package and bab1.version < bab2.version and
270         bab1.suite = bab2.suite and bab1.architecture > 2 and
271         bab2.architecture = 2
272     join architecture a on bab1.architecture = a.id
273     join suite s on bab1.suite = s.id
274     where s.suite_name = :suite_name
275     group by bab1.package, oldver, bab1.suite, newver"""
276     return session.execute(query, { 'suite_name': suite_name })
277
278 def reportNewerAll(suite_name, session):
279     rows = queryNewerAll(suite_name, session)
280     title = 'obsolete arch any packages in suite %s' % suite_name
281     if rows.rowcount > 0:
282         print '%s\n%s\n' % (title, '-' * len(title))
283     message = '"[auto-cruft] obsolete arch any package"'
284     for row in rows:
285         (package, oldver, oldarch, newver) = row
286         print "* package %s is arch any in version %s but arch all in version %s" % \
287             (package, oldver, newver)
288         print "  - suggested command:"
289         print "    dak rm -m %s -s %s -a %s -p -b %s\n" % \
290             (message, suite_name, oldarch, package)
291
292 def queryNBS(suite_id, session):
293     """This one is really complex. It searches arch != all packages that
294     are no longer built from current source packages in suite.
295
296     temp table unique_binaries: will be populated with packages that
297     have only one version in suite because 'dak rm' does not allow
298     specifying version numbers
299
300     temp table newest_binaries: will be populated with packages that are
301     built from current sources
302
303     subquery uptodate_arch: returns all architectures built from current
304     sources
305
306     subquery unique_binaries_uptodate_arch: returns all packages in
307     architectures from uptodate_arch
308
309     subquery unique_binaries_uptodate_arch_agg: same as
310     unique_binaries_uptodate_arch but with column architecture
311     aggregated to array
312
313     subquery uptodate_packages: similar to uptodate_arch but returns all
314     packages built from current sources
315
316     subquery outdated_packages: returns all packages with architectures
317     no longer built from current source
318     """
319
320     query = """
321 create temp table unique_binaries (
322     package text not null,
323     architecture integer not null,
324     source integer not null);
325
326 insert into unique_binaries
327     select bab.package, bab.architecture, max(bab.source)
328         from bin_associations_binaries bab
329         where bab.suite = :suite_id and bab.architecture > 2
330         group by package, architecture having count(*) = 1;
331
332 create temp table newest_binaries (
333     package text not null,
334     architecture integer not null,
335     source text not null,
336     version debversion not null);
337
338 insert into newest_binaries
339     select ub.package, ub.architecture, nsa.source, nsa.version
340         from unique_binaries ub
341         join newest_src_association nsa
342             on ub.source = nsa.src and nsa.suite = :suite_id;
343
344 with uptodate_arch as
345     (select architecture, source, version
346         from newest_binaries
347         group by architecture, source, version),
348     unique_binaries_uptodate_arch as
349     (select ub.package, ub.architecture, ua.source, ua.version
350         from unique_binaries ub
351         join source s
352             on ub.source = s.id
353         join uptodate_arch ua
354             on ub.architecture = ua.architecture and s.source = ua.source),
355     unique_binaries_uptodate_arch_agg as
356     (select ubua.package,
357         array(select unnest(array_agg(a.arch_string)) order by 1) as arch_list,
358         ubua.source, ubua.version
359         from unique_binaries_uptodate_arch ubua
360         join architecture a
361             on ubua.architecture = a.id
362         group by ubua.source, ubua.version, ubua.package),
363     uptodate_packages as
364     (select package, source, version
365         from newest_binaries
366         group by package, source, version),
367     outdated_packages as
368     (select array(select unnest(array_agg(package)) order by 1) as pkg_list,
369         arch_list, source, version
370         from unique_binaries_uptodate_arch_agg
371         where package not in
372             (select package from uptodate_packages)
373         group by arch_list, source, version)
374     select * from outdated_packages order by source"""
375     return session.execute(query, { 'suite_id': suite_id })
376
377 def reportNBS(suite_name, suite_id):
378     session = DBConn().session()
379     nbsRows = queryNBS(suite_id, session)
380     title = 'NBS packages in suite %s' % suite_name
381     if nbsRows.rowcount > 0:
382         print '%s\n%s\n' % (title, '-' * len(title))
383     for row in nbsRows:
384         (pkg_list, arch_list, source, version) = row
385         pkg_string = ' '.join(pkg_list)
386         arch_string = ','.join(arch_list)
387         print "* source package %s version %s no longer builds" % \
388             (source, version)
389         print "  binary package(s): %s" % pkg_string
390         print "  on %s" % arch_string
391         print "  - suggested command:"
392         message = '"[auto-cruft] NBS (no longer built by %s)"' % source
393         print "    dak rm -m %s -s %s -a %s -p -R -b %s\n" % \
394             (message, suite_name, arch_string, pkg_string)
395     session.close()
396
397 def reportAllNBS(suite_name, suite_id, session):
398     reportWithoutSource(suite_name, suite_id, session)
399     reportNewerAll(suite_name, session)
400     reportNBS(suite_name, suite_id)
401
402 ################################################################################
403
404 def do_dubious_nbs(dubious_nbs):
405     print "Dubious NBS"
406     print "-----------"
407     print
408
409     dubious_nbs_keys = dubious_nbs.keys()
410     dubious_nbs_keys.sort()
411     for source in dubious_nbs_keys:
412         print " * %s_%s builds: %s" % (source,
413                                        source_versions.get(source, "??"),
414                                        source_binaries.get(source, "(source does not exist)"))
415         print "      won't admit to building:"
416         versions = dubious_nbs[source].keys()
417         versions.sort(apt_pkg.VersionCompare)
418         for version in versions:
419             packages = dubious_nbs[source][version].keys()
420             packages.sort()
421             print "        o %s: %s" % (version, ", ".join(packages))
422
423         print
424
425 ################################################################################
426
427 def obsolete_source(suite_name, session):
428     """returns obsolete source packages for suite_name without binaries
429     in the same suite sorted by install_date; install_date should help
430     detecting source only (or binary throw away) uploads; duplicates in
431     the suite are skipped
432
433     subquery 'source_suite_unique' returns source package names from
434     suite without duplicates; the rationale behind is that neither
435     cruft-report nor rm cannot handle duplicates (yet)"""
436
437     query = """
438 WITH source_suite_unique AS
439     (SELECT source, suite
440         FROM source_suite GROUP BY source, suite HAVING count(*) = 1)
441 SELECT ss.src, ss.source, ss.version,
442     to_char(ss.install_date, 'YYYY-MM-DD') AS install_date
443     FROM source_suite ss
444     JOIN source_suite_unique ssu
445         ON ss.source = ssu.source AND ss.suite = ssu.suite
446     JOIN suite s ON s.id = ss.suite
447     LEFT JOIN bin_associations_binaries bab
448         ON ss.src = bab.source AND ss.suite = bab.suite
449     WHERE s.suite_name = :suite_name AND bab.id IS NULL
450     ORDER BY install_date"""
451     args = { 'suite_name': suite_name }
452     return session.execute(query, args)
453
454 def source_bin(source, session):
455     """returns binaries built by source for all or no suite grouped and
456     ordered by package name"""
457
458     query = """
459 SELECT b.package
460     FROM binaries b
461     JOIN src_associations_src sas ON b.source = sas.src
462     WHERE sas.source = :source
463     GROUP BY b.package
464     ORDER BY b.package"""
465     args = { 'source': source }
466     return session.execute(query, args)
467
468 def newest_source_bab(suite_name, package, session):
469     """returns newest source that builds binary package in suite grouped
470     and sorted by source and package name"""
471
472     query = """
473 SELECT sas.source, MAX(sas.version) AS srcver
474     FROM src_associations_src sas
475     JOIN bin_associations_binaries bab ON sas.src = bab.source
476     JOIN suite s on s.id = bab.suite
477     WHERE s.suite_name = :suite_name AND bab.package = :package
478         GROUP BY sas.source, bab.package
479         ORDER BY sas.source, bab.package"""
480     args = { 'suite_name': suite_name, 'package': package }
481     return session.execute(query, args)
482
483 def report_obsolete_source(suite_name, session):
484     rows = obsolete_source(suite_name, session)
485     if rows.rowcount == 0:
486         return
487     print \
488 """Obsolete source packages in suite %s
489 ----------------------------------%s\n""" % \
490         (suite_name, '-' * len(suite_name))
491     for os_row in rows.fetchall():
492         (src, old_source, version, install_date) = os_row
493         print " * obsolete source %s version %s installed at %s" % \
494             (old_source, version, install_date)
495         for sb_row in source_bin(old_source, session):
496             (package, ) = sb_row
497             print "   - has built binary %s" % package
498             for nsb_row in newest_source_bab(suite_name, package, session):
499                 (new_source, srcver) = nsb_row
500                 print "     currently built by source %s version %s" % \
501                     (new_source, srcver)
502         print "   - suggested command:"
503         rm_opts = "-S -p -m \"[auto-cruft] obsolete source package\""
504         print "     dak rm -s %s %s %s\n" % (suite_name, rm_opts, old_source)
505
506 def get_suite_binaries(suite, session):
507     # Initalize a large hash table of all binary packages
508     binaries = {}
509
510     print "Getting a list of binary packages in %s..." % suite.suite_name
511     q = session.execute("""SELECT distinct b.package
512                              FROM binaries b, bin_associations ba
513                             WHERE ba.suite = :suiteid AND ba.bin = b.id""",
514                            {'suiteid': suite.suite_id})
515     for i in q.fetchall():
516         binaries[i[0]] = ""
517
518     return binaries
519
520 ################################################################################
521
522 def main ():
523     global suite, suite_id, source_binaries, source_versions
524
525     cnf = Config()
526
527     Arguments = [('h',"help","Cruft-Report::Options::Help"),
528                  ('m',"mode","Cruft-Report::Options::Mode", "HasArg"),
529                  ('s',"suite","Cruft-Report::Options::Suite","HasArg"),
530                  ('w',"wanna-build-dump","Cruft-Report::Options::Wanna-Build-Dump","HasArg")]
531     for i in [ "help" ]:
532         if not cnf.has_key("Cruft-Report::Options::%s" % (i)):
533             cnf["Cruft-Report::Options::%s" % (i)] = ""
534     cnf["Cruft-Report::Options::Suite"] = cnf["Dinstall::DefaultSuite"]
535
536     if not cnf.has_key("Cruft-Report::Options::Mode"):
537         cnf["Cruft-Report::Options::Mode"] = "daily"
538
539     if not cnf.has_key("Cruft-Report::Options::Wanna-Build-Dump"):
540         cnf["Cruft-Report::Options::Wanna-Build-Dump"] = "/srv/ftp-master.debian.org/scripts/nfu"
541
542     apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
543
544     Options = cnf.SubTree("Cruft-Report::Options")
545     if Options["Help"]:
546         usage()
547
548     # Set up checks based on mode
549     if Options["Mode"] == "daily":
550         checks = [ "nbs", "nviu", "nvit", "obsolete source", "nfu" ]
551     elif Options["Mode"] == "full":
552         checks = [ "nbs", "nviu", "nvit", "obsolete source", "nfu", "dubious nbs", "bnb", "bms", "anais" ]
553     else:
554         utils.warn("%s is not a recognised mode - only 'full' or 'daily' are understood." % (Options["Mode"]))
555         usage(1)
556
557     session = DBConn().session()
558
559     bin_pkgs = {}
560     src_pkgs = {}
561     bin2source = {}
562     bins_in_suite = {}
563     nbs = {}
564     source_versions = {}
565
566     anais_output = ""
567
568     nfu_packages = {}
569
570     suite = get_suite(Options["Suite"].lower(), session)
571     suite_id = suite.suite_id
572     suite_name = suite.suite_name.lower()
573
574     if "obsolete source" in checks:
575         report_obsolete_source(suite_name, session)
576
577     if "nbs" in checks:
578         reportAllNBS(suite_name, suite_id, session)
579
580     bin_not_built = {}
581
582     if "bnb" in checks:
583         bins_in_suite = get_suite_binaries(suite, session)
584
585     # Checks based on the Sources files
586     components = cnf.ValueList("Suite::%s::Components" % (suite_name))
587     for component in components:
588         filename = "%s/dists/%s/%s/source/Sources.gz" % (cnf["Dir::Root"], suite_name, component)
589         # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
590         (fd, temp_filename) = utils.temp_filename()
591         (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
592         if (result != 0):
593             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
594             sys.exit(result)
595         sources = utils.open_file(temp_filename)
596         Sources = apt_pkg.ParseTagFile(sources)
597         while Sources.Step():
598             source = Sources.Section.Find('Package')
599             source_version = Sources.Section.Find('Version')
600             architecture = Sources.Section.Find('Architecture')
601             binaries = Sources.Section.Find('Binary')
602             binaries_list = [ i.strip() for i in  binaries.split(',') ]
603
604             if "bnb" in checks:
605                 # Check for binaries not built on any architecture.
606                 for binary in binaries_list:
607                     if not bins_in_suite.has_key(binary):
608                         bin_not_built.setdefault(source, {})
609                         bin_not_built[source][binary] = ""
610
611             if "anais" in checks:
612                 anais_output += do_anais(architecture, binaries_list, source, session)
613
614             # build indices for checking "no source" later
615             source_index = component + '/' + source
616             src_pkgs[source] = source_index
617             for binary in binaries_list:
618                 bin_pkgs[binary] = source
619             source_binaries[source] = binaries
620             source_versions[source] = source_version
621
622         sources.close()
623         os.unlink(temp_filename)
624
625     # Checks based on the Packages files
626     check_components = components[:]
627     if suite_name != "experimental":
628         check_components.append('main/debian-installer');
629
630     for component in check_components:
631         architectures = [ a.arch_string for a in get_suite_architectures(suite_name,
632                                                                          skipsrc=True, skipall=True,
633                                                                          session=session) ]
634         for architecture in architectures:
635             if component == 'main/debian-installer' and re.match("kfreebsd", architecture):
636                 continue
637             filename = "%s/dists/%s/%s/binary-%s/Packages.gz" % (cnf["Dir::Root"], suite_name, component, architecture)
638             # apt_pkg.ParseTagFile needs a real file handle
639             (fd, temp_filename) = utils.temp_filename()
640             (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
641             if (result != 0):
642                 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
643                 sys.exit(result)
644
645             if "nfu" in checks:
646                 nfu_packages.setdefault(architecture,[])
647                 nfu_entries = parse_nfu(architecture)
648
649             packages = utils.open_file(temp_filename)
650             Packages = apt_pkg.ParseTagFile(packages)
651             while Packages.Step():
652                 package = Packages.Section.Find('Package')
653                 source = Packages.Section.Find('Source', "")
654                 version = Packages.Section.Find('Version')
655                 if source == "":
656                     source = package
657                 if bin2source.has_key(package) and \
658                        apt_pkg.VersionCompare(version, bin2source[package]["version"]) > 0:
659                     bin2source[package]["version"] = version
660                     bin2source[package]["source"] = source
661                 else:
662                     bin2source[package] = {}
663                     bin2source[package]["version"] = version
664                     bin2source[package]["source"] = source
665                 if source.find("(") != -1:
666                     m = re_extract_src_version.match(source)
667                     source = m.group(1)
668                     version = m.group(2)
669                 if not bin_pkgs.has_key(package):
670                     nbs.setdefault(source,{})
671                     nbs[source].setdefault(package, {})
672                     nbs[source][package][version] = ""
673                 else:
674                     if "nfu" in checks:
675                         if package in nfu_entries and \
676                                version != source_versions[source]: # only suggest to remove out-of-date packages
677                             nfu_packages[architecture].append((package,version,source_versions[source]))
678                     
679             packages.close()
680             os.unlink(temp_filename)
681
682     # Distinguish dubious (version numbers match) and 'real' NBS (they don't)
683     dubious_nbs = {}
684     for source in nbs.keys():
685         for package in nbs[source].keys():
686             versions = nbs[source][package].keys()
687             versions.sort(apt_pkg.VersionCompare)
688             latest_version = versions.pop()
689             source_version = source_versions.get(source,"0")
690             if apt_pkg.VersionCompare(latest_version, source_version) == 0:
691                 add_nbs(dubious_nbs, source, latest_version, package, suite_id, session)
692
693     if "nviu" in checks:
694         do_newer_version('unstable', 'experimental', 'NVIU', session)
695
696     if "nvit" in checks:
697         do_newer_version('testing', 'testing-proposed-updates', 'NVIT', session)
698
699     ###
700
701     if Options["Mode"] == "full":
702         print "="*75
703         print
704
705     if "nfu" in checks:
706         do_nfu(nfu_packages)
707
708     if "bnb" in checks:
709         print "Unbuilt binary packages"
710         print "-----------------------"
711         print
712         keys = bin_not_built.keys()
713         keys.sort()
714         for source in keys:
715             binaries = bin_not_built[source].keys()
716             binaries.sort()
717             print " o %s: %s" % (source, ", ".join(binaries))
718         print
719
720     if "bms" in checks:
721         report_multiple_source(suite)
722
723     if "anais" in checks:
724         print "Architecture Not Allowed In Source"
725         print "----------------------------------"
726         print anais_output
727         print
728
729     if "dubious nbs" in checks:
730         do_dubious_nbs(dubious_nbs)
731
732
733 ################################################################################
734
735 if __name__ == '__main__':
736     main()