/usr/share/doc/python-apt/examples/all_deps.py is in python-apt-doc 0.9.3.12.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #!/usr/bin/env python
import sys
import apt
def dependencies(cache, pkg, deps, key="Depends"):
#print "pkg: %s (%s)" % (pkg.name, deps)
candver = cache._depcache.get_candidate_ver(pkg._pkg)
if candver is None:
return deps
dependslist = candver.depends_list
if key in dependslist:
for depVerList in dependslist[key]:
for dep in depVerList:
if dep.target_pkg.name in cache:
if (pkg.name != dep.target_pkg.name and
dep.target_pkg.name not in deps):
deps.add(dep.target_pkg.name)
dependencies(
cache, cache[dep.target_pkg.name], deps, key)
return deps
pkgname = sys.argv[1]
c = apt.Cache()
pkg = c[pkgname]
deps = set()
deps = dependencies(c, pkg, deps, "Depends")
print " ".join(deps)
preDeps = set()
preDeps = dependencies(c, pkg, preDeps, "PreDepends")
print " ".join(preDeps)
|