3 # Dependency check proposed-updates
4 # Copyright (C) 2001, 2002 James Troup <james@nocrew.org>
5 # $Id: jeri,v 1.9 2002-06-08 00:17:59 troup Exp $
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.
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.
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
21 ################################################################################
24 # <aj> what's wrong with me!?!?!?
25 # <aj> i was just nice to some mormon doorknockers!!!
28 # <Omnic> I'm gonna have to kick your ass when you come over
29 # <Culus> aj: GET THE HELL OUT OF THE CABAL! :P
31 ################################################################################
33 import pg, sys, os, string
34 import utils, db_access
35 import apt_pkg, apt_inst;
37 ################################################################################
46 ################################################################################
48 def usage (exit_code=0):
49 print """Usage: jeri [OPTION] <CHANGES FILE | DEB FILE | ADMIN FILE>[...]
50 Remove obsolete changes files from proposed-updates.
52 -q, --quiet be quieter about what is being done
53 -v, --verbose be more verbose about what is being done
54 -h, --help show this help and exit
56 Need either changes files, deb files or an admin.txt file with a '.joey' suffix."""
59 ################################################################################
64 (pkg, version, constraint) = atom;
66 pp_dep = "%s (%s %s)" % (pkg, constraint, version);
69 pp_deps.append(pp_dep);
70 return string.join(pp_deps, " |");
72 ################################################################################
74 def d_test (dict, key, positive, negative):
82 ################################################################################
84 def check_dep (depends, dep_type, check_archs, filename, files):
86 for arch in check_archs:
87 for parsed_dep in apt_pkg.ParseDepends(depends):
89 for atom in parsed_dep:
90 (dep, version, constraint) = atom;
92 if stable.has_key(dep):
93 if stable[dep].has_key(arch):
94 if apt_pkg.CheckDep(stable[dep][arch], constraint, version):
96 print "Found %s as a real package." % (pp_dep(parsed_dep));
100 if stable_virtual.has_key(dep):
101 if stable_virtual[dep].has_key(arch):
102 if not constraint and not version:
104 print "Found %s as a virtual package." % (pp_dep(parsed_dep));
107 # As part of the same .changes?
108 epochless_version = utils.re_no_epoch.sub('', version)
109 dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch);
110 if files.has_key(dep_filename):
112 print "Found %s in the same upload." % (pp_dep(parsed_dep));
116 # [FIXME: must be a better way ... ]
117 error = "%s not found. [Real: " % (pp_dep(parsed_dep))
118 if stable.has_key(dep):
119 if stable[dep].has_key(arch):
120 error = error + "%s:%s:%s" % (dep, arch, stable[dep][arch]);
122 error = error + "%s:-:-" % (dep);
124 error = error + "-:-:-";
125 error = error + ", Virtual: ";
126 if stable_virtual.has_key(dep):
127 if stable_virtual[dep].has_key(arch):
128 error = error + "%s:%s" % (dep, arch);
130 error = error + "%s:-";
132 error = error + "-:-";
133 error = error + ", Upload: ";
134 if files.has_key(dep_filename):
135 error = error + "yes";
137 error = error + "no";
142 sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, pp_dep(parsed_dep), dep_type));
144 sys.stderr.write(" %s\n" % (error));
149 def check_package(filename, files):
151 control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename)));
153 utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type));
155 Depends = control.Find("Depends");
156 Pre_Depends = control.Find("Pre-Depends");
157 #Recommends = control.Find("Recommends");
158 pkg_arch = control.Find("Architecture");
159 base_file = os.path.basename(filename);
160 if pkg_arch == "all":
161 check_archs = architectures;
163 check_archs = [pkg_arch];
167 pkg_unsat = pkg_unsat + check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files);
170 pkg_unsat = pkg_unsat + check_dep(Depends, "dependency", check_archs, base_file, files);
172 #pkg_unsat = pkg_unsat + check_dep(Recommends, "recommendation", check_archs, base_file, files);
176 ################################################################################
178 def pass_fail (filename, result):
179 if not Options["quiet"]:
180 print "%s:" % (os.path.basename(filename)),
186 ################################################################################
188 def check_changes (filename):
190 changes = utils.parse_changes(filename);
191 files = utils.build_file_list(changes);
193 utils.warn("Error parsing changes file '%s'" % (filename));
198 # Move to the pool directory
200 file = files.keys()[0];
201 pool_dir = Cnf["Dir::Pool"] + '/' + utils.poolify(changes["source"], files[file]["component"]);
205 for file in files.keys():
206 if file[-4:] == ".deb":
207 result = check_package(file, files);
208 if Options["verbose"]:
209 pass_fail(file, result);
210 changes_result = changes_result + result;
212 pass_fail (filename, changes_result);
217 ################################################################################
219 def check_deb (filename):
220 result = check_package(filename, {});
221 pass_fail(filename, result);
224 ################################################################################
226 def check_joey (filename):
227 file = utils.open_file(filename);
230 os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]));
232 for line in file.readlines():
233 line = string.rstrip(line);
234 if string.find(line, 'install') != -1:
235 split_line = string.split(line);
236 if len(split_line) != 2:
237 utils.fubar("Parse error (not exactly 2 elements): %s" % (line));
238 install_type = split_line[0];
239 if [ "install", "install-u", "sync-install" ].count(install_type) == 0:
240 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line));
241 changes_filename = split_line[1]
243 print "Processing %s..." % (changes_filename);
244 check_changes(changes_filename);
249 ################################################################################
251 def parse_packages():
252 global stable, stable_virtual, architectures;
254 # Parse the Packages files (since it's a sub-second operation on auric)
257 components = Cnf.ValueList("Suite::%s::Components" % (suite));
258 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
259 for component in components:
260 for architecture in architectures:
261 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
262 packages = utils.open_file(filename, 'r');
263 Packages = apt_pkg.ParseTagFile(packages);
264 while Packages.Step():
265 package = Packages.Section.Find('Package');
266 version = Packages.Section.Find('Version');
267 provides = Packages.Section.Find('Provides');
268 if not stable.has_key(package):
269 stable[package] = {};
270 stable[package][architecture] = version;
272 for virtual_pkg in string.split(provides,","):
273 virtual_pkg = string.strip(virtual_pkg);
274 if not stable_virtual.has_key(virtual_pkg):
275 stable_virtual[virtual_pkg] = {};
276 stable_virtual[virtual_pkg][architecture] = "NA";
279 ################################################################################
282 global Cnf, projectB, Options;
284 Cnf = utils.get_conf()
286 Arguments = [('d', "debug", "Jeri::Options::Debug"),
287 ('q',"quiet","Jeri::Options::Quiet"),
288 ('v',"verbose","Jeri::Options::Verbose"),
289 ('h',"help","Jeri::Options::Help")];
290 for i in [ "debug", "quiet", "verbose", "help" ]:
291 if not Cnf.has_key("Jeri::Options::%s" % (i)):
292 Cnf["Jeri::Options::%s" % (i)] = "";
294 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
295 Options = Cnf.SubTree("Jeri::Options")
300 utils.fubar("need at least one package name as an argument.");
302 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
303 db_access.init(Cnf, projectB);
305 print "Parsing packages files...",
309 for file in arguments:
310 if file[-8:] == ".changes":
312 elif file[-4:] == ".deb":
314 elif file[-5:] == ".joey":
317 utils.fubar("Unrecognised file type: '%s'." % (file));
319 #######################################################################################
321 if __name__ == '__main__':