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