File: all_deps.py

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (36 lines) | stat: -rw-r--r-- 964 bytes parent folder | download | duplicates (2)
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.GetCandidateVer(pkg._pkg)
    if candver is None:
        return deps
    dependslist = candver.DependsList
    if key in dependslist:
        for depVerList in dependslist[key]:
            for dep in depVerList:
                if dep.TargetPkg.Name in cache:
                    if pkg.name != dep.TargetPkg.Name and \
                        not dep.TargetPkg.Name in deps:
                        deps.add(dep.TargetPkg.Name)
                        dependencies(
                            cache, cache[dep.TargetPkg.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)