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 dak.lib.utils, dak.lib.database
33 import apt_pkg, apt_inst
35 ################################################################################
44 ################################################################################
46 def usage (exit_code=0):
47 print """Usage: dak check-proposed-updates [OPTION] <CHANGES FILE | DEB FILE | ADMIN FILE>[...]
48 (Very) Basic dependency checking for proposed-updates.
50 -q, --quiet be quieter about what is being done
51 -v, --verbose be more verbose about what is being done
52 -h, --help show this help and exit
54 Need either changes files, deb files or an admin.txt file with a '.joey' suffix."""
57 ################################################################################
59 def d_test (dict, key, positive, negative):
67 ################################################################################
69 def check_dep (depends, dep_type, check_archs, filename, files):
71 for arch in check_archs:
72 for parsed_dep in apt_pkg.ParseDepends(depends):
74 for atom in parsed_dep:
75 (dep, version, constraint) = atom
77 if stable.has_key(dep):
78 if stable[dep].has_key(arch):
79 if apt_pkg.CheckDep(stable[dep][arch], constraint, version):
81 print "Found %s as a real package." % (dak.lib.utils.pp_deps(parsed_dep))
85 if stable_virtual.has_key(dep):
86 if stable_virtual[dep].has_key(arch):
87 if not constraint and not version:
89 print "Found %s as a virtual package." % (dak.lib.utils.pp_deps(parsed_dep))
92 # As part of the same .changes?
93 epochless_version = dak.lib.utils.re_no_epoch.sub('', version)
94 dep_filename = "%s_%s_%s.deb" % (dep, epochless_version, arch)
95 if files.has_key(dep_filename):
97 print "Found %s in the same upload." % (dak.lib.utils.pp_deps(parsed_dep))
101 # [FIXME: must be a better way ... ]
102 error = "%s not found. [Real: " % (dak.lib.utils.pp_deps(parsed_dep))
103 if stable.has_key(dep):
104 if stable[dep].has_key(arch):
105 error += "%s:%s:%s" % (dep, arch, stable[dep][arch])
107 error += "%s:-:-" % (dep)
110 error += ", Virtual: "
111 if stable_virtual.has_key(dep):
112 if stable_virtual[dep].has_key(arch):
113 error += "%s:%s" % (dep, arch)
118 error += ", Upload: "
119 if files.has_key(dep_filename):
127 sys.stderr.write("MWAAP! %s: '%s' %s can not be satisifed:\n" % (filename, dak.lib.utils.pp_deps(parsed_dep), dep_type))
129 sys.stderr.write(" %s\n" % (error))
134 def check_package(filename, files):
136 control = apt_pkg.ParseSection(apt_inst.debExtractControl(dak.lib.utils.open_file(filename)))
138 dak.lib.utils.warn("%s: debExtractControl() raised %s." % (filename, sys.exc_type))
140 Depends = control.Find("Depends")
141 Pre_Depends = control.Find("Pre-Depends")
142 #Recommends = control.Find("Recommends")
143 pkg_arch = control.Find("Architecture")
144 base_file = os.path.basename(filename)
145 if pkg_arch == "all":
146 check_archs = architectures
148 check_archs = [pkg_arch]
152 pkg_unsat += check_dep(Pre_Depends, "pre-dependency", check_archs, base_file, files)
155 pkg_unsat += check_dep(Depends, "dependency", check_archs, base_file, files)
157 #pkg_unsat += check_dep(Recommends, "recommendation", check_archs, base_file, files)
161 ################################################################################
163 def pass_fail (filename, result):
164 if not Options["quiet"]:
165 print "%s:" % (os.path.basename(filename)),
171 ################################################################################
173 def check_changes (filename):
175 changes = dak.lib.utils.parse_changes(filename)
176 files = dak.lib.utils.build_file_list(changes)
178 dak.lib.utils.warn("Error parsing changes file '%s'" % (filename))
183 # Move to the pool directory
185 file = files.keys()[0]
186 pool_dir = Cnf["Dir::Pool"] + '/' + dak.lib.utils.poolify(changes["source"], files[file]["component"])
190 for file in files.keys():
191 if file.endswith(".deb"):
192 result = check_package(file, files)
193 if Options["verbose"]:
194 pass_fail(file, result)
195 changes_result += result
197 pass_fail (filename, changes_result)
202 ################################################################################
204 def check_deb (filename):
205 result = check_package(filename, {})
206 pass_fail(filename, result)
209 ################################################################################
211 def check_joey (filename):
212 file = dak.lib.utils.open_file(filename)
215 os.chdir("%s/dists/proposed-updates" % (Cnf["Dir::Root"]))
217 for line in file.readlines():
219 if line.find('install') != -1:
220 split_line = line.split()
221 if len(split_line) != 2:
222 dak.lib.utils.fubar("Parse error (not exactly 2 elements): %s" % (line))
223 install_type = split_line[0]
224 if install_type not in [ "install", "install-u", "sync-install" ]:
225 dak.lib.utils.fubar("Unknown install type ('%s') from: %s" % (install_type, line))
226 changes_filename = split_line[1]
228 print "Processing %s..." % (changes_filename)
229 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.ValueList("Suite::%s::Components" % (suite))
243 architectures = filter(dak.lib.utils.real_arch, Cnf.ValueList("Suite::%s::Architectures" % (suite)))
244 for component in components:
245 for architecture in architectures:
246 filename = "%s/dists/%s/%s/binary-%s/Packages" % (Cnf["Dir::Root"], suite, component, architecture)
247 packages = dak.lib.utils.open_file(filename, 'r')
248 Packages = apt_pkg.ParseTagFile(packages)
249 while Packages.Step():
250 package = Packages.Section.Find('Package')
251 version = Packages.Section.Find('Version')
252 provides = Packages.Section.Find('Provides')
253 if not stable.has_key(package):
255 stable[package][architecture] = version
257 for virtual_pkg in provides.split(","):
258 virtual_pkg = virtual_pkg.strip()
259 if not stable_virtual.has_key(virtual_pkg):
260 stable_virtual[virtual_pkg] = {}
261 stable_virtual[virtual_pkg][architecture] = "NA"
264 ################################################################################
267 global Cnf, projectB, Options
269 Cnf = dak.lib.utils.get_conf()
271 Arguments = [('d', "debug", "Check-Proposed-Updates::Options::Debug"),
272 ('q',"quiet","Check-Proposed-Updates::Options::Quiet"),
273 ('v',"verbose","Check-Proposed-Updates::Options::Verbose"),
274 ('h',"help","Check-Proposed-Updates::Options::Help")]
275 for i in [ "debug", "quiet", "verbose", "help" ]:
276 if not Cnf.has_key("Check-Proposed-Updates::Options::%s" % (i)):
277 Cnf["Check-Proposed-Updates::Options::%s" % (i)] = ""
279 arguments = apt_pkg.ParseCommandLine(Cnf,Arguments,sys.argv)
280 Options = Cnf.SubTree("Check-Proposed-Updates::Options")
285 dak.lib.utils.fubar("need at least one package name as an argument.")
287 projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
288 dak.lib.database.init(Cnf, projectB)
290 print "Parsing packages files...",
294 for file in arguments:
295 if file.endswith(".changes"):
297 elif file.endswith(".deb"):
299 elif file.endswith(".joey"):
302 dak.lib.utils.fubar("Unrecognised file type: '%s'." % (file))
304 #######################################################################################
306 if __name__ == '__main__':