File: recommends.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 (39 lines) | stat: -rwxr-xr-x 881 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
37
38
39
#!/usr/bin/python

import apt_pkg
apt_pkg.init()

cache = apt_pkg.Cache()


class Wanted:

    def __init__(self, name):
        self.name = name
        self.recommended = []
        self.suggested = []


wanted = {}

for package in cache.Packages:
    current = package.CurrentVer
    if not current:
        continue
    depends = current.DependsList
    for (key, attr) in (('Suggests', 'suggested'),
                        ('Recommends', 'recommended')):
        list = depends.get(key, [])
        for dependency in list:
            name = dependency[0].TargetPkg.Name
            dep = cache[name]
            if dep.CurrentVer:
                continue
            getattr(wanted.setdefault(name, Wanted(name)),
                    attr).append(package.Name)

ks = wanted.keys()
ks.sort()

for want in ks:
    print want, wanted[want].recommended, wanted[want].suggested