]> git.decadent.org.uk Git - dak.git/blob - rene
lots and lots of python 2.1 changes. rene: remove bogus argument handling. katie...
[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.15 2002-10-16 02:47:32 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, 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     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);
48
49     bin_pkgs = {};
50     miss_src = {};
51     src_pkgs = {};
52     source_binaries = {};
53
54     suite = "unstable";
55     suite_id = db_access.get_suite_id(suite);
56
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);
63         os.close(fd);
64         (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (filename, temp_filename));
65         if (result != 0):
66             sys.stderr.write("Gunzip invocation failed!\n%s\n" % (output));
67             sys.exit(result);
68         sources = utils.open_file(temp_filename);
69         Sources = apt_pkg.ParseTagFile(sources);
70         while Sources.Step():
71             source = Sources.Section.Find('Package');
72             architecture = Sources.Section.Find('Architecture');
73             binaries = Sources.Section.Find('Binary');
74
75             # Check for packages built on architectures they shouldn't be.
76             if architecture != "any" and architecture != "all":
77                 architectures = {};
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));
83                     ql = q.getresult();
84                     if not ql:
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
87                     versions = [];
88                     for i in q.getresult():
89                         arch = i[0];
90                         version = i[1];
91                         if architectures.has_key(arch):
92                             versions.append(version);
93                     versions.sort(apt_pkg.VersionCompare);
94                     if versions:
95                         latest_version = versions.pop()
96                     else:
97                         latest_version = None;
98                     # ... then to check for 'invalid' architectures
99                     for i in q.getresult():
100                         arch = i[0];
101                         version = i[1];
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 **";
106                                 continue;
107                             if apt_pkg.VersionCompare(latest_version, version) != -1:
108                                 print "- out of date.",
109                             else:
110                                 print "- current.",
111                             print "[%s vs %s (%s)]" % (latest_version, version, arch);
112
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;
124
125         sources.close();
126         os.unlink(temp_filename);
127
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', "");
137                 if source == "":
138                     source = package;
139                 if source.find("(") != -1:
140                     m = utils.re_extract_src_version.match(source)
141                     source = m.group(1)
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)"));
145             packages.close();
146
147     # Check for packages in experimental obsoleted by versions in unstable
148     #
149     # [If melanie was callable from python, we could auto-remove these
150     #  packages...]
151
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));
159     ql = q.getresult();
160     if ql:
161         print
162         print q
163
164 ####################################################################################################
165
166 if __name__ == '__main__':
167     main()