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