3 # Check for obsolete binary packages
4 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: rene,v 1.15 2002-10-16 02:47:32 troup Exp $
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ################################################################################
23 # ``If you're claiming that's a "problem" that needs to be "fixed",
24 # you might as well write some letters to God about how unfair entropy
25 # is while you're at it.'' -- 20020802143104.GA5628@azure.humbug.org.au
27 ################################################################################
29 import commands, pg, os, sys, tempfile;
30 import utils, db_access;
33 ################################################################################
38 ################################################################################
43 Cnf = utils.get_conf()
45 apt_pkg.ParseCommandLine(Cnf,[],sys.argv);
46 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
47 db_access.init(Cnf, projectB);
55 suite_id = db_access.get_suite_id(suite);
57 components = Cnf.ValueList("Suite::%s::Components" % (suite));
58 for component in components:
59 filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::Root"], suite, component);
60 # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
61 temp_filename = tempfile.mktemp();
62 fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
64 (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
66 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
68 sources = utils.open_file(temp_filename);
69 Sources = apt_pkg.ParseTagFile(sources);
71 source = Sources.Section.Find('Package');
72 architecture = Sources.Section.Find('Architecture');
73 binaries = Sources.Section.Find('Binary');
75 # Check for packages built on architectures they shouldn't be.
76 if architecture != "any" and architecture != "all":
78 for arch in architecture.split():
79 architectures[arch.strip()] = "";
80 for binary in binaries.split(','):
81 binary = binary.strip();
82 q = projectB.query("SELECT a.arch_string, b.version FROM binaries b, bin_associations ba, architecture a WHERE ba.suite = %s AND ba.bin = b.id AND b.architecture = a.id AND b.package = '%s'" % (suite_id, binary));
85 utils.warn("%s lists %s as a binary, but it doesn't seem to exist in %s?" % (source, binary, suite));
86 # Loop around twice; first to get the latest 'valid' version
88 for i in q.getresult():
91 if architectures.has_key(arch):
92 versions.append(version);
93 versions.sort(apt_pkg.VersionCompare);
95 latest_version = versions.pop()
97 latest_version = None;
98 # ... then to check for 'invalid' architectures
99 for i in q.getresult():
102 if not architectures.has_key(arch):
103 print "[%s]: %s appears for %s (vs. '%s')" % (source, binary, arch, architecture),
104 if not latest_version:
105 print "** mwaap, mwapp! Ignore me **";
107 if apt_pkg.VersionCompare(latest_version, version) != -1:
108 print "- out of date.",
111 print "[%s vs %s (%s)]" % (latest_version, version, arch);
113 # Check for duplicated packages and build indices for checking "no source" later
114 source_index = component + '/' + source;
115 if src_pkgs.has_key(source):
116 print " %s is a duplicated source package (%s and %s)" % (source, source_index, src_pkgs[source]);
117 src_pkgs[source] = source_index;
118 for binary in binaries.split(','):
119 binary = binary.strip();
120 if bin_pkgs.has_key(binary):
121 print " binary %s is duplicated in source packages %s and %s" % (binary, source, bin_pkgs[binary]);
122 bin_pkgs[binary] = source;
123 source_binaries[source] = binaries;
126 os.unlink(temp_filename);
128 for component in components:
129 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
130 for architecture in architectures:
131 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
132 packages = utils.open_file(filename);
133 Packages = apt_pkg.ParseTagFile(packages);
134 while Packages.Step():
135 package = Packages.Section.Find('Package');
136 source = Packages.Section.Find('Source', "");
139 if source.find("(") != -1:
140 m = utils.re_extract_src_version.match(source)
142 if not bin_pkgs.has_key(package) and not miss_src.has_key(package):
143 miss_src[package] = 1;
144 print " %s has no source [%s: %s]" % (package, source, source_binaries.get(source, "(source does not exist)"));
147 # Check for packages in experimental obsoleted by versions in unstable
149 # [If melanie was callable from python, we could auto-remove these
152 suite_id = db_access.get_suite_id("unstable");
153 q = projectB.query("""
154 SELECT s.source, s.version AS experimental, s2.version AS unstable
155 FROM src_associations sa, source s, source s2, src_associations sa2
156 WHERE sa.suite = 1 AND sa2.suite = %d AND sa.source = s.id
157 AND sa2.source = s2.id AND s.source = s2.source
158 AND versioncmp(s.version, s2.version) < 0""" % (suite_id));
164 ####################################################################################################
166 if __name__ == '__main__':