3 # Check for obsolete binary packages
4 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: rene,v 1.16 2003-01-02 18:10:02 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 ################################################################################
40 def usage(exit_code=0):
42 Check for obsolete or duplicated packages.
44 -h, --help show this help and exit."""
47 ################################################################################
52 Cnf = utils.get_conf();
54 Arguments = [('h',"help","Rene::Options::Help")];
56 if not Cnf.has_key("Rene::Options::%s" % (i)):
57 Cnf["Rene::Options::%s" % (i)] = "";
59 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
61 Options = Cnf.SubTree("Rene::Options")
65 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
66 db_access.init(Cnf, projectB);
74 suite_id = db_access.get_suite_id(suite);
76 components = Cnf.ValueList("Suite::%s::Components" % (suite));
77 for component in components:
78 filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::Root"], suite, component);
79 # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
80 temp_filename = tempfile.mktemp();
81 fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
83 (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
85 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
87 sources = utils.open_file(temp_filename);
88 Sources = apt_pkg.ParseTagFile(sources);
90 source = Sources.Section.Find('Package');
91 architecture = Sources.Section.Find('Architecture');
92 binaries = Sources.Section.Find('Binary');
94 # Check for packages built on architectures they shouldn't be.
95 if architecture != "any" and architecture != "all":
97 for arch in architecture.split():
98 architectures[arch.strip()] = "";
99 for binary in binaries.split(','):
100 binary = binary.strip();
101 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));
104 utils.warn("%s lists %s as a binary, but it doesn't seem to exist in %s?" % (source, binary, suite));
105 # Loop around twice; first to get the latest 'valid' version
107 for i in q.getresult():
110 if architectures.has_key(arch):
111 versions.append(version);
112 versions.sort(apt_pkg.VersionCompare);
114 latest_version = versions.pop()
116 latest_version = None;
117 # ... then to check for 'invalid' architectures
118 for i in q.getresult():
121 if not architectures.has_key(arch):
122 print "[%s]: %s appears for %s (vs. '%s')" % (source, binary, arch, architecture),
123 if not latest_version:
124 print "** mwaap, mwapp! Ignore me **";
126 if apt_pkg.VersionCompare(latest_version, version) != -1:
127 print "- out of date.",
130 print "[%s vs %s (%s)]" % (latest_version, version, arch);
132 # Check for duplicated packages and build indices for checking "no source" later
133 source_index = component + '/' + source;
134 if src_pkgs.has_key(source):
135 print " %s is a duplicated source package (%s and %s)" % (source, source_index, src_pkgs[source]);
136 src_pkgs[source] = source_index;
137 for binary in binaries.split(','):
138 binary = binary.strip();
139 if bin_pkgs.has_key(binary):
140 print " binary %s is duplicated in source packages %s and %s" % (binary, source, bin_pkgs[binary]);
141 bin_pkgs[binary] = source;
142 source_binaries[source] = binaries;
145 os.unlink(temp_filename);
147 for component in components:
148 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
149 for architecture in architectures:
150 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
151 packages = utils.open_file(filename);
152 Packages = apt_pkg.ParseTagFile(packages);
153 while Packages.Step():
154 package = Packages.Section.Find('Package');
155 source = Packages.Section.Find('Source', "");
158 if source.find("(") != -1:
159 m = utils.re_extract_src_version.match(source)
161 if not bin_pkgs.has_key(package) and not miss_src.has_key(package):
162 miss_src[package] = 1;
163 print " %s has no source [%s: %s]" % (package, source, source_binaries.get(source, "(source does not exist)"));
166 # Check for packages in experimental obsoleted by versions in unstable
168 # [If melanie was callable from python, we could auto-remove these
171 suite_id = db_access.get_suite_id("unstable");
172 q = projectB.query("""
173 SELECT s.source, s.version AS experimental, s2.version AS unstable
174 FROM src_associations sa, source s, source s2, src_associations sa2
175 WHERE sa.suite = 1 AND sa2.suite = %d AND sa.source = s.id
176 AND sa2.source = s2.id AND s.source = s2.source
177 AND versioncmp(s.version, s2.version) < 0""" % (suite_id));
183 ################################################################################
185 if __name__ == '__main__':