3 # Check for obsolete binary packages
4 # Copyright (C) 2000, 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: rene,v 1.17 2003-01-20 19:13:21 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 ## TODO: fix NBS looping for version, implement Dubious NBS, fix up output of duplicate source package stuff, improve experimental ?, add support for non-US ?, add overrides, avoid ANAIS for duplicated packages
29 ################################################################################
31 import commands, pg, os, string, sys, tempfile, time;
32 import utils, db_access;
35 ################################################################################
41 ################################################################################
43 def usage(exit_code=0):
45 Check for obsolete or duplicated packages.
47 -h, --help show this help and exit."""
50 ################################################################################
52 def add_nbs(nbs_d, source, version, package):
53 if not nbs_d.has_key(source):
55 if not nbs_d[source].has_key(version):
56 nbs_d[source][version] = {};
57 nbs_d[source][version][package] = "";
59 ################################################################################
62 global Cnf, projectB, suite_id;
64 Cnf = utils.get_conf();
66 Arguments = [('h',"help","Rene::Options::Help")];
68 if not Cnf.has_key("Rene::Options::%s" % (i)):
69 Cnf["Rene::Options::%s" % (i)] = "";
71 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv);
73 Options = Cnf.SubTree("Rene::Options")
77 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
78 db_access.init(Cnf, projectB);
91 suite_id = db_access.get_suite_id(suite);
95 # Initalize a large hash table of all binary packages
97 sys.stderr.write("[Getting a list of binary packages in %s..." % (suite));
98 q = projectB.query("SELECT distinct b.package FROM binaries b, bin_associations ba WHERE ba.suite = 5 AND ba.bin = b.id");
100 sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before)));
102 bins_in_suite[i[0]] = "";
104 components = Cnf.ValueList("Suite::%s::Components" % (suite));
105 for component in components:
106 filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::Root"], suite, component);
107 # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
108 temp_filename = tempfile.mktemp();
109 fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
111 (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
113 sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
115 sources = utils.open_file(temp_filename);
116 Sources = apt_pkg.ParseTagFile(sources);
117 while Sources.Step():
118 source = Sources.Section.Find('Package');
119 source_version = Sources.Section.Find('Version');
120 architecture = Sources.Section.Find('Architecture');
121 binaries = Sources.Section.Find('Binary');
122 binaries_list = map(string.strip, binaries.split(','));
124 # Check for binaries not built on any architecture.
125 for binary in binaries_list:
126 if not bins_in_suite.has_key(binary):
127 if not bin_not_built.has_key(source):
128 bin_not_built[source] = {};
129 bin_not_built[source][binary] = "";
131 # Check for packages built on architectures they shouldn't be.
132 if architecture != "any" and architecture != "all":
134 for arch in architecture.split():
135 architectures[arch.strip()] = "";
136 for binary in binaries_list:
137 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));
143 if architectures.has_key(arch):
144 versions.append(version);
145 versions.sort(apt_pkg.VersionCompare);
147 latest_version = versions.pop()
149 latest_version = None;
150 # Check for 'invalid' architectures
155 if not architectures.has_key(arch):
156 if not versions_d.has_key(version):
157 versions_d[version] = [];
158 versions_d[version].append(arch)
161 anais_output += "\n (*) %s_%s [%s]: %s\n" % (binary, latest_version, source, architecture);
162 versions = versions_d.keys();
163 versions.sort(apt_pkg.VersionCompare);
164 for version in versions:
165 arches = versions_d[version];
167 anais_output += " o %s: %s\n" % (version, ", ".join(arches));
169 # Check for duplicated packages and build indices for checking "no source" later
170 source_index = component + '/' + source;
171 if src_pkgs.has_key(source):
172 print " %s is a duplicated source package (%s and %s)" % (source, source_index, src_pkgs[source]);
173 src_pkgs[source] = source_index;
174 for binary in binaries_list:
175 if bin_pkgs.has_key(binary):
176 key = "%s~%s" % (source, bin_pkgs[binary]);
177 if not duplicate_bins.has_key(key):
178 duplicate_bins[key] = [];
179 duplicate_bins[key].append(binary);
180 bin_pkgs[binary] = source;
181 source_binaries[source] = binaries;
182 source_versions[source] = source_version;
185 os.unlink(temp_filename);
187 for component in components:
188 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
189 for architecture in architectures:
190 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
191 packages = utils.open_file(filename);
192 Packages = apt_pkg.ParseTagFile(packages);
193 while Packages.Step():
194 package = Packages.Section.Find('Package');
195 source = Packages.Section.Find('Source', "");
196 version = Packages.Section.Find('Version');
199 if source.find("(") != -1:
200 m = utils.re_extract_src_version.match(source);
202 version = m.group(2);
203 if not bin_pkgs.has_key(package):
204 if not nbs.has_key(source):
206 if not nbs[source].has_key(package):
207 nbs[source][package] = {};
208 nbs[source][package][version] = "";
213 for source in nbs.keys():
214 for package in nbs[source].keys():
215 versions = nbs[source][package].keys();
216 versions.sort(apt_pkg.VersionCompare);
217 latest_version = versions.pop();
218 source_version = source_versions.get(source,"0");
219 if apt_pkg.VersionCompare(latest_version, source_version) == 0:
220 add_nbs(dubious_nbs, source, latest_version, package);
222 add_nbs(real_nbs, source, latest_version, package);
224 # Check for packages in experimental obsoleted by versions in unstable
225 suite_id = db_access.get_suite_id("unstable");
226 q = projectB.query("""
227 SELECT s.source, s.version AS experimental, s2.version AS unstable
228 FROM src_associations sa, source s, source s2, src_associations sa2
229 WHERE sa.suite = 1 AND sa2.suite = %d AND sa.source = s.id
230 AND sa2.source = s2.id AND s.source = s2.source
231 AND versioncmp(s.version, s2.version) < 0""" % (suite_id));
235 print "Newer version in unstable";
236 print "-------------------------";
239 (source, experimental_version, unstable_version) = i;
240 print " o %s (%s, %s)" % (source, experimental_version, unstable_version);
241 nviu_to_remove.extend(source);
243 print "Suggested command:"
244 print " melanie -m \"[rene] NVIU\" -s experimental %s" % (" ".join(nviu_to_remove));
247 print "Not Built from Source";
248 print "---------------------";
252 nbs_keys = real_nbs.keys();
254 for source in nbs_keys:
255 binaries = source_binaries.get(source, "(source does not exist)")
256 print " * %s_%s builds: %s" % (source,
257 source_versions.get(source, "??"),
258 source_binaries.get(source, "(source does not exist)"));
259 print " but no longer builds:"
260 versions = real_nbs[source].keys();
261 versions.sort(apt_pkg.VersionCompare);
262 for version in versions:
263 packages = real_nbs[source][version].keys();
267 if pkg.find("pcmcia") == -1:
268 nbs_to_remove.append(pkg);
269 print " o %s: %s" % (version, ", ".join(packages));
273 print "Suggested command:"
274 print " melanie -m \"[rene] NBS\" -b %s" % (" ".join(nbs_to_remove));
280 print "Unbuilt binary packages";
281 print "-----------------------";
283 keys = bin_not_built.keys();
286 binaries = bin_not_built[source].keys();
288 print " o %s: %s" % (source, ", ".join(binaries));
291 print "Built from multiple source packages";
292 print "-----------------------------------";
294 keys = duplicate_bins.keys();
297 (source_a, source_b) = key.split("~");
298 print " o %s & %s => %s" % (source_a, source_b, ", ".join(duplicate_bins[key]));
301 print "Architecture Not Allowed In Source";
302 print "----------------------------------";
310 dubious_nbs_keys = dubious_nbs.keys();
311 dubious_nbs_keys.sort();
312 for source in dubious_nbs_keys:
313 binaries = source_binaries.get(source, "(source does not exist)")
314 print " * %s_%s builds: %s" % (source,
315 source_versions.get(source, "??"),
316 source_binaries.get(source, "(source does not exist)"));
317 print " won't admit to building:"
318 versions = dubious_nbs[source].keys();
319 versions.sort(apt_pkg.VersionCompare);
320 for version in versions:
321 packages = dubious_nbs[source][version].keys();
323 print " o %s: %s" % (version, ", ".join(packages));
328 ################################################################################
330 if __name__ == '__main__':