3 # Dependency check proposed-updates
4 # Copyright (C) 2001 James Troup <james@nocrew.org>
5 # $Id: jeri,v 1.3 2001-11-18 19:57:58 rmurray 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 ################################################################################
45 ################################################################################
50 (pkg, version, constraint) = atom;
52 pp_dep = "%s (%s %s)" % (pkg, constraint, version);
55 pp_deps.append(pp_dep);
56 return string.join(pp_deps, " |");
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." % (pp_dep(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." % (pp_dep(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." % (pp_dep(parsed_dep));
102 # [FIXME: must be a better way ... ]
103 error = "%s not found. [Real: " % (pp_dep(parsed_dep))
104 if stable.has_key(dep):
105 if stable[dep].has_key(arch):
106 error = error + "%s:%s:%s" % (dep, arch, stable[dep][arch]);
108 error = error + "%s:-:-" % (dep);
110 error = error + "-:-:-";
111 error = error + ", Virtual: ";
112 if stable_virtual.has_key(dep):
113 if stable_virtual[dep].has_key(arch):
114 error = error + "%s:%s" % (dep, arch);
116 error = error + "%s:-";
118 error = error + "-:-";
119 error = error + ", Upload: ";
120 if files.has_key(dep_filename):
121 error = error + "yes";
123 error = error + "no";
128 sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, pp_dep(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 = pkg_unsat + check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files);
156 pkg_unsat = pkg_unsat + check_dep(Depends, "dependency", check_archs, base_file, files);
158 #pkg_unsat = 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, 0)
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::PoolDir"] + '/' + utils.poolify(changes["source"], files[file]["component"]);
191 for file in files.keys():
192 if file[-4:] == ".deb":
193 result = check_package(file, files);
194 if Options["verbose"]:
195 pass_fail(file, result);
196 changes_result = 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::RootDir"]));
218 for line in file.readlines():
220 if string.find(line, 'install') != -1:
221 split_line = string.split(line);
222 install_type = split_line[0];
223 if [ "install", "install-u", "sync-install" ].count(install_type) == 0:
224 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line));
225 changes_filename = split_line[1]
226 if len(split_line) != 2:
227 utils.fubar("Parse error (more than 2 elements): %s" % (line));
229 print "Processing %s..." % (changes_filename);
230 check_changes(changes_filename);
234 ################################################################################
236 def parse_packages():
237 global stable, stable_virtual, architectures;
239 # Parse the Packages files (since it's a sub-second operation on auric)
242 components = Cnf.SubTree("Suite::%s::Components" % (suite)).List();
243 architectures = Cnf.SubTree("Suite::%s::Architectures" % (suite)).List();
244 for arch in [ "source", "all" ]:
245 if architectures.count(arch):
246 architectures.remove(arch);
247 for component in components:
248 for architecture in architectures:
249 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::RootDir"], suite, component, architecture);
250 packages = utils.open_file(filename, 'r');
251 Packages = apt_pkg.ParseTagFile(packages);
252 while Packages.Step():
253 package = Packages.Section.Find('Package');
254 version = Packages.Section.Find('Version');
255 provides = Packages.Section.Find('Provides');
256 if not stable.has_key(package):
257 stable[package] = {};
258 stable[package][architecture] = version;
260 for virtual_pkg in string.split(provides,","):
261 virtual_pkg = string.strip(virtual_pkg);
262 if not stable_virtual.has_key(virtual_pkg):
263 stable_virtual[virtual_pkg] = {};
264 stable_virtual[virtual_pkg][architecture] = "NA";
266 ################################################################################
269 global Cnf, projectB, Options;
271 Cnf = utils.get_conf()
273 Arguments = [('q',"quiet","Jeri::Options::Quiet"),
274 ('v',"verbose","Jeri::Options::Verbose"),
275 ('D',"debug","Jeri::Options::Debug"),
276 ('h',"help","Jeri::Options::Help"),
277 ('V',"version","Jeri::Options::Version")];
278 for i in [ "quiet", "verbose", "help", "debug" ]:
279 if not Cnf.has_key("Jeri::Options::%s" % (i)):
280 Cnf["Jeri::Options::%s" % (i)] = "";
282 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv);
283 Options = Cnf.SubTree("Jeri::Options")
288 utils.fubar("need at least one package name as an argument.");
290 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
291 db_access.init(Cnf, projectB);
293 print "Parsing packages files...",
297 for file in arguments:
298 if file[-8:] == ".changes":
300 elif file[-4:] == ".deb":
302 elif file[-5:] == ".joey":
305 utils.fubar("Unrecognised file type: '%s'." % (file));
307 #######################################################################################
309 if __name__ == '__main__':