]> git.decadent.org.uk Git - dak.git/blob - rene
Quotes
[dak.git] / rene
1 #!/usr/bin/env python
2
3 # Check for obsolete binary packages
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: rene,v 1.14 2002-08-07 17:19:29 troup Exp $
6
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.
11
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.
16
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
20
21 ################################################################################
22
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
26
27 ################################################################################
28
29 import commands, pg, os, string, sys, tempfile;
30 import utils, db_access;
31 import apt_pkg;
32
33 ################################################################################
34
35 Cnf = None;
36 projectB = None;
37
38 ################################################################################
39
40 def main ():
41     global Cnf, projectB;
42
43     Cnf = utils.get_conf()
44
45     Arguments = [('h',"help","Catherine::Options::Help"),
46                  ('V',"version","Catherine::Options::Version"),
47                  ('l',"limit", "Catherine::Options::Limit", "HasArg"),
48                  ('n',"no-action","Catherine::Options::No-Action"),
49                  ('v',"verbose","Catherine::Options::Verbose")];
50
51     apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
52     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
53     db_access.init(Cnf, projectB);
54
55     bin_pkgs = {};
56     miss_src = {};
57     src_pkgs = {};
58     source_binaries = {};
59
60     suite = "unstable";
61     suite_id = db_access.get_suite_id(suite);
62
63     components = Cnf.ValueList("Suite::%s::Components" % (suite));
64     for component in components:
65         filename = "%s/dists/%s/%s/source/Sources.gz" % (Cnf["Dir::Root"], suite, component);
66         # apt_pkg.ParseTagFile needs a real file handle and can't handle a GzipFile instance...
67         temp_filename = tempfile.mktemp();
68         fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
69         os.close(fd);
70         (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
71         if (result != 0):
72             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
73             sys.exit(result);
74         sources = utils.open_file(temp_filename);
75         Sources = apt_pkg.ParseTagFile(sources);
76         while Sources.Step():
77             source = Sources.Section.Find('Package');
78             architecture = Sources.Section.Find('Architecture');
79             binaries = Sources.Section.Find('Binary');
80
81             # Check for packages built on architectures they shouldn't be.
82             if architecture != "any" and architecture != "all":
83                 architectures = {};
84                 for arch in string.split(architecture):
85                     architectures[string.strip(arch)] = "";
86                 for binary in string.split(binaries, ','):
87                     binary = string.strip(binary);
88                     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));
89                     ql = q.getresult();
90                     if not ql:
91                         utils.warn("%s lists %s as a binary, but it doesn't seem to exist in %s?" % (source, binary, suite));
92                     # Loop around twice; first to get the latest 'valid' version
93                     versions = [];
94                     for i in q.getresult():
95                         arch = i[0];
96                         version = i[1];
97                         if architectures.has_key(arch):
98                             versions.append(version);
99                     versions.sort(apt_pkg.VersionCompare);
100                     if versions:
101                         latest_version = versions.pop()
102                     else:
103                         latest_version = None;
104                     # ... then to check for 'invalid' architectures
105                     for i in q.getresult():
106                         arch = i[0];
107                         version = i[1];
108                         if not architectures.has_key(arch):
109                             print "[%s]: %s appears for %s (vs. '%s')" % (source, binary, arch, architecture),
110                             if not latest_version:
111                                 print "** mwaap, mwapp!  Ignore me **";
112                                 continue;
113                             if apt_pkg.VersionCompare(latest_version, version) != -1:
114                                 print "- out of date.",
115                             else:
116                                 print "- current.",
117                             print "[%s vs %s (%s)]" % (latest_version, version, arch);
118
119             # Check for duplicated packages and build indices for checking "no source" later
120             source_index = component + '/' + source;
121             if src_pkgs.has_key(source):
122                 print " %s is a duplicated source package (%s and %s)" % (source, source_index, src_pkgs[source]);
123             src_pkgs[source] = source_index;
124             for binary in string.split(binaries, ','):
125                 binary = string.strip(binary);
126                 if bin_pkgs.has_key(binary):
127                     print " %s is duplicated in %s and %s" % (binary, source, bin_pkgs[binary]);
128                 bin_pkgs[binary] = source;
129             source_binaries[source] = binaries;
130
131         sources.close();
132         os.unlink(temp_filename);
133
134     for component in components:
135         architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
136         for architecture in architectures:
137             filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
138             packages = utils.open_file(filename);
139             Packages = apt_pkg.ParseTagFile(packages);
140             while Packages.Step():
141                 package = Packages.Section.Find('Package');
142                 source = Packages.Section.Find('Source', "");
143                 if source == "":
144                     source = package;
145                 if string.find(source, "(") != -1:
146                     m = utils.re_extract_src_version.match(source)
147                     source = m.group(1)
148                 if not bin_pkgs.has_key(package) and not miss_src.has_key(package):
149                     miss_src[package] = 1;
150                     print " %s has no source [%s: %s]" % (package, source, source_binaries.get(source, "(source does not exist)"));
151             packages.close();
152
153     # Check for packages in experimental obsoleted by versions in unstable
154     #
155     # [If melanie was callable from python, we could auto-remove these
156     #  packages...]
157
158     suite_id = db_access.get_suite_id("unstable");
159     q = projectB.query("""
160 SELECT s.source, s.version AS experimental, s2.version AS unstable
161   FROM src_associations sa, source s, source s2, src_associations sa2
162   WHERE sa.suite = 1 AND sa2.suite = %d AND sa.source = s.id
163    AND sa2.source = s2.id AND s.source = s2.source
164    AND versioncmp(s.version, s2.version) < 0""" % (suite_id));
165     ql = q.getresult();
166     if ql:
167         print
168         print q
169
170 ####################################################################################################
171
172 if __name__ == '__main__':
173     main()