]> git.decadent.org.uk Git - dak.git/blob - dak/cruft_report.py
auto-decruft: Disable short options for NVI
[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     ORDER BY install_date"""
350     args = { 'suite_name': suite_name }
351     return session.execute(query, args)
352
353 def source_bin(source, session):
354     """returns binaries built by source for all or no suite grouped and
355     ordered by package name"""
356
357     query = """
358 SELECT b.package
359     FROM binaries b
360     JOIN src_associations_src sas ON b.source = sas.src
361     WHERE sas.source = :source
362     GROUP BY b.package
363     ORDER BY b.package"""
364     args = { 'source': source }
365     return session.execute(query, args)
366
367 def newest_source_bab(suite_name, package, session):
368     """returns newest source that builds binary package in suite grouped
369     and sorted by source and package name"""
370
371     query = """
372 SELECT sas.source, MAX(sas.version) AS srcver
373     FROM src_associations_src sas
374     JOIN bin_associations_binaries bab ON sas.src = bab.source
375     JOIN suite s on s.id = bab.suite
376     WHERE s.suite_name = :suite_name AND bab.package = :package
377         GROUP BY sas.source, bab.package
378         ORDER BY sas.source, bab.package"""
379     args = { 'suite_name': suite_name, 'package': package }
380     return session.execute(query, args)
381
382 def report_obsolete_source(suite_name, session):
383     rows = obsolete_source(suite_name, session)
384     if rows.rowcount == 0:
385         return
386     print \
387 """Obsolete source packages in suite %s
388 ----------------------------------%s\n""" % \
389         (suite_name, '-' * len(suite_name))
390     for os_row in rows.fetchall():
391         (src, old_source, version, install_date) = os_row
392         print " * obsolete source %s version %s installed at %s" % \
393             (old_source, version, install_date)
394         for sb_row in source_bin(old_source, session):
395             (package, ) = sb_row
396             print "   - has built binary %s" % package
397             for nsb_row in newest_source_bab(suite_name, package, session):
398                 (new_source, srcver) = nsb_row
399                 print "     currently built by source %s version %s" % \
400                     (new_source, srcver)
401         print "   - suggested command:"
402         rm_opts = "-S -p -m \"[auto-cruft] obsolete source package\""
403         print "     dak rm -s %s %s %s\n" % (suite_name, rm_opts, old_source)
404
405 def get_suite_binaries(suite, session):
406     # Initalize a large hash table of all binary packages
407     binaries = {}
408
409     print "Getting a list of binary packages in %s..." % suite.suite_name
410     q = session.execute("""SELECT distinct b.package
411                              FROM binaries b, bin_associations ba
412                             WHERE ba.suite = :suiteid AND ba.bin = b.id""",
413                            {'suiteid': suite.suite_id})
414     for i in q.fetchall():
415         binaries[i[0]] = ""
416
417     return binaries
418
419 ################################################################################
420
421 def report_outdated_nonfree(suite, session, rdeps=False):
422
423     packages = {}
424     query = """WITH outdated_sources AS (
425                  SELECT s.source, s.version, s.id
426                  FROM source s
427                  JOIN src_associations sa ON sa.source = s.id
428                  WHERE sa.suite IN (
429                    SELECT id
430                    FROM suite
431                    WHERE suite_name = :suite )
432                  AND sa.created < (now() - interval :delay)
433                  EXCEPT SELECT s.source, max(s.version) AS version, max(s.id)
434                  FROM source s
435                  JOIN src_associations sa ON sa.source = s.id
436                  WHERE sa.suite IN (
437                    SELECT id
438                    FROM suite
439                    WHERE suite_name = :suite )
440                  AND sa.created < (now() - interval :delay)
441                  GROUP BY s.source ),
442                binaries AS (
443                  SELECT b.package, s.source, (
444                    SELECT a.arch_string
445                    FROM architecture a
446                    WHERE a.id = b.architecture ) AS arch
447                  FROM binaries b
448                  JOIN outdated_sources s ON s.id = b.source
449                  JOIN bin_associations ba ON ba.bin = b.id
450                  JOIN override o ON o.package = b.package AND o.suite = ba.suite
451                  WHERE ba.suite IN (
452                    SELECT id
453                    FROM suite
454                    WHERE suite_name = :suite )
455                  AND o.component IN (
456                    SELECT id
457                    FROM component
458                    WHERE name = 'non-free' ) )
459                SELECT DISTINCT package, source, arch
460                FROM binaries
461                ORDER BY source, package, arch"""
462
463     res = session.execute(query, {'suite': suite, 'delay': "'15 days'"})
464     for package in res:
465         binary = package[0]
466         source = package[1]
467         arch = package[2]
468         if arch == 'all':
469             continue
470         if not source in packages:
471             packages[source] = {}
472         if not binary in packages[source]:
473             packages[source][binary] = set()
474         packages[source][binary].add(arch)
475     if packages:
476         title = 'Outdated non-free binaries in suite %s' % suite
477         message = '"[auto-cruft] outdated non-free binaries"'
478         print '%s\n%s\n' % (title, '-' * len(title))
479         for source in sorted(packages):
480             archs = set()
481             binaries = set()
482             print '* package %s has outdated non-free binaries' % source
483             print '  - suggested command:'
484             for binary in sorted(packages[source]):
485                 binaries.add(binary)
486                 archs = archs.union(packages[source][binary])
487             print '    dak rm -m %s -s %s -a %s -p -R -b %s' % \
488                    (message, suite, ','.join(archs), ' '.join(binaries))
489             if rdeps:
490                 if utils.check_reverse_depends(list(binaries), suite, archs, session, True):
491                     print
492                 else:
493                     print "  - No dependency problem found\n"
494             else:
495                 print
496
497 ################################################################################
498
499 def main ():
500     global suite, suite_id, source_binaries, source_versions
501
502     cnf = Config()
503
504     Arguments = [('h',"help","Cruft-Report::Options::Help"),
505                  ('m',"mode","Cruft-Report::Options::Mode", "HasArg"),
506                  ('R',"rdep-check", "Cruft-Report::Options::Rdep-Check"),
507                  ('s',"suite","Cruft-Report::Options::Suite","HasArg"),
508                  ('w',"wanna-build-dump","Cruft-Report::Options::Wanna-Build-Dump","HasArg")]
509     for i in [ "help", "Rdep-Check" ]:
510         if not cnf.has_key("Cruft-Report::Options::%s" % (i)):
511             cnf["Cruft-Report::Options::%s" % (i)] = ""
512
513     cnf["Cruft-Report::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable")
514
515     if not cnf.has_key("Cruft-Report::Options::Mode"):
516         cnf["Cruft-Report::Options::Mode"] = "daily"
517
518     if not cnf.has_key("Cruft-Report::Options::Wanna-Build-Dump"):
519         cnf["Cruft-Report::Options::Wanna-Build-Dump"] = "/srv/ftp-master.debian.org/scripts/nfu"
520
521     apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
522
523     Options = cnf.subtree("Cruft-Report::Options")
524     if Options["Help"]:
525         usage()
526
527     if Options["Rdep-Check"]:
528         rdeps = True
529     else:
530         rdeps = False
531
532     # Set up checks based on mode
533     if Options["Mode"] == "daily":
534         checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu" ]
535     elif Options["Mode"] == "full":
536         checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu", "dubious nbs", "bnb", "bms", "anais" ]
537     elif Options["Mode"] == "bdo":
538         checks = [ "nbs",  "obsolete source" ]
539     else:
540         utils.warn("%s is not a recognised mode - only 'full', 'daily' or 'bdo' are understood." % (Options["Mode"]))
541         usage(1)
542
543     session = DBConn().session()
544
545     bin_pkgs = {}
546     src_pkgs = {}
547     bin2source = {}
548     bins_in_suite = {}
549     nbs = {}
550     source_versions = {}
551
552     anais_output = ""
553
554     nfu_packages = {}
555
556     suite = get_suite(Options["Suite"].lower(), session)
557     if not suite:
558         utils.fubar("Cannot find suite %s" % Options["Suite"].lower())
559
560     suite_id = suite.suite_id
561     suite_name = suite.suite_name.lower()
562
563     if "obsolete source" in checks:
564         report_obsolete_source(suite_name, session)
565
566     if "nbs" in checks:
567         reportAllNBS(suite_name, suite_id, session, rdeps)
568
569     if "outdated non-free" in checks:
570         report_outdated_nonfree(suite_name, session, rdeps)
571
572     bin_not_built = {}
573
574     if "bnb" in checks:
575         bins_in_suite = get_suite_binaries(suite, session)
576
577     # Checks based on the Sources files
578     components = get_component_names(session)
579     for component in components:
580         filename = "%s/dists/%s/%s/source/Sources.gz" % (suite.archive.path, suite_name, component)
581         # apt_pkg.TagFile needs a real file handle and can't handle a GzipFile instance...
582         (fd, temp_filename) = utils.temp_filename()
583         (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
584         if (result != 0):
585             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
586             sys.exit(result)
587         sources = utils.open_file(temp_filename)
588         Sources = apt_pkg.TagFile(sources)
589         while Sources.step():
590             source = Sources.section.find('Package')
591             source_version = Sources.section.find('Version')
592             architecture = Sources.section.find('Architecture')
593             binaries = Sources.section.find('Binary')
594             binaries_list = [ i.strip() for i in  binaries.split(',') ]
595
596             if "bnb" in checks:
597                 # Check for binaries not built on any architecture.
598                 for binary in binaries_list:
599                     if not bins_in_suite.has_key(binary):
600                         bin_not_built.setdefault(source, {})
601                         bin_not_built[source][binary] = ""
602
603             if "anais" in checks:
604                 anais_output += do_anais(architecture, binaries_list, source, session)
605
606             # build indices for checking "no source" later
607             source_index = component + '/' + source
608             src_pkgs[source] = source_index
609             for binary in binaries_list:
610                 bin_pkgs[binary] = source
611             source_binaries[source] = binaries
612             source_versions[source] = source_version
613
614         sources.close()
615         os.unlink(temp_filename)
616
617     # Checks based on the Packages files
618     check_components = components[:]
619     if suite_name != "experimental":
620         check_components.append('main/debian-installer');
621
622     for component in check_components:
623         architectures = [ a.arch_string for a in get_suite_architectures(suite_name,
624                                                                          skipsrc=True, skipall=True,
625                                                                          session=session) ]
626         for architecture in architectures:
627             if component == 'main/debian-installer' and re.match("kfreebsd", architecture):
628                 continue
629             filename = "%s/dists/%s/%s/binary-%s/Packages.gz" % (suite.archive.path, suite_name, component, architecture)
630             # apt_pkg.TagFile needs a real file handle
631             (fd, temp_filename) = utils.temp_filename()
632             (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
633             if (result != 0):
634                 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
635                 sys.exit(result)
636
637             if "nfu" in checks:
638                 nfu_packages.setdefault(architecture,[])
639                 nfu_entries = parse_nfu(architecture)
640
641             packages = utils.open_file(temp_filename)
642             Packages = apt_pkg.TagFile(packages)
643             while Packages.step():
644                 package = Packages.section.find('Package')
645                 source = Packages.section.find('Source', "")
646                 version = Packages.section.find('Version')
647                 if source == "":
648                     source = package
649                 if bin2source.has_key(package) and \
650                        apt_pkg.version_compare(version, bin2source[package]["version"]) > 0:
651                     bin2source[package]["version"] = version
652                     bin2source[package]["source"] = source
653                 else:
654                     bin2source[package] = {}
655                     bin2source[package]["version"] = version
656                     bin2source[package]["source"] = source
657                 if source.find("(") != -1:
658                     m = re_extract_src_version.match(source)
659                     source = m.group(1)
660                     version = m.group(2)
661                 if not bin_pkgs.has_key(package):
662                     nbs.setdefault(source,{})
663                     nbs[source].setdefault(package, {})
664                     nbs[source][package][version] = ""
665                 else:
666                     if "nfu" in checks:
667                         if package in nfu_entries and \
668                                version != source_versions[source]: # only suggest to remove out-of-date packages
669                             nfu_packages[architecture].append((package,version,source_versions[source]))
670                     
671             packages.close()
672             os.unlink(temp_filename)
673
674     # Distinguish dubious (version numbers match) and 'real' NBS (they don't)
675     dubious_nbs = {}
676     for source in nbs.keys():
677         for package in nbs[source].keys():
678             versions = nbs[source][package].keys()
679             versions.sort(apt_pkg.version_compare)
680             latest_version = versions.pop()
681             source_version = source_versions.get(source,"0")
682             if apt_pkg.version_compare(latest_version, source_version) == 0:
683                 add_nbs(dubious_nbs, source, latest_version, package, suite_id, session)
684
685     if "nviu" in checks:
686         do_newer_version('unstable', 'experimental', 'NVIU', session)
687
688     if "nvit" in checks:
689         do_newer_version('testing', 'testing-proposed-updates', 'NVIT', session)
690
691     ###
692
693     if Options["Mode"] == "full":
694         print "="*75
695         print
696
697     if "nfu" in checks:
698         do_nfu(nfu_packages)
699
700     if "bnb" in checks:
701         print "Unbuilt binary packages"
702         print "-----------------------"
703         print
704         keys = bin_not_built.keys()
705         keys.sort()
706         for source in keys:
707             binaries = bin_not_built[source].keys()
708             binaries.sort()
709             print " o %s: %s" % (source, ", ".join(binaries))
710         print
711
712     if "bms" in checks:
713         report_multiple_source(suite)
714
715     if "anais" in checks:
716         print "Architecture Not Allowed In Source"
717         print "----------------------------------"
718         print anais_output
719         print
720
721     if "dubious nbs" in checks:
722         do_dubious_nbs(dubious_nbs)
723
724
725 ################################################################################
726
727 if __name__ == '__main__':
728     main()