]> git.decadent.org.uk Git - dak.git/blob - dak/cruft_report.py
7dedceed886c1c9f4c11c0e3fab4db0389147764
[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 http://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 def queryWithoutSource(suite_id, session):
213     """searches for arch: all packages from suite that do no longer
214     reference a source package in the same suite
215
216     subquery unique_binaries: selects all packages with only 1 version
217     in suite since 'dak rm' does not allow to specify version numbers"""
218
219     query = """
220     with unique_binaries as
221         (select package, max(version) as version, max(source) as source
222             from bin_associations_binaries
223             where architecture = 2 and suite = :suite_id
224             group by package having count(*) = 1)
225     select ub.package, ub.version
226         from unique_binaries ub
227         left join src_associations_src sas
228             on ub.source = sas.src and sas.suite = :suite_id
229         where sas.id is null
230         order by ub.package"""
231     return session.execute(query, { 'suite_id': suite_id })
232
233 def reportWithoutSource(suite_name, suite_id, session, rdeps=False):
234     rows = queryWithoutSource(suite_id, session)
235     title = 'packages without source in suite %s' % suite_name
236     if rows.rowcount > 0:
237         print '%s\n%s\n' % (title, '-' * len(title))
238     message = '"[auto-cruft] no longer built from source"'
239     for row in rows:
240         (package, version) = row
241         print "* package %s in version %s is no longer built from source" % \
242             (package, version)
243         print "  - suggested command:"
244         print "    dak rm -m %s -s %s -a all -p -R -b %s" % \
245             (message, suite_name, package)
246         if rdeps:
247             if utils.check_reverse_depends([package], suite_name, [], session, True):
248                 print
249             else:
250                 print "  - No dependency problem found\n"
251         else:
252             print
253
254 def queryNewerAll(suite_name, session):
255     """searches for arch != all packages that have an arch == all
256     package with a higher version in the same suite"""
257
258     query = """
259 select bab1.package, bab1.version as oldver,
260     array_to_string(array_agg(a.arch_string), ',') as oldarch,
261     bab2.version as newver
262     from bin_associations_binaries bab1
263     join bin_associations_binaries bab2
264         on bab1.package = bab2.package and bab1.version < bab2.version and
265         bab1.suite = bab2.suite and bab1.architecture > 2 and
266         bab2.architecture = 2
267     join architecture a on bab1.architecture = a.id
268     join suite s on bab1.suite = s.id
269     where s.suite_name = :suite_name
270     group by bab1.package, oldver, bab1.suite, newver"""
271     return session.execute(query, { 'suite_name': suite_name })
272
273 def reportNewerAll(suite_name, session):
274     rows = queryNewerAll(suite_name, session)
275     title = 'obsolete arch any packages in suite %s' % suite_name
276     if rows.rowcount > 0:
277         print '%s\n%s\n' % (title, '-' * len(title))
278     message = '"[auto-cruft] obsolete arch any package"'
279     for row in rows:
280         (package, oldver, oldarch, newver) = row
281         print "* package %s is arch any in version %s but arch all in version %s" % \
282             (package, oldver, newver)
283         print "  - suggested command:"
284         print "    dak rm -m %s -s %s -a %s -p -b %s\n" % \
285             (message, suite_name, oldarch, package)
286
287 def queryNBS(suite_id, session):
288     """This one is really complex. It searches arch != all packages that
289     are no longer built from current source packages in suite.
290
291     temp table unique_binaries: will be populated with packages that
292     have only one version in suite because 'dak rm' does not allow
293     specifying version numbers
294
295     temp table newest_binaries: will be populated with packages that are
296     built from current sources
297
298     subquery uptodate_arch: returns all architectures built from current
299     sources
300
301     subquery unique_binaries_uptodate_arch: returns all packages in
302     architectures from uptodate_arch
303
304     subquery unique_binaries_uptodate_arch_agg: same as
305     unique_binaries_uptodate_arch but with column architecture
306     aggregated to array
307
308     subquery uptodate_packages: similar to uptodate_arch but returns all
309     packages built from current sources
310
311     subquery outdated_packages: returns all packages with architectures
312     no longer built from current source
313     """
314
315     query = """
316 create temp table unique_binaries (
317     package text not null,
318     architecture integer not null,
319     source integer not null);
320
321 insert into unique_binaries
322     select bab.package, bab.architecture, max(bab.source)
323         from bin_associations_binaries bab
324         where bab.suite = :suite_id and bab.architecture > 2
325         group by package, architecture having count(*) = 1;
326
327 create temp table newest_binaries (
328     package text not null,
329     architecture integer not null,
330     source text not null,
331     version debversion not null);
332
333 insert into newest_binaries
334     select ub.package, ub.architecture, nsa.source, nsa.version
335         from unique_binaries ub
336         join newest_src_association nsa
337             on ub.source = nsa.src and nsa.suite = :suite_id;
338
339 with uptodate_arch as
340     (select architecture, source, version
341         from newest_binaries
342         group by architecture, source, version),
343     unique_binaries_uptodate_arch as
344     (select ub.package, ub.architecture, ua.source, ua.version
345         from unique_binaries ub
346         join source s
347             on ub.source = s.id
348         join uptodate_arch ua
349             on ub.architecture = ua.architecture and s.source = ua.source),
350     unique_binaries_uptodate_arch_agg as
351     (select ubua.package,
352         array(select unnest(array_agg(a.arch_string)) order by 1) as arch_list,
353         ubua.source, ubua.version
354         from unique_binaries_uptodate_arch ubua
355         join architecture a
356             on ubua.architecture = a.id
357         group by ubua.source, ubua.version, ubua.package),
358     uptodate_packages as
359     (select package, source, version
360         from newest_binaries
361         group by package, source, version),
362     outdated_packages as
363     (select array(select unnest(array_agg(package)) order by 1) as pkg_list,
364         arch_list, source, version
365         from unique_binaries_uptodate_arch_agg
366         where package not in
367             (select package from uptodate_packages)
368         group by arch_list, source, version)
369     select * from outdated_packages order by source"""
370     return session.execute(query, { 'suite_id': suite_id })
371
372 def reportNBS(suite_name, suite_id, rdeps=False):
373     session = DBConn().session()
374     nbsRows = queryNBS(suite_id, session)
375     title = 'NBS packages in suite %s' % suite_name
376     if nbsRows.rowcount > 0:
377         print '%s\n%s\n' % (title, '-' * len(title))
378     for row in nbsRows:
379         (pkg_list, arch_list, source, version) = row
380         pkg_string = ' '.join(pkg_list)
381         arch_string = ','.join(arch_list)
382         print "* source package %s version %s no longer builds" % \
383             (source, version)
384         print "  binary package(s): %s" % pkg_string
385         print "  on %s" % arch_string
386         print "  - suggested command:"
387         message = '"[auto-cruft] NBS (no longer built by %s)"' % source
388         print "    dak rm -m %s -s %s -a %s -p -R -b %s" % \
389             (message, suite_name, arch_string, pkg_string)
390         if rdeps:
391             if utils.check_reverse_depends(pkg_list, suite_name, arch_list, session, True):
392                 print
393             else:
394                 print "  - No dependency problem found\n"
395         else:
396             print
397     session.close()
398
399 def reportAllNBS(suite_name, suite_id, session, rdeps=False):
400     reportWithoutSource(suite_name, suite_id, session, rdeps)
401     reportNewerAll(suite_name, session)
402     reportNBS(suite_name, suite_id, rdeps)
403
404 ################################################################################
405
406 def do_dubious_nbs(dubious_nbs):
407     print "Dubious NBS"
408     print "-----------"
409     print
410
411     dubious_nbs_keys = dubious_nbs.keys()
412     dubious_nbs_keys.sort()
413     for source in dubious_nbs_keys:
414         print " * %s_%s builds: %s" % (source,
415                                        source_versions.get(source, "??"),
416                                        source_binaries.get(source, "(source does not exist)"))
417         print "      won't admit to building:"
418         versions = dubious_nbs[source].keys()
419         versions.sort(apt_pkg.version_compare)
420         for version in versions:
421             packages = dubious_nbs[source][version].keys()
422             packages.sort()
423             print "        o %s: %s" % (version, ", ".join(packages))
424
425         print
426
427 ################################################################################
428
429 def obsolete_source(suite_name, session):
430     """returns obsolete source packages for suite_name without binaries
431     in the same suite sorted by install_date; install_date should help
432     detecting source only (or binary throw away) uploads; duplicates in
433     the suite are skipped
434
435     subquery 'source_suite_unique' returns source package names from
436     suite without duplicates; the rationale behind is that neither
437     cruft-report nor rm cannot handle duplicates (yet)"""
438
439     query = """
440 WITH source_suite_unique AS
441     (SELECT source, suite
442         FROM source_suite GROUP BY source, suite HAVING count(*) = 1)
443 SELECT ss.src, ss.source, ss.version,
444     to_char(ss.install_date, 'YYYY-MM-DD') AS install_date
445     FROM source_suite ss
446     JOIN source_suite_unique ssu
447         ON ss.source = ssu.source AND ss.suite = ssu.suite
448     JOIN suite s ON s.id = ss.suite
449     LEFT JOIN bin_associations_binaries bab
450         ON ss.src = bab.source AND ss.suite = bab.suite
451     WHERE s.suite_name = :suite_name AND bab.id IS NULL
452     ORDER BY install_date"""
453     args = { 'suite_name': suite_name }
454     return session.execute(query, args)
455
456 def source_bin(source, session):
457     """returns binaries built by source for all or no suite grouped and
458     ordered by package name"""
459
460     query = """
461 SELECT b.package
462     FROM binaries b
463     JOIN src_associations_src sas ON b.source = sas.src
464     WHERE sas.source = :source
465     GROUP BY b.package
466     ORDER BY b.package"""
467     args = { 'source': source }
468     return session.execute(query, args)
469
470 def newest_source_bab(suite_name, package, session):
471     """returns newest source that builds binary package in suite grouped
472     and sorted by source and package name"""
473
474     query = """
475 SELECT sas.source, MAX(sas.version) AS srcver
476     FROM src_associations_src sas
477     JOIN bin_associations_binaries bab ON sas.src = bab.source
478     JOIN suite s on s.id = bab.suite
479     WHERE s.suite_name = :suite_name AND bab.package = :package
480         GROUP BY sas.source, bab.package
481         ORDER BY sas.source, bab.package"""
482     args = { 'suite_name': suite_name, 'package': package }
483     return session.execute(query, args)
484
485 def report_obsolete_source(suite_name, session):
486     rows = obsolete_source(suite_name, session)
487     if rows.rowcount == 0:
488         return
489     print \
490 """Obsolete source packages in suite %s
491 ----------------------------------%s\n""" % \
492         (suite_name, '-' * len(suite_name))
493     for os_row in rows.fetchall():
494         (src, old_source, version, install_date) = os_row
495         print " * obsolete source %s version %s installed at %s" % \
496             (old_source, version, install_date)
497         for sb_row in source_bin(old_source, session):
498             (package, ) = sb_row
499             print "   - has built binary %s" % package
500             for nsb_row in newest_source_bab(suite_name, package, session):
501                 (new_source, srcver) = nsb_row
502                 print "     currently built by source %s version %s" % \
503                     (new_source, srcver)
504         print "   - suggested command:"
505         rm_opts = "-S -p -m \"[auto-cruft] obsolete source package\""
506         print "     dak rm -s %s %s %s\n" % (suite_name, rm_opts, old_source)
507
508 def get_suite_binaries(suite, session):
509     # Initalize a large hash table of all binary packages
510     binaries = {}
511
512     print "Getting a list of binary packages in %s..." % suite.suite_name
513     q = session.execute("""SELECT distinct b.package
514                              FROM binaries b, bin_associations ba
515                             WHERE ba.suite = :suiteid AND ba.bin = b.id""",
516                            {'suiteid': suite.suite_id})
517     for i in q.fetchall():
518         binaries[i[0]] = ""
519
520     return binaries
521
522 ################################################################################
523
524 def report_outdated_nonfree(suite, session, rdeps=False):
525
526     packages = {}
527     query = """WITH outdated_sources AS (
528                  SELECT s.source, s.version, s.id
529                  FROM source s
530                  JOIN src_associations sa ON sa.source = s.id
531                  WHERE sa.suite IN (
532                    SELECT id
533                    FROM suite
534                    WHERE suite_name = :suite )
535                  AND sa.created < (now() - interval :delay)
536                  EXCEPT SELECT s.source, max(s.version) AS version, max(s.id)
537                  FROM source s
538                  JOIN src_associations sa ON sa.source = s.id
539                  WHERE sa.suite IN (
540                    SELECT id
541                    FROM suite
542                    WHERE suite_name = :suite )
543                  AND sa.created < (now() - interval :delay)
544                  GROUP BY s.source ),
545                binaries AS (
546                  SELECT b.package, s.source, (
547                    SELECT a.arch_string
548                    FROM architecture a
549                    WHERE a.id = b.architecture ) AS arch
550                  FROM binaries b
551                  JOIN outdated_sources s ON s.id = b.source
552                  JOIN bin_associations ba ON ba.bin = b.id
553                  JOIN override o ON o.package = b.package AND o.suite = ba.suite
554                  WHERE ba.suite IN (
555                    SELECT id
556                    FROM suite
557                    WHERE suite_name = :suite )
558                  AND o.component IN (
559                    SELECT id
560                    FROM component
561                    WHERE name = 'non-free' ) )
562                SELECT DISTINCT package, source, arch
563                FROM binaries
564                ORDER BY source, package, arch"""
565
566     res = session.execute(query, {'suite': suite, 'delay': "'15 days'"})
567     for package in res:
568         binary = package[0]
569         source = package[1]
570         arch = package[2]
571         if arch == 'all':
572             continue
573         if not source in packages:
574             packages[source] = {}
575         if not binary in packages[source]:
576             packages[source][binary] = set()
577         packages[source][binary].add(arch)
578     if packages:
579         title = 'Outdated non-free binaries in suite %s' % suite
580         message = '"[auto-cruft] outdated non-free binaries"'
581         print '%s\n%s\n' % (title, '-' * len(title))
582         for source in sorted(packages):
583             archs = set()
584             binaries = set()
585             print '* package %s has outdated non-free binaries' % source
586             print '  - suggested command:'
587             for binary in sorted(packages[source]):
588                 binaries.add(binary)
589                 archs = archs.union(packages[source][binary])
590             print '    dak rm -m %s -s %s -a %s -p -R -b %s' % \
591                    (message, suite, ','.join(archs), ' '.join(binaries))
592             if rdeps:
593                 if utils.check_reverse_depends(list(binaries), suite, archs, session, True):
594                     print
595                 else:
596                     print "  - No dependency problem found\n"
597             else:
598                 print
599
600 ################################################################################
601
602 def main ():
603     global suite, suite_id, source_binaries, source_versions
604
605     cnf = Config()
606
607     Arguments = [('h',"help","Cruft-Report::Options::Help"),
608                  ('m',"mode","Cruft-Report::Options::Mode", "HasArg"),
609                  ('R',"rdep-check", "Cruft-Report::Options::Rdep-Check"),
610                  ('s',"suite","Cruft-Report::Options::Suite","HasArg"),
611                  ('w',"wanna-build-dump","Cruft-Report::Options::Wanna-Build-Dump","HasArg")]
612     for i in [ "help", "Rdep-Check" ]:
613         if not cnf.has_key("Cruft-Report::Options::%s" % (i)):
614             cnf["Cruft-Report::Options::%s" % (i)] = ""
615
616     cnf["Cruft-Report::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable")
617
618     if not cnf.has_key("Cruft-Report::Options::Mode"):
619         cnf["Cruft-Report::Options::Mode"] = "daily"
620
621     if not cnf.has_key("Cruft-Report::Options::Wanna-Build-Dump"):
622         cnf["Cruft-Report::Options::Wanna-Build-Dump"] = "/srv/ftp-master.debian.org/scripts/nfu"
623
624     apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
625
626     Options = cnf.subtree("Cruft-Report::Options")
627     if Options["Help"]:
628         usage()
629
630     if Options["Rdep-Check"]:
631         rdeps = True
632     else:
633         rdeps = False
634
635     # Set up checks based on mode
636     if Options["Mode"] == "daily":
637         checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu" ]
638     elif Options["Mode"] == "full":
639         checks = [ "nbs", "nviu", "nvit", "obsolete source", "outdated non-free", "nfu", "dubious nbs", "bnb", "bms", "anais" ]
640     elif Options["Mode"] == "bdo":
641         checks = [ "nbs",  "obsolete source" ]
642     else:
643         utils.warn("%s is not a recognised mode - only 'full', 'daily' or 'bdo' are understood." % (Options["Mode"]))
644         usage(1)
645
646     session = DBConn().session()
647
648     bin_pkgs = {}
649     src_pkgs = {}
650     bin2source = {}
651     bins_in_suite = {}
652     nbs = {}
653     source_versions = {}
654
655     anais_output = ""
656
657     nfu_packages = {}
658
659     suite = get_suite(Options["Suite"].lower(), session)
660     if not suite:
661         utils.fubar("Cannot find suite %s" % Options["Suite"].lower())
662
663     suite_id = suite.suite_id
664     suite_name = suite.suite_name.lower()
665
666     if "obsolete source" in checks:
667         report_obsolete_source(suite_name, session)
668
669     if "nbs" in checks:
670         reportAllNBS(suite_name, suite_id, session, rdeps)
671
672     if "outdated non-free" in checks:
673         report_outdated_nonfree(suite_name, session, rdeps)
674
675     bin_not_built = {}
676
677     if "bnb" in checks:
678         bins_in_suite = get_suite_binaries(suite, session)
679
680     # Checks based on the Sources files
681     components = get_component_names(session)
682     for component in components:
683         filename = "%s/dists/%s/%s/source/Sources.gz" % (suite.archive.path, suite_name, component)
684         # apt_pkg.TagFile needs a real file handle and can't handle a GzipFile instance...
685         (fd, temp_filename) = utils.temp_filename()
686         (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
687         if (result != 0):
688             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
689             sys.exit(result)
690         sources = utils.open_file(temp_filename)
691         Sources = apt_pkg.TagFile(sources)
692         while Sources.step():
693             source = Sources.section.find('Package')
694             source_version = Sources.section.find('Version')
695             architecture = Sources.section.find('Architecture')
696             binaries = Sources.section.find('Binary')
697             binaries_list = [ i.strip() for i in  binaries.split(',') ]
698
699             if "bnb" in checks:
700                 # Check for binaries not built on any architecture.
701                 for binary in binaries_list:
702                     if not bins_in_suite.has_key(binary):
703                         bin_not_built.setdefault(source, {})
704                         bin_not_built[source][binary] = ""
705
706             if "anais" in checks:
707                 anais_output += do_anais(architecture, binaries_list, source, session)
708
709             # build indices for checking "no source" later
710             source_index = component + '/' + source
711             src_pkgs[source] = source_index
712             for binary in binaries_list:
713                 bin_pkgs[binary] = source
714             source_binaries[source] = binaries
715             source_versions[source] = source_version
716
717         sources.close()
718         os.unlink(temp_filename)
719
720     # Checks based on the Packages files
721     check_components = components[:]
722     if suite_name != "experimental":
723         check_components.append('main/debian-installer');
724
725     for component in check_components:
726         architectures = [ a.arch_string for a in get_suite_architectures(suite_name,
727                                                                          skipsrc=True, skipall=True,
728                                                                          session=session) ]
729         for architecture in architectures:
730             if component == 'main/debian-installer' and re.match("kfreebsd", architecture):
731                 continue
732             filename = "%s/dists/%s/%s/binary-%s/Packages.gz" % (suite.archive.path, suite_name, component, architecture)
733             # apt_pkg.TagFile needs a real file handle
734             (fd, temp_filename) = utils.temp_filename()
735             (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename))
736             if (result != 0):
737                 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output))
738                 sys.exit(result)
739
740             if "nfu" in checks:
741                 nfu_packages.setdefault(architecture,[])
742                 nfu_entries = parse_nfu(architecture)
743
744             packages = utils.open_file(temp_filename)
745             Packages = apt_pkg.TagFile(packages)
746             while Packages.step():
747                 package = Packages.section.find('Package')
748                 source = Packages.section.find('Source', "")
749                 version = Packages.section.find('Version')
750                 if source == "":
751                     source = package
752                 if bin2source.has_key(package) and \
753                        apt_pkg.version_compare(version, bin2source[package]["version"]) > 0:
754                     bin2source[package]["version"] = version
755                     bin2source[package]["source"] = source
756                 else:
757                     bin2source[package] = {}
758                     bin2source[package]["version"] = version
759                     bin2source[package]["source"] = source
760                 if source.find("(") != -1:
761                     m = re_extract_src_version.match(source)
762                     source = m.group(1)
763                     version = m.group(2)
764                 if not bin_pkgs.has_key(package):
765                     nbs.setdefault(source,{})
766                     nbs[source].setdefault(package, {})
767                     nbs[source][package][version] = ""
768                 else:
769                     if "nfu" in checks:
770                         if package in nfu_entries and \
771                                version != source_versions[source]: # only suggest to remove out-of-date packages
772                             nfu_packages[architecture].append((package,version,source_versions[source]))
773                     
774             packages.close()
775             os.unlink(temp_filename)
776
777     # Distinguish dubious (version numbers match) and 'real' NBS (they don't)
778     dubious_nbs = {}
779     for source in nbs.keys():
780         for package in nbs[source].keys():
781             versions = nbs[source][package].keys()
782             versions.sort(apt_pkg.version_compare)
783             latest_version = versions.pop()
784             source_version = source_versions.get(source,"0")
785             if apt_pkg.version_compare(latest_version, source_version) == 0:
786                 add_nbs(dubious_nbs, source, latest_version, package, suite_id, session)
787
788     if "nviu" in checks:
789         do_newer_version('unstable', 'experimental', 'NVIU', session)
790
791     if "nvit" in checks:
792         do_newer_version('testing', 'testing-proposed-updates', 'NVIT', session)
793
794     ###
795
796     if Options["Mode"] == "full":
797         print "="*75
798         print
799
800     if "nfu" in checks:
801         do_nfu(nfu_packages)
802
803     if "bnb" in checks:
804         print "Unbuilt binary packages"
805         print "-----------------------"
806         print
807         keys = bin_not_built.keys()
808         keys.sort()
809         for source in keys:
810             binaries = bin_not_built[source].keys()
811             binaries.sort()
812             print " o %s: %s" % (source, ", ".join(binaries))
813         print
814
815     if "bms" in checks:
816         report_multiple_source(suite)
817
818     if "anais" in checks:
819         print "Architecture Not Allowed In Source"
820         print "----------------------------------"
821         print anais_output
822         print
823
824     if "dubious nbs" in checks:
825         do_dubious_nbs(dubious_nbs)
826
827
828 ################################################################################
829
830 if __name__ == '__main__':
831     main()