3 # Dependency check proposed-updates
4 # Copyright (C) 2001, 2002, 2004 James Troup <james@nocrew.org>
5 # $Id: jeri,v 1.15 2005-02-08 22:43:45 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 ################################################################################
23 # | > amd64 is more mature than even some released architectures
25 # | This might be true of the architecture, unfortunately it seems to be the
26 # | exact opposite for most of the people involved with it.
28 # <1089213290.24029.6.camel@descent.netsplit.com>
30 ################################################################################
33 import utils, db_access
34 import apt_pkg, apt_inst;
36 ################################################################################
45 ################################################################################
47 def usage (exit_code=0):
48 print """Usage: jeri [OPTION] <CHANGES FILE | DEB FILE | ADMIN FILE>[...]
49 (Very) Basic dependency checking for proposed-updates.
51 -q, --quiet be quieter about what is being done
52 -v, --verbose be more verbose about what is being done
53 -h, --help show this help and exit
55 Need either changes files, deb files or an admin.txt file with a '.joey' suffix."""
58 ################################################################################
60 def d_test (dict, key, positive, negative):
68 ################################################################################
70 def check_dep (depends, dep_type, check_archs, filename, files):
72 for arch in check_archs:
73 for parsed_dep in apt_pkg.ParseDepends(depends):
75 for atom in parsed_dep:
76 (dep, version, constraint) = atom;
78 if stable.has_key(dep):
79 if stable[dep].has_key(arch):
80 if apt_pkg.CheckDep(stable[dep][arch], constraint, version):
82 print "Found %s as a real package." % (utils.pp_deps(parsed_dep));
86 if stable_virtual.has_key(dep):
87 if stable_virtual[dep].has_key(arch):
88 if not constraint and not version:
90 print "Found %s as a virtual package." % (utils.pp_deps(parsed_dep));
93 # As part of the same .changes?
94 epochless_version = utils.re_no_epoch.sub('', version)
95 dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch);
96 if files.has_key(dep_filename):
98 print "Found %s in the same upload." % (utils.pp_deps(parsed_dep));
102 # [FIXME: must be a better way ... ]
103 error = "%s not found. [Real: " % (utils.pp_deps(parsed_dep))
104 if stable.has_key(dep):
105 if stable[dep].has_key(arch):
106 error += "%s:%s:%s" % (dep, arch, stable[dep][arch]);
108 error += "%s:-:-" % (dep);
111 error += ", Virtual: ";
112 if stable_virtual.has_key(dep):
113 if stable_virtual[dep].has_key(arch):
114 error += "%s:%s" % (dep, arch);
119 error += ", Upload: ";
120 if files.has_key(dep_filename):
128 sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, utils.pp_deps(parsed_dep), dep_type));
130 sys.stderr.write(" %s\n" % (error));
135 def check_package(filename, files):
137 control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename)));
139 utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type));
141 Depends = control.Find("Depends");
142 Pre_Depends = control.Find("Pre-Depends");
143 #Recommends = control.Find("Recommends");
144 pkg_arch = control.Find("Architecture");
145 base_file = os.path.basename(filename);
146 if pkg_arch == "all":
147 check_archs = architectures;
149 check_archs = [pkg_arch];
153 pkg_unsat += check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files);
156 pkg_unsat += check_dep(Depends, "dependency", check_archs, base_file, files);
158 #pkg_unsat += check_dep(Recommends, "recommendation", check_archs, base_file, files);
162 ################################################################################
164 def pass_fail (filename, result):
165 if not Options["quiet"]:
166 print "%s:" % (os.path.basename(filename)),
172 ################################################################################
174 def check_changes (filename):
176 changes = utils.parse_changes(filename);
177 files = utils.build_file_list(changes);
179 utils.warn("Error parsing changes file '%s'" % (filename));
184 # Move to the pool directory
186 file = files.keys()[0];
187 pool_dir = Cnf["Dir::Pool"] + '/' + utils.poolify(changes["source"], files[file]["component"]);
191 for file in files.keys():
192 if file.endswith(".deb"):
193 result = check_package(file, files);
194 if Options["verbose"]:
195 pass_fail(file, result);
196 changes_result += result;
198 pass_fail (filename, changes_result);
203 ################################################################################
205 def check_deb (filename):
206 result = check_package(filename, {});
207 pass_fail(filename, result);
210 ################################################################################
212 def check_joey (filename):
213 file = utils.open_file(filename);
216 os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]));
218 for line in file.readlines():
219 line = line.rstrip();
220 if line.find('install') != -1:
221 split_line = line.split();
222 if len(split_line) != 2:
223 utils.fubar("Parse error (not exactly 2 elements): %s" % (line));
224 install_type = split_line[0];
225 if install_type not in [ "install", "install-u", "sync-install" ]:
226 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line));
227 changes_filename = split_line[1]
229 print "Processing %s..." % (changes_filename);
230 check_changes(changes_filename);
235 ################################################################################
237 def parse_packages():
238 global stable, stable_virtual, architectures;
240 # Parse the Packages files (since it's a sub-second operation on auric)
243 components = Cnf.ValueList("Suite::%s::Components" % (suite));
244 architectures = filter(utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)));
245 for component in components:
246 for architecture in architectures:
247 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture);
248 packages = utils.open_file(filename, 'r');
249 Packages = apt_pkg.ParseTagFile(packages);
250 while Packages.Step():
251 package = Packages.Section.Find('Package');
252 version = Packages.Section.Find('Version');
253 provides = Packages.Section.Find('Provides');
254 if not stable.has_key(package):
255 stable[package] = {};
256 stable[package][architecture] = version;
258 for virtual_pkg in provides.split(","):
259 virtual_pkg = virtual_pkg.strip();
260 if not stable_virtual.has_key(virtual_pkg):
261 stable_virtual[virtual_pkg] = {};
262 stable_virtual[virtual_pkg][architecture] = "NA";
265 ################################################################################
268 global Cnf, projectB, Options;
270 Cnf = utils.get_conf()
272 Arguments = [('d', "debug", "Jeri::Options::Debug"),
273 ('q',"quiet","Jeri::Options::Quiet"),
274 ('v',"verbose","Jeri::Options::Verbose"),
275 ('h',"help","Jeri::Options::Help")];
276 for i in [ "debug", "quiet", "verbose", "help" ]:
277 if not Cnf.has_key("Jeri::Options::%s" % (i)):
278 Cnf["Jeri::Options::%s" % (i)] = "";
280 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
281 Options = Cnf.SubTree("Jeri::Options")
286 utils.fubar("need at least one package name as an argument.");
288 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
289 db_access.init(Cnf, projectB);
291 print "Parsing packages files...",
295 for file in arguments:
296 if file.endswith(".changes"):
298 elif file.endswith(".deb"):
300 elif file.endswith(".joey"):
303 utils.fubar("Unrecognised file type: '%s'." % (file));
305 #######################################################################################
307 if __name__ == '__main__':