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