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