- components = Cnf.SubTree("Suite::%s::Components" % (suite)).List();
- for component in components:
- filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::RootDir"], suite, component);
- print "Processing %s..." % (filename);
- # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
- temp_filename = tempfile.mktemp();
- fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
- os.close(fd);
- (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
- if (result != 0):
- sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
- sys.exit(result);
- sources = utils.open_file(temp_filename, 'r');
- Sources = apt_pkg.ParseTagFile(sources);
- while Sources.Step():
- source = Sources.Section.Find('Package');
- architecture = Sources.Section.Find('Architecture');
- if architecture == "any" or architecture == "all":
- continue;
- architectures = {};
- for arch in string.split(architecture):
- architectures[string.strip(arch)] = "";
- binaries = Sources.Section.Find('Binary');
- for binary in string.split(binaries, ','):
- binary = string.strip(binary);
- 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));
- ql = q.getresult();
- if ql == []:
- utils.warn("%s lists %s as a binary, but it doesn't seem to exist in %s?" % (source, binary, suite));
- # Loop around twice; first to get the latest 'valid' version
- versions = [];
- for i in q.getresult():
- arch = i[0];
- version = i[1];
- if architectures.has_key(arch):
- versions.append(version);
- versions.sort(apt_pkg.VersionCompare);
- if versions != []:
- latest_version = versions.pop()
+def usage(exit_code=0):
+ print """Usage: rene
+Check for obsolete or duplicated packages.
+
+ -h, --help show this help and exit.
+ -m, --mode=MODE chose the MODE to run in (full or daily).
+ -s, --suite=SUITE check suite SUITE."""
+ sys.exit(exit_code)
+
+################################################################################
+
+def add_nbs(nbs_d, source, version, package):
+ # Ensure the package is still in the suite (someone may have already removed it)
+ if no_longer_in_suite.has_key(package):
+ return;
+ else:
+ q = projectB.query("SELECT b.id FROM binaries b, bin_associations ba WHERE ba.bin = b.id AND ba.suite = %s AND b.package = '%s' LIMIT 1" % (suite_id, package));
+ if not q.getresult():
+ no_longer_in_suite[package] = "";
+ return;
+
+ nbs_d.setdefault(source, {})
+ nbs_d[source].setdefault(version, {})
+ nbs_d[source][version][package] = "";
+
+################################################################################
+
+# Check for packages built on architectures they shouldn't be.
+def do_anais(architecture, binaries_list, source):
+ if architecture == "any" or architecture == "all":
+ return "";
+
+ anais_output = "";
+ architectures = {};
+ for arch in architecture.split():
+ architectures[arch.strip()] = "";
+ for binary in binaries_list:
+ 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));
+ ql = q.getresult();
+ versions = [];
+ for i in ql:
+ arch = i[0];
+ version = i[1];
+ if architectures.has_key(arch):
+ versions.append(version);
+ versions.sort(apt_pkg.VersionCompare);
+ if versions:
+ latest_version = versions.pop()
+ else:
+ latest_version = None;
+ # Check for 'invalid' architectures
+ versions_d = {}
+ for i in ql:
+ arch = i[0];
+ version = i[1];
+ if not architectures.has_key(arch):
+ versions_d.setdefault(version, [])
+ versions_d[version].append(arch)
+
+ if versions_d != {}:
+ anais_output += "\n (*) %s_%s [%s]: %s\n" % (binary, latest_version, source, architecture);
+ versions = versions_d.keys();
+ versions.sort(apt_pkg.VersionCompare);
+ for version in versions:
+ arches = versions_d[version];
+ arches.sort();
+ anais_output += " o %s: %s\n" % (version, ", ".join(arches));
+ return anais_output;
+
+################################################################################
+
+def do_nviu():
+ experimental_id = db_access.get_suite_id("experimental");
+ if experimental_id == -1:
+ return;
+ # Check for packages in experimental obsoleted by versions in unstable
+ q = projectB.query("""
+SELECT s.source, s.version AS experimental, s2.version AS unstable
+ FROM src_associations sa, source s, source s2, src_associations sa2
+ WHERE sa.suite = %s AND sa2.suite = %d AND sa.source = s.id
+ AND sa2.source = s2.id AND s.source = s2.source
+ AND versioncmp(s.version, s2.version) < 0""" % (experimental_id,
+ db_access.get_suite_id("unstable")));
+ ql = q.getresult();
+ if ql:
+ nviu_to_remove = [];
+ print "Newer version in unstable";
+ print "-------------------------";
+ print ;
+ for i in ql:
+ (source, experimental_version, unstable_version) = i;
+ print " o %s (%s, %s)" % (source, experimental_version, unstable_version);
+ nviu_to_remove.append(source);
+ print
+ print "Suggested command:"
+ print " melanie -m \"[rene] NVIU\" -s experimental %s" % (" ".join(nviu_to_remove));
+ print
+
+################################################################################
+
+def do_nbs(real_nbs):
+ output = "Not Built from Source\n";
+ output += "---------------------\n\n";
+
+ nbs_to_remove = [];
+ nbs_keys = real_nbs.keys();
+ nbs_keys.sort();
+ for source in nbs_keys:
+ output += " * %s_%s builds: %s\n" % (source,
+ source_versions.get(source, "??"),
+ source_binaries.get(source, "(source does not exist)"));
+ output += " but no longer builds:\n"
+ versions = real_nbs[source].keys();
+ versions.sort(apt_pkg.VersionCompare);
+ for version in versions:
+ packages = real_nbs[source][version].keys();
+ packages.sort();
+ for pkg in packages:
+ nbs_to_remove.append(pkg);
+ output += " o %s: %s\n" % (version, ", ".join(packages));
+
+ output += "\n";
+
+ if nbs_to_remove:
+ print output;
+
+ print "Suggested command:"
+ print " melanie -m \"[rene] NBS\" -b %s" % (" ".join(nbs_to_remove));
+ print
+
+################################################################################
+
+def do_dubious_nbs(dubious_nbs):
+ print "Dubious NBS";
+ print "-----------";
+ print ;
+
+ dubious_nbs_keys = dubious_nbs.keys();
+ dubious_nbs_keys.sort();
+ for source in dubious_nbs_keys:
+ print " * %s_%s builds: %s" % (source,
+ source_versions.get(source, "??"),
+ source_binaries.get(source, "(source does not exist)"));
+ print " won't admit to building:"
+ versions = dubious_nbs[source].keys();
+ versions.sort(apt_pkg.VersionCompare);
+ for version in versions:
+ packages = dubious_nbs[source][version].keys();
+ packages.sort();
+ print " o %s: %s" % (version, ", ".join(packages));
+
+ print ;
+
+################################################################################
+
+def do_obsolete_source(duplicate_bins, bin2source):
+ obsolete = {}
+ for key in duplicate_bins.keys():
+ (source_a, source_b) = key.split('~')
+ for source in [ source_a, source_b ]:
+ if not obsolete.has_key(source):
+ if not source_binaries.has_key(source):
+ # Source has already been removed
+ continue;