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