3 """ Dependency check proposed-updates """
4 # Copyright (C) 2001, 2002, 2004, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
22 # | > amd64 is more mature than even some released architectures
24 # | This might be true of the architecture, unfortunately it seems to be the
25 # | exact opposite for most of the people involved with it.
27 # <1089213290.24029.6.camel@descent.netsplit.com>
29 ################################################################################
32 import apt_pkg, apt_inst
34 from daklib.dbconn import *
35 from daklib.config import Config
36 from daklib import utils
37 from daklib.regexes import re_no_epoch
39 ################################################################################
46 ################################################################################
48 def usage (exit_code=0):
49 print """Usage: dak check-proposed-updates [OPTION] <CHANGES FILE | DEB FILE | ADMIN FILE>[...]
50 (Very) Basic dependency checking for 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 ################################################################################
61 def d_test (dict, key, positive, negative):
69 ################################################################################
71 def check_dep (depends, dep_type, check_archs, filename, files):
73 for arch in check_archs:
74 for parsed_dep in apt_pkg.ParseDepends(depends):
76 for atom in parsed_dep:
77 (dep, version, constraint) = atom
79 if stable.has_key(dep):
80 if stable[dep].has_key(arch):
81 if apt_pkg.CheckDep(stable[dep][arch], constraint, version):
83 print "Found %s as a real package." % (utils.pp_deps(parsed_dep))
87 if stable_virtual.has_key(dep):
88 if stable_virtual[dep].has_key(arch):
89 if not constraint and not version:
91 print "Found %s as a virtual package." % (utils.pp_deps(parsed_dep))
94 # As part of the same .changes?
95 epochless_version = re_no_epoch.sub('', version)
96 dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch)
97 if files.has_key(dep_filename):
99 print "Found %s in the same upload." % (utils.pp_deps(parsed_dep))
103 # [FIXME: must be a better way ... ]
104 error = "%s not found. [Real: " % (utils.pp_deps(parsed_dep))
105 if stable.has_key(dep):
106 if stable[dep].has_key(arch):
107 error += "%s:%s:%s" % (dep, arch, stable[dep][arch])
109 error += "%s:-:-" % (dep)
112 error += ", Virtual: "
113 if stable_virtual.has_key(dep):
114 if stable_virtual[dep].has_key(arch):
115 error += "%s:%s" % (dep, arch)
120 error += ", Upload: "
121 if files.has_key(dep_filename):
129 sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, utils.pp_deps(parsed_dep), dep_type))
131 sys.stderr.write(" %s\n" % (error))
136 def check_package(filename, files):
138 control = apt_pkg.ParseSection(apt_inst.debExtractControl(utils.open_file(filename)))
140 utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type))
142 Depends = control.Find("Depends")
143 Pre_Depends = control.Find("Pre-Depends")
144 #Recommends = control.Find("Recommends")
145 pkg_arch = control.Find("Architecture")
146 base_file = os.path.basename(filename)
147 if pkg_arch == "all":
148 check_archs = architectures
150 check_archs = [pkg_arch]
154 pkg_unsat += check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files)
157 pkg_unsat += check_dep(Depends, "dependency", check_archs, base_file, files)
159 #pkg_unsat += check_dep(Recommends, "recommendation", check_archs, base_file, files)
163 ################################################################################
165 def pass_fail (filename, result):
166 if not Options["quiet"]:
167 print "%s:" % (os.path.basename(filename)),
173 ################################################################################
175 def check_changes (filename):
179 changes = utils.parse_changes(filename)
180 files = utils.build_file_list(changes)
181 except ChangesUnicodeError:
182 utils.warn("Improperly encoded changes file, not utf-8")
185 utils.warn("Error parsing changes file '%s'" % (filename))
190 # Move to the pool directory
193 pool_dir = cnf["Dir::Pool"] + '/' + utils.poolify(changes["source"], files[f]["component"])
197 for f in files.keys():
198 if f.endswith(".deb"):
199 result = check_package(f, files)
200 if Options["verbose"]:
202 changes_result += result
204 pass_fail (filename, changes_result)
209 ################################################################################
211 def check_deb (filename):
212 result = check_package(filename, {})
213 pass_fail(filename, result)
216 ################################################################################
218 def check_joey (filename):
221 f = utils.open_file(filename)
224 os.chdir("%s/dists/proposed-updates" % (cnf["Dir::Root"]))
226 for line in f.readlines():
228 if line.find('install') != -1:
229 split_line = line.split()
230 if len(split_line) != 2:
231 utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
232 install_type = split_line[0]
233 if install_type not in [ "install", "install-u", "sync-install" ]:
234 utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
235 changes_filename = split_line[1]
237 print "Processing %s..." % (changes_filename)
238 check_changes(changes_filename)
243 ################################################################################
245 def parse_packages():
246 global stable, stable_virtual, architectures
250 # Parse the Packages files (since it's a sub-second operation on auric)
253 components = cnf.ValueList("Suite::%s::Components" % (suite))
254 architectures = [ a.arch_string for a in get_suite_architectures(suite, skipsrc=True, skipall=True) ]
255 for component in components:
256 for architecture in architectures:
257 filename = "%s/dists/%s/%s/binary-%s/Packages" % (cnf["Dir::Root"], suite, component, architecture)
258 packages = utils.open_file(filename, 'r')
259 Packages = apt_pkg.ParseTagFile(packages)
260 while Packages.Step():
261 package = Packages.Section.Find('Package')
262 version = Packages.Section.Find('Version')
263 provides = Packages.Section.Find('Provides')
264 if not stable.has_key(package):
266 stable[package][architecture] = version
268 for virtual_pkg in provides.split(","):
269 virtual_pkg = virtual_pkg.strip()
270 if not stable_virtual.has_key(virtual_pkg):
271 stable_virtual[virtual_pkg] = {}
272 stable_virtual[virtual_pkg][architecture] = "NA"
275 ################################################################################
282 Arguments = [('d', "debug", "Check-Proposed-Updates::Options::Debug"),
283 ('q',"quiet","Check-Proposed-Updates::Options::Quiet"),
284 ('v',"verbose","Check-Proposed-Updates::Options::Verbose"),
285 ('h',"help","Check-Proposed-Updates::Options::Help")]
286 for i in [ "debug", "quiet", "verbose", "help" ]:
287 if not cnf.has_key("Check-Proposed-Updates::Options::%s" % (i)):
288 cnf["Check-Proposed-Updates::Options::%s" % (i)] = ""
290 arguments = apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
291 Options = cnf.SubTree("Check-Proposed-Updates::Options")
296 utils.fubar("need at least one package name as an argument.")
300 print "Parsing packages files...",
305 if f.endswith(".changes"):
307 elif f.endswith(".deb"):
309 elif f.endswith(".joey"):
312 utils.fubar("Unrecognised file type: '%s'." % (f))
314 #######################################################################################
316 if __name__ == '__main__':